Samstag, August 18, 2012

copy/move files with find

To copy or move files from different locations in a subtree into a single directory find is your friend.

find . -name "select_*" | while read f; do cp -iv $f ~/destination/${f##.*/}; done

My natural first try with -exec didn't work. I was not able to use parameter expansion of the shell on {} from find. Assigning the -exec parameter {} to a variable and use it with the next command didn't work, because find interpreted the ; as exec end. Escaping the -exec command with "" did result in No such file or directory.

[todo] Play with this in a quite minute.