Полезная информация

UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: Reference: writeChapter 2
UNIX Commands
Next: Reference: yacc


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.



Stop passing arguments when argument string is encountered (default is underscore).


Pass arguments to command, replacing instances of { } on the command line with the current line of input.


Execute command for n lines of arguments.


Execute command with up to n arguments.


Prompt for a y to confirm each execution of command.


Each argument list can contain up to n characters (470 is the default and the maximum value).


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 pattern > 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 would be invoked as a shell script, specifying filenames as arguments. Display file, one word per line (same as deroff -w):

cat file | xargs -n1

Move files in olddir to newdir, showing each command:

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

Previous: Reference: writeUNIX in a Nutshell: System V EditionNext: Reference: yacc
Reference: writeBook IndexReference: yacc

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