Command usage with options
xargs --version
Prints the version number of xargs command and then exit.
Output :
xargs (GNU findutils) 4.7.0-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
xargs -a test.txt
It will show contents of file
file1
file2
file3
file4
xargs -p -a test.txt
-p option prompts for confirmation before running each command line. It only runs the command line if the response starts with ‘y’ or ‘Y’ Output :
# xargs -p -a test.txt
echo file1 file2 file3 file4 ?...y
file1 file2 file3 file4
# xargs -p -a test.txt
echo file1 file2 file3 file4 ?...n
xargs -r -a test.txt
Now, let’s suppose the file “test.txt” is empty, and above command is executed, -r option ensures if standard input is empty, then command is not executed, so above command will not produce any output, But, if above command is executed without -r option, it will produce a blank line as output. See below image as instance :
xargs command in Linux with examples
xargs is a Unix command which can be used to build and execute commands from standard input.
Importance:
Some commands like grep can accept input as parameters, but some commands accept arguments, this is a place where xargs came into the picture.