![]() |
who's good at the terminal? need to move a bunch of files into directories - Printable Version +- MacResource (https://forums.macresource.com) +-- Forum: My Category (https://forums.macresource.com/forumdisplay.php?fid=1) +--- Forum: Tips and Deals (https://forums.macresource.com/forumdisplay.php?fid=3) +--- Thread: who's good at the terminal? need to move a bunch of files into directories (/showthread.php?tid=88937) |
who's good at the terminal? need to move a bunch of files into directories - mattkime - 12-04-2009 i have thousands of images named by the time they were taken and i need to move them into directories to make them more manageable. for instance, all files named starting with 91108 need to go into 2009-11/08/ i know mv is the command, i know * is the wildcard, but i don't know how to put it all together. do you? thx! Re: who's good at the terminal? need to move a bunch of files into directories - freeradical - 12-04-2009 How about output redirection. For example, you can redirect the output of the "ls" command from the monitor to a file that you create on the fly like so: ls > filename Can this also be used to create directories on the fly? Re: who's good at the terminal? need to move a bunch of files into directories - TheCaber - 12-04-2009 Assuming you are in the directory where all the photo files reside, and that you want to add directories in the same directory: $ mkdir -p 2009-11/08 $ mv 91108* 2009-11/08 will create the new directory (actually a new directory 2009-11 and a subdirectory 08 within that) and move all files beginning 91108 into the new (sub)directory. I'll have to think a bit about processing all of 2009 ... Re: who's good at the terminal? need to move a bunch of files into directories - TheCaber - 12-04-2009 Here's a bash shell script that should do what you want. copy the lines inside (not including) the ==snipsnip== into a file called, say foo.sh =========snipsnip================= #!/bin/bash=========snipsnip================ make foo.sh executable: $ chmod +x foo.sh and put it in the directory where the photos reside, and where the new month directories (and their respective day subdirectories) will be. $ ./foo.sh will run the new script. The script is set to only echo the commands it would do to create each directory and move files to it. (debug=1 at the beginning). To make it run for real, edit the script and change debug=1 to debug=0 and run the script. Directories will be created and files moved. Test it first. Make a directory with copies of a few photo files of different dates. (or you can just sit in the new empty test directory 'touch' some file names to create empty files to be moved). Re: who's good at the terminal? need to move a bunch of files into directories - Article Accelerator - 12-04-2009 These GUI-based utilities may do: Hazel: http://www.noodlesoft.com/hazel.php Automaton: http://www.tech.com.au/Site/Home.html |