Your American History Reference Guide!
- Xargs

HistoryMania Information Site on Xargs American History American History Search        American History Browse welcome to our free resource site for all enthusiasts!

Xargs


xargs is a command of the Unix and most Unix-like operating system which eases passing command output to another command as command line arguments.

It splits its often piped input at whitespaces (or the null character) and calls the command given as an argument with each element of the split input as parameter. If the parameter list is too long, it calls the program as often as necessary. It often covers the same functionality as the backquote feature of many shells, but is more flexible and often also safer, especially if there are blanks or special characters in the input.

This is often used in conjunction with the Unix commands find, locate and grep.

Example

  • find . -name "*.foo" | xargs grep bar in practice does the same as grep bar `find . -name "*.foo"`, but will work even if there are so many files to search that they will not all fit on a single command line. It searches in all files in the current directory and its subdirectories which end in .foo for occurrences of the string bar.
  • find . -name "*.foo" -print0 | xargs -0 grep bar does the same thing, but uses GNU specific extensions to find and xargs to separate filenames using the null character; this will work even if there are whitespace characters, including newlines, in the filenames.

External links

The contents of this article are licensed from Wikipedia.org under the
GNU Free Documentation License. How to see transparent copy
Search | Browse | Contact | Legal info