Mandalika's scratchpad [ Work blog @Oracle | My Music Compositions ]

Friday, May 13, 2005

Csh: Arguments too long error

Symptom:
C-shell fails to execute commands with arguments using wildcard characters.
eg.,% \rm -rf *Arguments too long% ls -l | wc    8462   76151  550202

The reason for this failure is that the wildcard has exceeded C-shell limitation(s). The command in this example is evaluating to a very long string. It overwhelmed the csh limit of 1706, for the maximum number of arguments to a command for which filename expansion applies.

Workarounds:
1. Use multiple commands Or
2. Use xargs utility
% \rm -rf *Arguments too long% ls | xargs rm -rf% ls%
Or
% \rm -rf *Arguments too long% find . -name "*" | xargs rm -rf% ls%

From Jerry Peek's Handle Too-Long Command Lines with xargs:
• xargs reads a group of arguments from its standard input, then runs a UNIX command with that group of arguments. It keeps reading arguments and running the command until it runs out of arguments.
• The shell's backquotes do the same kind of thing, but they give all the arguments to the command at once. That's the main reason for the Arguments too long error, when the shell reaches its limitations

Reference:
Man page of csh

Thanks to Chris Quenelle for suggesting the xargs workaround

You can use the xargs command to handle long argument lists.

/bin/ls | xargs rm -rf

I didn't try that, but that's the gist of it.