xargs
can be used to process output from other commands (such as find
) as argument to a new commands.
It can come very handy in many cases, here are 3:
1. Finding and deleting .zip
files:
$ find . -name "*.zip" -type f -print | xargs /bin/rm -f
2. Finding all .py
files importing ujson
:
$ find . -name '*.py' | xargs grep 'import ujson'
3. Process input from a file here changing permissions on a file list:
$ xargs -a file-list.txt -t -d: chmod -v 644
# -a to tell what file
# -t for grouping
# -d for telling the delimiter
GNU find provides a
--delete
option