title: Understanding the UNIX command xargs
body: <p>I'm pretty much confused on this. Need some clarifications.</p>
  
  <p><strong>Example 1 :</strong></p>
  
  <pre><code>pgrep string | xargs ps
  </code></pre>
  
  <p><strong>Example 2 :</strong></p>
  
  <pre><code>find . | xargs grep whatever
  </code></pre>
  
  <p>From Example 1, I gather it's this way:</p>
  
  <p>Search for a "string" which is part of name of running process and return the process-ids of all the matches to 'xargs ps' -> which just appends ps to the matches (which are process-ids themselves) to get the same output as :</p>
  
  <pre><code>ps &lt;processid&gt;
  </code></pre>
  
  <p>Can someone explain what xargs really does in this case?</p>
  
  <p>From Example 2, I gather it's this way:</p>
  
  <p>It's to search for some "string" recursively from the current working directory.
  Here, how exactly does 'xargs' work?</p>
  
  <p>I was of the opinion that 'xargs' repeatedly appends data from standard input to the 'argument' given to xargs (which usually is a UNIX command by itself). </p>
  
  <p>From xargs() man page :</p>
  
  <blockquote>
    <p>xargs reads items from the standard input, delimited by blanks (which  can  be 
    protected with  double or single quotes or a backslash) or newlines, and
    executes the command (default is /bin/echo) one or more times with any 
    initial-arguments  followed  by items read from standard input. Blank lines
    on the standard input are ignored.</p>
  </blockquote>