Wanted to copy all my EPM .list files to a separate folder so I can do a bit of edit and test with it. Wanted to do it in a true geek mode and hence decided to make use of bash’s find command (Thanks to floyd_n_milan for introducing me to this wonderful command). Since it some time I really used `find`, I had to do a bit of Googling to find I needed. This might be a piece of piss for seasoned Bash’ers but for me it was a chance to revive my detoriating Bash knowledge and as it always happens, I love to post newbie stuffs.
$ find ./myproj/pkgs -name \*.list -exec cp {} epm-list/ \;
This command searches the myproj/pkgs directory (within current directory) and its sub-directories for files ending with .list. Upon each file found, it executes the `cp` command copying the file to the directory epm-list. The {} is replaced by the name of the file found (each time).
Please note the escaping ‘\’ before the ‘*’ in the regular expression and before the trailing ‘;’. If you miss the trailing semicolon or the escaping, bash will complain that the -exec has no options. We need not put `epm-list/{}`, it uses the file name automatically (if we use {} then it tries to put the file in epm-list/<path-where-the-file-is-actually-found> which ends in a path not found error).
Thanks. Works fine.
Thanks, I used this slightly modified version to copy over all my custom Intellij files when I checkout a new branch of code from cvs or svn.
#execute from within the origin branch
# e.g. If copying from ~/branches/seventeen to ~/branches/seventeen_one, then cd into ~/branches/seventeen to execute
#copies .ipr, .iml, .iws
find . -name \*.i?[lrs] -exec cp {} ../seventeen_one/{} \;
Thanks a lot, have been messing up my foto and movie collection… This SIMPLE explanation provided a real time saver.
Thanks a lot man, really helped.
Brilliant, thanks for that. Saved me a lot of IT support time.
Pingback: Command line method to copy all files out of a folder tree « Rforge