Find error: Arguments too long

Tuesday, July 17, 2007

I needed to remove some old files on my Solaris system and use the “find” command to accomplish this. Execute the command below and I get the “Arguments too long” error.

% find *.arc -mtime +0 -exec ls -l {} \;

I encountered this error many times before, but typically would be hasty and start manually selecting files to delete. Since I had a spare moment, I decided to research this to understand the problem.

Found information in this forum thread and this blog regarding the value used with “mtime”. It helped me understand when using the value +1, why I would see files 2 days old still existent in the file system.

1 means 24 hours old
-1 means less than 24 hours old
+0 means more than 24 hours old
+1 means more than 48 hours old

So I tried using the value +0 and that is when I encountered the “Arguments too long” error. Searching further, I found Solaris Error Messages with an entry about Arguments too long. The problem is typical when using the C shell. Resolution is to temporarily use the Bourne shell.

“This C shell error message indicates that there are too many arguments after a command. For example, this can happen by invoking rm * in a huge directory. The C shell cannot handle more than 1706 arguments.

Temporarily start a Bourne shell with sh and run the command again. The Bourne shell dynamically allocates command line arguments. Return to your original shell by typing exit.”

Just to confirm it was more than 1706 arguments, I started the Bourne shell and ran the find command piped to word count.

$ find *.arc -mtime 0 | wc -l
2093