Linux/General – tar – Too many arguments

Occasionally, when working in directories with large numbers of files and/or directories contained within them, you will get an error stating: Too many arguments.

This is not an error from the application. Rather, it is an error from the shell erroring on ARG_MAX limit reached.
 There are a few ways to get around this, none of them are particularly elegant:

Using tar inside of a directory with too many files.

find . -print | tar -cvzf archive.tar.gz --files-from -

Using cp to move files, but too many files to work with:

for x in $( ls ); do cp $x /new/location; done

These are just some examples of ways to get around that problem. As a rule of thumb, try to keep the number of files in any given directory to < 1024.