The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: explain Xargs ?
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 01-07-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,893
xargs runs the specified arguments as a command, followed by the filenames provided from standard input. If the length of a command line exceeds UNIX's capability, it runs the command again with the remaining arguments (and repeats until all arguments are consumed).

The reason you do this instead of: find . -type f -exec grep ... is because (1) you don't have to mess with the funny {} syntax and (2) it's more efficient -- fewer invocations of grep, and (3) when grep receives multiple arguments on the command line, it preceeds each match with the filename, so that you know which file grep found it in. (You can do this with find, but it's a hack).