When you try to do any operation in unix (eg. tar, mv, cp) that involves too many arguments (or filenames), then you might get an “Argument list too long” error.
Here’s a solution:
1. Create a file with all the arguments (or filenames).
ls -1 > filenames.txt
2. Use xargs command to read in the file and pipe it into the unix command you’re executing.
xargs -a filenames.txt mv -t /otherfolder/.
There are several ways around this. You can also write a for loop in a script and some commands let you use a file as arguments.
For example, the tar command can be executed as
tar -cvzf archive.tar.gz --files-from filenames.txt