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

Sat Oct 18 02:11:57 UTC 2008
Les Mikesell <lesmikesell at gmail.com>

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

These shouldn't make any difference.  The limit is on the size of the 
expanded shell command line.  The original example won't cause it.  The 
ones that expand a list with a * or the output of ls may.  The right 
solution is to let rm recurse with -r or to potentially long list to xargs.

-- 
   Les Mikesell
    lesmikesell at gmail.com