The xargs
command is commonly used with find
to perform a command on each of files that match the search criteria, 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
Reference: Using the xargs Command