home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


xargs [options ] [command ]

Execute command (with any initial arguments), but read remaining arguments from standard input instead of specifying them directly. xargs passes these arguments in several bundles to command , allowing command to process more arguments than it could normally handle at once. The arguments are typically a long list of filenames (generated by ls or find , for example) that get passed to xargs via a pipe.

Without a command , xargs behaves similarly to echo , simply bundling the input lines into output lines and printing them to standard output.


-e [string ]

Stop passing arguments when argument string is encountered (default is underscore). An omitted string disables the logical EOF capability.

-E string

Use string instead of underscore as the default logical EOF string. Solaris only.

-i [string ]

Pass arguments to command , replacing instances of {} on the command line with the current line of input. With Solaris, the optional string can be used instead of {} .

-I string

Same as -i , but string is used instead of {} .

-l [n ]

Execute command for n lines of arguments. With Solaris, default n is 1 when -l is supplied.

-L n

Same as -l n . Solaris only.

-n n

Execute command with up to n arguments.


Prompt for a y to confirm each execution of command . Implies -t .

-s n

Each argument list can contain up to n characters. (Older systems limited n to 470. The default is system-dependent.)


Echo each command before executing.


Exit if argument list exceeds n characters (from -s ); -x takes effect automatically with -i and -l .


grep for pattern in all files on the system:

find / -print | xargs grep

 > out &

Run diff on file pairs (e.g., f1.a and f1.b , f2.a and f2.b ...):

echo $* | xargs -n2 diff

The previous line could be invoked as a shell script, specifying filenames as arguments.

Display file , one word per line (similar to deroff -w ):


 | xargs -n1

Move files in olddir to newdir , showing each command:

ls olddir | xargs -i -t mv olddir/{} newdir/{}

Previous: Reference: whoami UNIX in a Nutshell: System V Edition Next: Reference: xgettext
Reference: whoami Book Index Reference: xgettext

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System