June 2019
Intermediate to advanced
328 pages
7h 27m
English
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 ...