Richard Bucker

bash one-liner; copy and make unique

Posted at — Feb 27, 2015

As part of the ongoing process of correcting my lost images in iPhoto I offer this one-liner:find . -name “*.mov” -exec env file={} bash -c ‘base="$(basename “$file”)";dir="$HOME/Desktop/Movies";pre=$(echo $RANDOM);cp "$file" "$dir/$pre-$base"’ ;  > work. ./work Here’s the problem: I have a folder called “Master” and in that folder there are many sub-folders. Each folder path represents the year/month/day that the images were imported. Now that I am trying to import some MOV files it appears that the iPhoto importer does not like duplicate filenames in the same day. This was evidenced when iPhoto failed to import many MOV files without an explanation.So I tried to find and copy the files with a simple find command. Unfortunately the source path included spaces and since the copy was into a ingle folder it resulted in duplicate filenames so instead of 2200 files I had about 1000.The command above will:locate the MOV files in the source treecopy the file from the source folder to the destination folderand rename the file by inserting a random number as the filename’s prefixWell, it’s not pretty but it works. I wonder if I should have been able to perform this function using the installinator?