xargs is a extended arguments. xargs connects two commands, evaluate output of one command and apply this generated output to second command.
Syntax of Linux xargs?¶
To use the xargs command in the terminal, use the following syntax:
Prompt
This causes the second command to be executed with the arguments of the first one.
Options...
- -0 or –null: This option causes each character to be taken literally and arguments to be separated because of the NULL character.
- -a or –arg-file: With this option, arguments aren’t read from standard input, but from a file.
- -d or –delimiter: Separations are made with this option based on the separator character and not the space character. Each character is treated literally.
- -p or –interactive: This option queries whether to continue before executing each command.
Examples¶
The functionality of the xargs command is best shown with some examples.
Prompt
In this example, you apply xargs with the Linux find command and the Linux rm command. The result is that all files with the extension .txt are removed from the computer’s file system.
Prompt
Find all files containing the word “invoice”. For this, you can also use the Linux grep command.
Prompt
Above command will get the output of size of "/boot" directory and xargs will divide that size with 1024