Skip to content

Instantly share code, notes, and snippets.

@lbydev
Forked from nepsilon/3-xargs-tips.md
Created July 19, 2017 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbydev/423c6526bc2d0e58f96ce42b2dd36c35 to your computer and use it in GitHub Desktop.
Save lbydev/423c6526bc2d0e58f96ce42b2dd36c35 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment