Say I have a directory structure like this:  - main folder   - folder 1      - file 1.txt   - folder 2   - folder 3      - file 2.txt      - file 3.png   - file 4.txt   - file 5.jpg   I'd like to create a batch script in Windows where I can drag/drop main folder onto it and it'll do the following:  - main folder_encrypted   - folder 1      - file 1.txt.7z   - folder 2   - folder 3      - file 2.txt.7z      - file 3.png.7z   - file 4.txt.7z   - file 5.jpg.7z   Basically, it'll maintain directory structure and individually compress and encrypt every file using 7zip and copy it to main folder_encrypted
121234
I have a bunch of files like this:  C:\G\G1\35antique-shop.mp3 C:\G\G2\35antique-shop.mp3 C:\G\G1\09saguri.mp3 C:\G\G2\09saguri.mp3   I just want to know how to keep the folder structure while archiving. This is more important than the duplicate thing, to know how to solve that, would be a bonus.     @Lamb "Do you want to archive only selective files (not the whole folder content) from the G1 and G2 folders?"   That almost says it all, but I'll try to improve: Not only do I want to move only some selected files to an archive. I also have a list of these files, including path-names to each file.  So, in SubDir1 there might be 10 files, of which I want to zip three, and in SubDir1\sub2 there might be five files, of which I want to zip all five. The files that I need to archive are in a listfile.  There might be duplicate files, so my hope is that with subdirectories added, 7-Zip does NOT see them as duplicates.  And I like to do it on the command line.  I've tried a batch file like this:  7z a -r MyArchive.7z C:\G\G1\35antique-shop.mp3 7z a -r MyArchive.7z C:\G\G2\35antique-shop.mp3 7z a -r MyArchive.7z C:\G\G1\09saguri.mp3 7z a -r MyArchive.7z C:\G\G2\09saguri.mp3   This also means that files 01antique-shop.mp3, 02antique-shop.mp3, ...., til 33antique-shop.mp3 and 34antique-shop.mp3, should NOT be archived.  The foldernames (=subdirectories) weren't added to MyArchive.7z, and this is the problem.  Obviously, I'd like to use just one commando with a listfile, but that doesn't work either.  I've tried:  7z a -mx0 -tzip C:\$$-edrive\F-G-H.zip @fgh.txt   which actually works pretty fine as far as the selecting goes, but it does NOT keep the directory structure. Sadly.  How do I do this?
50976
I am bit of a batch file noob, so I'd really appreciate your help. I have a ton of files stored in a single directory which I wish to sort into subfolders based on the first word in their filenames. So, I have files like these:  C:\Folder\Wedding2018 img20929.jpg  C:\Folder\Wedding2018 entrance.mov C:\Folder\Wedding2018 registry of guests.pdf  C:\Folder\HorseRiding2017 spirit1.jpg C:\Folder\HorseRiding2017 guests.txt  C:\Folder\HorseRiding2017 certificate.pdf C:\Folder\HorseRiding2017 jumping.mov   And I wish to move all files to subfolders based on the first word, ending up like this:  C:\Folder\Wedding2018\img20929.jpg C:\Folder\Wedding2018\entrance.mov C:\Folder\Wedding2018\registry of guests.pdf  C:\Folder\HorseRiding2017\spirit1.jpg C:\Folder\HorseRiding2017\guests.txt C:\Folder\HorseRiding2017\certificate.pdf C:\Folder\HorseRiding2017\jumping.mov   I've found a couple of scripts that almost do what I need, but I don't have the chops to bring it home:       I just can't work out how to integrate the script to grab the first word and make a directory to which the files will be moved.  Can you help me get this across the line?
90140
I want to copy all files of a certain type (like .docx, .pdf, etc) on my PC into a folder. How can I do that?
59319
Firstly, I'm aware there are tons of similar questions, and I know because I must have tried adapting at least 5 of them, but I'm still here asking because my crappy grasp of CMD (which I actually thought I was getting good at up until this point) is frustrating me with generic, unhelpful errors, and I can't understand what part of the syntax is wrong. This is likely due to the fact that other questions deal with the folder/filename structures of their respective OPs, and when I try to adapt the code to my own folder/file structure it refuses to work. Therefore, I'm here asking for a CMD for loop solution that'll actually work for my own file and folder structure.  I have a parent folder which contains many other folders, in which there are files:  Parent Folder      Subfolder            File1            File2      Subfolder            File1            File2      Subfolder            File1            File2   ...and so on.  I'm wanting to use a CMD for loop in combination with the move command to extract all the files in the subfolders to the parent folder, leaving each subfolder empty.  When giving the CMD for loop please break down what each part of the command is doing, as this'll help make sure I understand the code and hopefully minimise the trouble I have getting it to work for myself.
72552
How do I work recursively through a directory tree and execute a specific command on each file, and output the path, filename, extension, filesize and some other specific text to a single file in bash.
42446
I have a directory that I am trying to clean out that contains both files and subdirectories.  What I am trying to do is simple: move all the files into another directory, but leave all the sub-directories as they are.  I am thinking something like:  mv [*_but_no_dirs] ./other_directory   It seems like there should be a simple way to do this with wildcards * and regex...  Anyone have ideas?
44386
I have a directory filled with various files, differently named (i.e. not named with a specific pattern) and with different extensions, and I want to put each file in a newly created subdirectory named after each file; what's the best way to accomplish that from the command line under Linux? This sounds a bit confusing, let me make and example: let's call a random file in the directory ./filename.ext, I'd like to put it in a subdirectory called ./filename so that effectively the new path will be ./filename/filename.ext.  I did some trials with the following steps:   I've created some test files, from file-1.txt to file-9.txt, inside a test directory with for num in {1..9}; do touch file-$num.txt; done  I've created a directory named after each filename with for name in $(eval ls | cut -b 1-6); do mkdir $name; done I've moved the source files in their respective directories with for name in $(eval ls | grep -e ".txt" | cut -b 1-6); do mv $name.txt $name/$name.txt; done   As you can see, this solution works, but its huge drawback is that it works just in this case, with files of that extact filename lenght and with that particular extension. If I have some files with different names and extensions, this would be of no use at all. The use of cut command is not the ideal solution here, I suppose, but I haven't found anything better at the moment.  As a bonus, it would be cool to find a way to create the subdirs automatically when moving/renaming the files, without having to use mkdir previously (so when I ls to actually rename, I don't have to worry about excluding the newly created directories); but in the end this is a secondary problem.
91679
I've got many, many mp3 files that I would like to merge into a single file.  I've used the command line method  copy /b 1.mp3+2.mp3 3.mp3   but it's a pain when there's a lot of them and their namings are inconsistent.  The time never seems to come out right either.
8430
I'm not well versed in shell scripting but I imagine this to be a painfully easy fix but its eluding me.  I need to copy the contents of a directory excluding a number of files. I have a command that works when I enter it into the terminal, but when its run in a shell script it fails with a syntax error or just doesn't work.   The command in question is:  cp -r path/to/!(dir1|dir2|dir3) destination   Any help would be greatly appreciated!
72412
I have to deal with a large number of files nested inside of directories (one file per directory), resembling something like this:  fred/result.txt john/result.txt mary/result.txt ...   I am currently using the following command to process each of those files:  find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c \"cd '{}' &amp;&amp; processResult result.txt\" \;   I am looking for something I can add into the end of this command that will change the filenames to fred.txt, etc. and then later move the file into the parent directory to eliminate the extra layer of directories.  What would be the best way to do this?
54653
I have a folder with more than 30 sub directories and I want to get the list of the files which was modified after a specified date(say sep 8 which is the real case) and to be copied with the same tree structure with only the modified files in that folder   I have say 30 dir from that I have the list of the files I need found using last modified date Find command output  a/a.txt a/b/b.txt a/www.txt etc..   For example I want the folder "a" created and only the a.txt in it...like wise for the other also "a/b" to be created and b.txt inside it...
97449
I want to write the Ubuntu analogue of a "batch file" (a shell script). But I don't know how to use chmod +x filename command to make it so that the script can be run. Nor do I know where to use it.
60814
I have a directory structure like this:  ├── Tom │   └── c │       └── 2 │           ├── file.jpg │           └── text.txt └── Sam     ├── 1     │   └── c     │       └── music.aac     ├── E     │   └── 9     │       └── pic.jpg     └── b         ├── 9         │   └── sound.aac         └── d             └── book.doc   I'd like to move all files from the various subfolders to the main parent folders (Tom, Sam, etc.) with a single command, and then deleting all the empty subfolders. How can I do that?  Thank you
8370
I'm trying to make a zip function that'll do all the steps I typically do when zipping a file or folder. Say my current directory is ~, and I want to zip a folder named Folder1, whose file path is ~/Folder2/Folder1.  Issuing  cd ~/Folder2 &amp;&amp; zip -r Folder1 Folder1 &amp;&amp; cd -   does exactly what I want. Namely, it zips so that the output Folder1.zip does not contain folders that lead up to the folder I'm zipping (namely, /home/user/Folder2), it zips recursively, and it takes in the first argument of zip with the exact name as the file or folder I'm zipping (Folder1.zip).  So I want to make a function in my .zshrc something akin to  coolerzip() { cd /path/to/file &amp;&amp; zip -r file file &amp;&amp; cd - }   where it need only take in one argument, which in this case, it will be ~/Folder2/Folder1. Then Folder1 will be the name for both files in coolerzip, and I will cd right into ~/Folder2 so Folder1 lies in my current directory before zipping. Is there any way I can achieve this so that coolerzip only requires one argument rather than three?
95132
I'd like to know what is the command to use to gunzip all files in a target directory recursively? I tried to use the unzip command but it didn't work.  I tried the command from
32264
Is it possible to 'partition' a directory listing - say in to blocks of some number, to perform different actions on each 'range'?  For example, lets say I have the following directories inside another folder:  $ ls test abc/ def/ hij/ klm/ nop/ qrs/ tuv/ wxy/ zzz/   And I want to perform some action on the first 3 directories, another on the second 3, and so on.  My thought was that perhaps a loop across numbers would work, based on the output of something like ls | nl (but before anyone mentions it, I know parsing ls is a no-no!)  This obviously doesn't work, but illustrates my point I hope:  for dir in `ls | nl`;  do     do-something-with ${dir{1..3}} # Where $dir has taken on some numerical value linked to the folder)     do-something-with ${dir{4..6}}  # And so on...     do-something-with ${dir{n-3..n}}  done   The folders I intend to actually do this on, can be worked on in any order (i.e. the final splits can be totally arbitrary), but they have no logical naming consistency - by which I mean they can't be organised sensibly alphabetically or numerically based on any key within the directory name themselves.
8872
I've got a folder full of folders, and some of those folders may or may not have folders in them. It looks something like this:  ~/stuff/01.d/01/files ~/stuff/02.d/files ~/stuff/03.d/files ~/stuff/04.d/lol/files ~/stuff/05.d/files   I want to make separate .rars for each of the folders in ~/stuff, so I was going to do for f in *.d; do rar a "${f//.d/.rar}" "$f"; done which worked great, and gave me the rars. But I'd rather have no directory structure in the rars at all, just files. Is there an easy way to do this? It seemed like one of the switches looked like it might have done what I wanted, but the man page is a bit confusing. I'll try a few things.  I may end up trying to figure out a bash script to cd into the directory, check if it's the files, if so make the .rar in the parent (../${f//.d/.rar}), else go into the directory again and make the rar two parents up (../../${f//.d/.rar}). In this case, I'd want rar a ../"${f//.d/.rar}" * I think, I haven't tested it.