I've been beating my head against this for a while, but I'm really not a good script writer. Apologies…
I'm running Ubuntu/gnome 18.10, and have a large set of pictures exported from my wifey's mac. The directory structure is:
year1
(login dir name with spaces) - Month
Image names
year2
...
as in:
2013
May 4, 2013
Image1.jpg
Image2.jpg
May 5, 2013
Image 1.jpg
Image 3.jpg
June 22, 2013
What I would like, is:
2013
January
All the "january" images...
February
All the...
I can create the directories easily enough mkdir {January..December}
suffices. But I cannot figure out how to walk the ugly directory tree (exported from Mac), move the images, and then delete the ugly directory.
Best Answer
Here is such script:
The script should be executed in the first level directory where your images are located. You should tweak the destination directory -
DEST="/tmp/new-order-pictures/"
. This version of the script relies that all files are in directories that contain the name of a month in one way or another. Example of usage:In my case the script is named
order.sh
and it is located in~/bin
, thus I can use it as shell command. In the example you can see the directory structure is changed but the number of files is 14 in both structures.Here is another version of the script that use
mv
instead ofcp
and will deal also with the files which are not in directories that contain the name of a month. Before running this script it is a good idea to create a backup copy of the original directory structure.Example of usage:
After that you can go inside the destination directory and use the
rename
command withinfor
loop to deal with the long names:Example:
Or you can change
(\.[0-9a-zA-Z]+)
with(\.jpg)
, then on next iteration with(\.mpg)
(respectivelyImage-
withVideo-
), etc. References about this usage ofrename
:How to rename multiple files sequentially from command line?
Renaming hundreds of files at once for proper sorting