[xargs]How to use 'xargs' command?

D

Deleted member 107511

Guest
Hello,
First of all, sorry for such a silly question, but i really did not understood that what does 'xargs' command do!
Already Read: 'man xargs', google.com
Thanking you...
 


Hello.
Okay, here follows a try of a simple descrition for you:
If you run a commandand that produce an output (result of the programm) and you want to use this output as input (argument) for an other command, you can perform this task with xargs in one step. By default xargs use 'echo' as command to write the result on standard output.
Thats the main purpose of it.

Example:
command1 (produce an output ->) | xargs [options] command2 (<- take the output of command1 as input)

For more you realy must read intensive the manpage. There are more complexe ability of xargs, but so i hope you now can understand the base of the xargs usage.

Good luck
 
Hello.
Okay, here follows a try of a simple descrition for you:
If you run a commandand that produce an output (result of the programm) and you want to use this output as input (argument) for an other command, you can perform this task with xargs in one step. By default xargs use 'echo' as command to write the result on standard output.
Thats the main purpose of it.

Example:
command1 (produce an output ->) | xargs [options] command2 (<- take the output of command1 as input)

For more you realy must read intensive the manpage. There are more complexe ability of xargs, but so i hope you now can understand the base of the xargs usage.

Good luck
First of all Thanking you for your very helpful reply, but may i ask a related question that:
Why was 'xargs' created, if there is "<command> | <command1> -"(that dash at the end)?
Thank you once again...
 
The point is in this case is the more powerfull usage of the tool. If your command1 has more then one lines of output, xargs perform the action for every single 'result'. So you not need to create complex structures like a loop or else. How i sad: Best to read the manpage in detail to understand what all to do with xargs.
 
“xargs” is a command on Linux operating systems used to build and execute commands from
standard input. It converts input from standard input into arguments to a command. Some commands
such as “grep” and “awk” can take input either as command-line arguments or from the standard input.
However, others such as “cp” and echo can only take input as arguments, which is why “xargs” is
necessary.
I use it to remove left over "rc" packages which come from kernel upgrades and the like and are left over files

How to remove "rc" Packages

dpkg --list |grep "^rc"

dpkg --list |grep "^rc" |cut -d " " -f3

dpkg --list |grep "^rc" |cut -d " " -f3 |xargs sudo dpkg --purge
 
Last edited by a moderator:

Members online


Top