I ran into this situation when working with 4.2 BSD long ago. Under the covers, the shell has a memory space in the environment to use to pass command line arguments to invoked programs. As has been mentioned, it varies from Unix to Unix, but is often a tunable parameter in the OS.
Expanding this space on the system bumps up the memory requirement for the whole system, so that may not be optimal for you. What would be useful to explore for your purpose is the use of the -exec option in a 'find' syntax, as in this syntax to recursively find and delete files (type f) in the current directory (and below) which are older than 30 days (-mtime +30):
find . -type f -mtime +30 -exec rm {} \;
Its very powerful, and find itself is doing the removal, so there is no limit on the number of files removed. If your removal needs to match files of certain name patterns, you can generate that with find as well.
find(1)
and perhapsxargs(1)
– vonbrand Mar 05 '14 at 20:12