Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)
xargs(1) OSS Shell and Utilities Reference Manual
main.c readit.c
gettoken.c
putobj.c
Then xargs constructs and runs the command:
ls -l main.c readit.c gettoken.c putobj.c
Each shell command line can be up to LINE_MAX bytes long. If cfiles contains more
filenames than fit on a single line, then xargs runs the ls command with the filenames
that fit. It then constructs and runs another ls command using the remaining filenames.
Depending on the names listed in cfiles, the commands might look like the following:
ls -l main.c readit.c gettoken.c...
ls -l getisx.c getprp.c getpid.c...
ls -l fltadd.c fltmult.c fltdiv.c...
2. To construct commands that contain a certain number of filenames, use a command line
similar to the following:
xargs -t -n 2 diff <<end
starting chap1 concepts chap2 writing
chap3
end
This constructs and runs diff commands that contain two filenames each (-n 2):
diff starting chap1
diff concepts chap2
diff writing chap3
The -t flag tells xargs to display each command before running it so that you can see
what is happening. The <<end and end arguments define a Here Document, which uses
the text entered before the end line as standard input for the xargs command. (For more
details, see the section Inline Input (Here) Documents in the sh reference page.)
3. To insert filenames into the middle of commands, use a command line similar to the fol-
lowing:
ls | xargs -t -r mv {} {}.old
This renames all files in the current directory by adding .old to the end of each name.
The -r tells xargs to insert each line of the ls directory listing where {}(braces) appear.
(You might need to precede the braces with shell escape characters, depending on what
shell you are using.)
If the current directory contains the files chap1, chap2, and chap3, then this constructs
the following commands:
mv chap1 chap1.old
mv chap2 chap2.old
mv chap3 chap3.old
4. To run a command on files that you select individually, use a command line similar to the
following:
ls | xargs -p -n 1 ar r lib.a
This allows you to select files to add to the library lib.a. The -p flag tells xargs to
display each ar command it constructs and ask if you want to run it. Press y, or the
10−34 Hewlett-Packard Company 527188-021