Skip to Content
Navigation:

A stick figure smiling

Here's a preview from my zine, Bite Size Command Line!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

Image of a comic. To read the full HTML alt text, click "read the transcript". get the zine!
read the transcript!

xargs takes white space separated strings from stdin and converts them into command-line arguments

$ echo "/home /tmp" 
| xargs ls 

will run ls /home/tmp

this is useful when you want to run the same command on a list of files!

  • delete (xargs rm)
  • combine (xargs cat)
  • search (xargs grep)
  • replace (xargs sed)

how to replace “foo” with “bar” in all .txt files:

find. -name '*.txt' | 
xargs sed -i s/foo/bar/g

how to lint every Python file in your Git repo:

git ls-files | grep pyl 
xargs pep8

if there are spaces in your filenames “my day.txt” xargs will think it’s 2 files

““my” and “day.txt” fix it like this:

find -print0 |  
xargs -0 COMMAND

more useful xargs options

-n 1 (max-args): makes xargs run a separate process max-args for each input
-P (capital P, max-procs): is the max number of parallel processes xargs will start