Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active July 19, 2017 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nepsilon/9a7f52df0ca034403f79 to your computer and use it in GitHub Desktop.
Save nepsilon/9a7f52df0ca034403f79 to your computer and use it in GitHub Desktop.
3 xargs usage tips — First published in fullweb.io issue #26

3 xargs tips on the road to CLI mastery

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
@floudet
Copy link

floudet commented Dec 22, 2015

GNU find provides a --delete option

@nepsilon
Copy link
Author

Thanks @floudet for the info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment