can anyone help me with this?
I am trying to copy images from my USB to an archive on my computer, I have decided to make a BASH script to make this job easier. I want to copy files(ie IMG_0101.JPG) and if there is already a file with that name in the archive (Which there will be as I wipe my camera everytime I use it) the file should be named IMG_0101.JPG.JPG so that I don't lose the file.
#method, then
mv IMG_0101.JPG IMG_0101.JPG.JPG
else mv IMG_0101 path/to/destination
There is a race condition here (if another process could create a file by the same name between the first
done
and thecp
) but that's fairly theoretical.It would not be hard to come up with a less primitive renaming policy; perhaps replace
.JPG
at the end with an increasing numeric suffix plus.JPG
?Use the last modified timestamp of the file to tag each filename so if it is the same file it doesn't copy it over again.
Here's a bash specific script that you can use to move files from a "from" directory to a "to" directory:
Here's some sample output (using the above code in a script called "movefiles"):