Related
Quick Links
xargs is fireworks for your shell commands.
Learn to harness this great power of xargs today!
The information presented here is based on research and many years of experience using this particular method and approach.
Pipes and xargs
Anyone learning Bash will grow in their command line scripting skills over time.
The syntax is as good as identical.
And, as skills improve, newer engineers will usually discover the Pipe idiom first.
For example, consider this situation:
Here we start a sleep in the background.
The problem is thatkilldoes not accept the input directly, whether it comes frompsor even from a simpleecho.
It is thus as if we executedkill -9 some_piddirectly.
Shutterstock/ksb
One small change to code (i.e.
Still, even this has it’s limitations.
How about if we wanted to provide some nice debug information printed inline and from within the statement?
It seems impossible thus far.
Let’s take our previous example and inject some debugging information without post-processing the outcome.
There is a lot of power here.
Otherwise, if the secondechowas not there, the firstechowould start to output ‘The PID …’ etc.
We first create three files, a, b and c, and a subdirectory named subdir.
We can also see how there are no more files in the subdir.
Wrapping up
Usingxargsbeing great power to an advanced Linux (and in this case) Bash user.