tags:

views:

104

answers:

3
+3  A: 

Use -print0 instead of -print on the find command, and the xargs -0 (or --null) option - then NULs will be used as separators rather than newlines and spaces.

find ./dir -type f -iname "*.t[argz]*[bz2]" -print0 | xargs --null mv --target-directory=dir
martin clayton
$ find ./ -type f -iname "*.xls" -print0 | xargs mv --null --target-directory=xlsxargs: Warning: a NUL character occurred in the input. It cannot be passed through in the argument list. Did you mean to use the --null option?mv: unrecognized option `--null'Try `mv --help' for more information.
Sorry - should have been an xargs option, not a mv option! Fixed.
martin clayton
A: 

Have you looked at the -exec option for find?

find ./dir -type f -iname "*.t[argz][bz2]" -exec mv {} --target-directory=dir ';' 

The -exec option will execute any options following it as a command until it sees the semi-colon wrapped in quotes. This way you won't have to deal with the spacing issue.

Sean Madden
This spawns a subprocess for every file, though, where the xargs variant batches hundreds of files up onto the same command line. For small operations like a single mv invocation, that can be a significant performance difference. Though you have to use -print0 and --null as martin points out above unless you're absolutely sure the filenames have no whitespace.
Andy Ross
+1  A: 

GNU find

find ./dir -type f -iname "*.t[argz]*[bz2]" -exec mv "{}" /destination +;
ghostdog74