Find all images, append unique prefix to name and move to different directory

Hi,

I have a directory with Multiple subdirectories and 1000s of pictures (jpg) in each directory. The problem is that each directory has a 001.jpg in them. I want to append a unique name (the directory_name)would be fine. and then move them to one main backup directory once they have been renamed.

I used the find command below on a test dir but it blew away duplicate names.

find ./ -type f -exec mv {} . \;

---------- Post updated at 01:37 PM ---------- Previous update was at 12:38 PM ----------

found the solution...

[CODE]rename -v 's/(.*)\/(.)/$1_$2/;' */

renames all the files in each directory with the directoryname_filename then moves them to the parent folder.

Glad rename works for you, my rename (version 2.19.1) dosn't support the -v option. For others in this boat the following ksh/bash script should work:

find . \( -iname '*.jpg' -o -iname '*.jpeg' \) -type f -print | while read file
do
   NF=${file#./}
   NF=${NF//\//_}
   [ "$file" = "$NF" ] || mv $file ./$NF
done

Wonder if your going to want something that removes empty directories next :wink: