Argument too long for operation of many files

Argument too long for operation of many files

I encountered several times when trying to cp/rm/cat >10000 files on Mac. Just a note for the solutions.

There is a very useful post to find and overcome the line length limitations. As written there are two solutions:

  • using the find or xargs command
  • using a loop

For instance I have >10000 files to concatenate and I cannot use

cat Smp*counts.txt > bigFile.txt
rm -f Smp*counts.txt

Instead I can use

find . -name "Smp*-bTcounts.txt" -exec cat '{}' ';'|sort >bT-colCounts.txt
find . -name "Smp*-bTcounts.txt" -delete
# or 
echo Smp*-bTcounts.txt | xargs /bin/rm -f
Z. Lu avatar
Z. Lu
Data mining, bioinformatics, parasites, retro, plain text.
comments powered by Disqus