Skip to Content
Mac OS X in a Nutshell
book

Mac OS X in a Nutshell

by Jason McIntosh, Chuck Toporek, Chris Stone
January 2003
Intermediate to advanced
832 pages
32h 40m
English
O'Reilly Media, Inc.
Content preview from Mac OS X in a Nutshell

Name

xargs

Synopsis

xargs [options] [command]

Executes command (with any initial arguments), but reads 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.

Options

-0

Expect filenames to be terminated by NULL instead of whitespace. Do not treat quotes or backslashes specially.

-n args

Allow no more than args arguments on the command line. May be overridden by -s.

-s max

Allow no more than max characters per command line.

-t

Verbose mode. Print command line on standard error before executing.

-x

If the maximum size (as specified by -s) is exceeded, exit.

Examples

grep for pattern in all files on the system, including those with spaces in their names:

                     find / -print0 | xargs -0 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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mac OS X Internals: A Systems Approach

Mac OS X Internals: A Systems Approach

Amit Singh
C++ In a Nutshell

C++ In a Nutshell

Ray Lischner
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar
Optimized C++

Optimized C++

Kurt Guntheroth

Publisher Resources

ISBN: 0596003706Supplemental ContentCatalog PageErrata