Another Useful Copy Command
Saturday, May 8th, 2010I last came up with this subject a while ago, whilst working on my own backup. Been needing something slightly different, which allows pulling out files of the same type. This one uses find rather than a straight cp function.
find /pathtoinputdir/ -name “*.*” -type f -exec cp -urvp ‘{}’ /pathtooutputdir \;
I’ll break it down again:
find /pathtoinputdir/ (pretty obvious, you could use just / to search your whole drive)
-name “*.*” (what to search for, replace *.* with anything you want to search for, but say you wanted to find all your jpg files, change it to *.jpg)
-type -f (brings back files as opposed to directories)
-exec (allows a function to run based upon what is found by find)
cp -urvp ‘{}’ (the copy with arguments and some magic (the brackets) which allows files and directories with spaces, newlines etc. See my other post to get descriptions of the cp arguments. You could replace cp with mv if you wanted to move and not copy)
/pathtooutputdir (straight forward again, I create it first)
\; (more magic to go with the brackets)
Word of warning, if you have lots of files with the same name but different contents, you will overwrite the older ones with the latest one, regardless of content