Skip to Content
Small, Sharp Software Tools
book

Small, Sharp Software Tools

by Brian P. Hogan
June 2019
Intermediate to advanced
328 pages
7h 27m
English
Pragmatic Bookshelf
Content preview from Small, Sharp Software Tools

Using xargs

The xargs program takes data from standard input and lets you use it as arguments to another program. To understand how it works, let’s do something incredibly trivial: print out the numbers 1 to 5 with echo, using xargs. You’ll use the seq command, which prints out a sequence of numbers, each on its own line.

 $ ​​seq​​ ​​5​​ ​​|​​ ​​xargs​​ ​​echo
 1 2 3 4 5

What actually happened here? The numbers 1 through 5 were passed as arguments to the echo command. You can see this for yourself with the -t argument:

 $ ​​seq​​ ​​5​​ ​​|​​ ​​xargs​​ ​​-t​​ ​​echo
 echo 1 2 3 4 5
 1 2 3 4 5

If you don’t specify a command, xargs uses echo by default. Test it out:

 $ ​​seq​​ ​​5​​ ​​|​​ ​​xargs​​ ​​-t
 echo 1 2 3 4 5
 1 2 3 4 5

Printing ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The VimL Primer

The VimL Primer

Benjamin Klein
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz

Publisher Resources

ISBN: 9781680507003Errata Page