[CentOS] Re: ls and rm: "argument list too long"

Fri Oct 17 20:38:38 UTC 2008
John Kordash <kordash at supplyscape.com>

> >     rm -rf /var/amavis/tmp
> >
> > and get only "argument list too long" as feedback.
> >
> > Is there a way to go round this problem?
> >
> > I have CentOS 5.2.
> >
> It isn't a problem with the commands, it is a problem of how
> long a command
> line can be when piped to a command.
>
> rm -rf /var/amavis/tmp is effectively the same as rm -rf
> /var/amavis/tmp/1
> /var/amavis/tmp/2 /var/amavis/tmp/3 /var/amavis/tmp/4
> /var/amavis/tmp/5 ...
> etc. The number of diles and directories in that folder is
> the limiting factor.

I don't believe this is correct.  The command "rm -rf /path/to/dir" doesn't expand on the shell the same way "rm -rf /path/to/dir/*" would.

Unless I'm misunderstanding your comment, "rm -rf /path/to/dir" will remove everything as intended without blowing out the argument list.

Dealing with file removal and getting 'argument list too long' is a FAQish question, and there is more than one way to get around the issue.  Common workarounds include find piped to xargs rm, the above mentioned recursive directory nuke, one line perl scripts, etc.

-John