title: Why "xargs -I {}" gets errors "wc or ls: {}: open: No such file or directory" but "xargs without -I {}" works?
body: <h4>What works: <code>xargs</code> without <code>-I {}</code></h4>
  <p>I find all &quot;.txt&quot; files in my documents folder (about 5000 found) and use <code>wc -l</code> on them.</p>
  <pre><code>find . -type f -name &quot;*.txt&quot; -print0 | xargs -0 wc -l &gt;| ~/Downloads/xargs_wc.txt
  </code></pre>
  <h4>Problem: <code>xargs -I {}</code></h4>
  <p>I now use <code>xargs -I {}</code> to find the same files:</p>
  <pre><code>find . -type f -name &quot;*.txt&quot; -print0 | xargs -0 -I {} wc -l {} &gt;| ~/Downloads/xargs_I_wc.txt
  </code></pre>
  <p>I get consistently 8 lines of error output, corresponding to 8 files missing from <code>~/Downloads/xargs_I_wc.txt</code>:</p>
  <pre><code>wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  </code></pre>
  <h4>Debugging</h4>
  <p>I do a diff between <code>~/Downloads/xargs_wc.txt</code> and <code>~/Downloads/xargs_I_wc.txt</code> to get the actual files.</p>
  <p>The 8 filenames are clean, the file contents are clean, all the files are able to be <code>wc -l</code>'ed manually, I can <code>open</code> them from the Terminal, and running <code>file</code> on them gives, in order:</p>
  <pre><code>... ASCII text   (wc gives 202 lines for this file)
  ... ASCII text   (16 lines for this one)
  ... ASCII text   (16 lines for this)
  ... ASCII text, with no line terminators   (132 lines each for the rest)
  ... ASCII text, with no line terminators
  ... ASCII text, with no line terminators
  ... ASCII text, with no line terminators
  ... ASCII text, with no line terminators
  </code></pre>
  <p>The first 3 files are like LICENSE files, of which the first one is in its own directory, and the next two are in relatively close proximity to each other. The last 5 are data files written in TSV format, all relatively close to each other.</p>
  <p>The only thing that I find similar with the files is that doing <code>ls -l</code> on them, they all have the &quot;@&quot; symbol as their last symbol, but that's true for a lot of the files found:</p>
  <pre><code>-rw-r--r--@ ...
  etc ...
  </code></pre>
  <h4>Debugging - doing <code>ls</code> instead</h4>
  <p>I use <code>ls</code> instead of <code>wc</code>:</p>
  <pre><code>find . -type f -name &quot;*.txt&quot; -print0 | xargs -0 -I {} ls -l {} &gt;| ~/Downloads/xargs_I_ls.txt
  </code></pre>
  <p>8 similar error lines get output:</p>
  <pre><code>ls: {}: No such file or directory
  ls: {}: No such file or directory
  ls: {}: No such file or directory
  ls: {}: No such file or directory
  ls: {}: No such file or directory
  ls: {}: No such file or directory
  ls: {}: No such file or directory
  ls: {}: No such file or directory
  </code></pre>
  <p>I don't know why <code>xargs -I {}</code> is not working.</p>
  <h4>Further debugging - manipulating offending files</h4>
  <p>I copy the directory of one of the failing files to the root of my documents folder. I do same test with <code>xargs -I {} wc -l</code>:</p>
  <pre><code>find . -type f -name &quot;*.txt&quot; -print0 | xargs -0 -I {} wc -l {} &gt;| ~/Downloads/xargs_I_wc_after_copy.txt
  </code></pre>
  <p>Same 8 error lines are output:</p>
  <pre><code>wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  </code></pre>
  <p>I don't know what's going on, I should be getting 9 error lines.</p>
  <h4>Even further debugging</h4>
  <p>I duplicate one of the other offending files in its own directory. I run same test.</p>
  <pre><code>find . -type f -name &quot;*.txt&quot; -print0 | xargs -0 -I {} wc -l {} &gt;| ~/Downloads/xargs_I_wc_after_duplicate.txt
  </code></pre>
  <p>This time I get 9 error lines:</p>
  <pre><code>wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  wc: {}: open: No such file or directory
  </code></pre>
  <p>I do many manipulations on the duplicated file: I run chmod's, I empty the file, I change the file contents, I rename the file, I repeatedly save the file, but I always get 9 error lines.</p>
  <p>I create a new blank file and copy the contents of the original offending file into  it, but I don't get 10 error lines, I get 9 error lines still.</p>
  <p>If I move an offending file one directory outside of its current directory, I get 8 error lines. If I move the file back in, I get 9 error lines again.</p>
  <p>There are other &quot;.txt&quot; files in the offending files' directories, but they don't cause errors.</p>
  <p>The directories of the offending files do not appear to be special in any way.</p>
  <p>Apart from deleting all the offending files, or moving them away, or creating new identical-content copies in their place, I don't know how to figure out how to get rid of their errors or what the reason is for why they're erroring.</p>
  <h4>Questions</h4>
  <p>What is going on with my seemingly normal and mundane files that is causing them to fail an <code>xargs -I {}</code>?</p>
  <p>How do I get more info on what is causing them to fail and find the root cause?</p>