find - search for files in a directory hierarchy
xargs - build and execute command lines from standard input
Using find and xargs we can search any file in the directory hiearchy and xargs execute the command accepting the output of find command as input.
Use xargs with -I option to replace occurrences of replace-str in the initial-arguments with names read from standard input(In our case from find command). The placeholder following the -I is a string that can appear multiple times in the command.
Example: Below command will find all files with pattern *.txt in current directory and move to /NewDir/.
find . -name "*.txt" | xargs -I '{}' mv '{}' /NewDir/'{}'
Here '{}' is placeholder
No comments:
Post a Comment