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.
There is an application which can move and rename the files in a single command line -
exiftool
In my case, the specific command line used was
or
depending upon which tag is present in the images. If the requested tag is not present, the application throws a warning and does not move that file, but continues processing. This application also handles multiple images with the same date/time by appending a numeric to the end of the filename.
I did have several images without exif data, and I was able to add exif data to the images with the command
As an example, I placed some images in a directory ~/aa/test1 and ran the tool, placing the output in ~/aa/test2. The results are below:
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
So, I assume you want a step-by-step and simple solution. First, I would address the problem of Whitespace and comma in the folders. I would first cd into the year folder and use
rename
to first remove WhitespaceSimilarly, remove comma
Now that I have all the folders as desired I would create a month based list using
Now make folder "January"
Then loop thru the list using
xargs
to copy their contents