Find error: Arguments too long

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


One Response to Find error: Arguments too long

  1. Roberto says:

    The error “Arguments too long” is inevitable running for example:
    ls *.arc
    but the “find” command does not have this problem.
    First, your unix command is wrong: the first argument must be one (or more) directory name.
    Perhaps you wanted to run:
    find . -name \*.arc -mtime +0 -exec ls -l {} \;

    As you see I have protected the argument to be passed to the find command using the \ character, in fact, if for example there are in your current directory the files:
    a.arc b.arc c.arc …
    the command is actually executed, is (shell global expansion):
    find a.arc b.arc c.arc … -mtime +0 -exec ls -l {} \;

    If the number of files in the current directory is very large, the length of the command is excessive and this causes the error “Arguments too long”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: