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

Sat Oct 18 13:18:19 UTC 2008
Kevin Krieser <k_krieser at sbcglobal.net>

On Oct 17, 2008, at 7:58 PM, thad wrote:

> Satchel Paige  - "Don't look back. Something might be gaining on you."
>
>
> On Fri, Oct 17, 2008 at 4:36 AM, Laurent Wandrebeck
> <l.wandrebeck at gmail.com> wrote:
>> 2008/10/17 Jussi Hirvi <greenspot at greenspot.fi>:
>>> Since when is there a limit in how long directory listings CentOS  
>>> can show
>>> (ls), or how large directories can be removed (rm). It is really  
>>> annoying to
>>> say, for example
>>>
>>>   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.
>>>
>>> - Jussi
>> try something like:
>> for i in /var/amavis/tmp/*
>> do
>>   rm -rf $i
>> done
>
> it should be:
>
> for i in `ls  /var/amavis/tmp`
> do
> rm $i
> done
> _______________________________________________


Taking into account the valid objections others have mentioned, such  
as problems of embedded whitespace in names, rm -rf $i and rm $i above  
are not the same.
Even if there are no directories under the /var/amavis/tmp/, depending  
on aliases, etc, rm $i may prompt you for confirmation.  the other  
will go ahead and do the remove if you have permission to do it (or at  
least the -f).

The -r for files is unnecessary, and offends me when I see people do  
it, but doesn't really cause any harm :)

I personally either rm -rf directory, and recreate the directory if  
necessary, or do a find /var/amavis/tmp -type f ... because of  
experience through the years with too long of command lines.  Unixes  
in the past had even smaller limits.  xargs most frequently, and if  
things fail, I may just do -exec rm -f {} \; on the find.