xargs

The xargs command is commonly used with find to perform a command on each of files that match the search critera, by piping the results of the find command into xargs.

find ./ -type f -print | xargs -i mv -f {} ./newdir

This will move all files from the current directory to newdir. Each result from the find command replaces the {} characters before mv is called. So, if the find command returns

file1.txt
file2.txt

then the following is executed:

mv -f file1.txt ./newdir
mv -f file2.txt ./newdir

Also see

Last modified: 07/05/2006 (most likely earlier as a site migration in 2006 reset some dates) Tags: (none)

Go to top

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top