Grokbase
Topics Posts Groups | in
x
[ help ]

Re: ls and rm: "argument list too long"

View PostFlat  Thread  Threaded | < Prev - Next >
mouss Re: [CentOS] ls and rm: "argument list too long"
| +1 vote
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
Jussi Hirvi a écrit :
> 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.


I doubt this. "argument list too long" is a shell error, and in your
command the shell doesn't see many arguments.

I guess you want to remove amavisd-new temp files and you did
rm -rf /var/amavis/tmp/*

In this case, the shell would need to replace that with
rm -rf /var/amavis/tmp/foo1 /var/amavis/tmp/foo2 ....
in which case, it needs to store these arguments in memory. so it would
need to allocate enough memory for all these before passing them to the
rm command. so a limitation is necessary to avoid consuming all your
memory. This limitation exists on all unix systems that I have seen.


>
> Is there a way to go round this problem?
>

Since amavisd-new temp files have no spaces in them, you can do
for f in in /var/amavis/tmp/*; do rm -rf $f; done
(Here, the shell does the loop, so doesn't need to expand the list at
once).

alternatively, you could remove the whole directory (rm -rf
/var/amavis/tmp) and recreate it (don't forget to reset the owner and
permisions).




> I have CentOS 5.2.
>
_______________________________________________
CentOS mailing list
[email protected: C...@centos.org]
http://lists.centos.org/mailman/listinfo/centos

Thread : ls and rm: "argument list too long"
1)
Jussi Hirvi Since when is there a limit in how long directory listings CentOS can show say, for example rm -rf...
2)
Laurent Wandrebeck 2008/10/17 Jussi Hirvi <greenspot@greenspot.fi>: try something like: for i in /var/amavis/tmp/* do...
3)
thad Satchel Paige - "Don't look back. Something might be gaining on you." it should be: for i in `ls...
4)
Les Mikesell These shouldn't make any difference. The limit is on the size of the expanded shell command line....
5)
Robert Nichols Really? $ M=0; N=0; for W in `find /usr -xdev 2>/dev/null`; do M=$(($M+1)); N=$(($N+${#W}+1));...
6)
Les Mikesell Is that peculiar to bash? I thought the `command` construct was expanded by shells into the command...
7)
William L. Maltby IIRC, none of the above make a "command line". Everything but the `find /usr -xdev 2>/dev/null` is...
8)
William L. Maltby Uh, +1 for the \0 that terminates each parameter? Need more java here. > <snip>
9)
William L. Maltby Ok. 3rd cup of coffee has made its way into various of my systems. A minor correction (but...
10)
Robert Nichols I can't answer for how any particular shell allocates its internal memory, but yes, the shell does...
11)
Kevin Krieser Taking into account the valid objections others have mentioned, such as problems of embedded...
12)
Lawrence Guirre piping ls to xargs should do the trick. man xargs for details. ...
13)
Jussi Hirvi Lawrence Guirre (lawrence.guirre@gmail.com) kirjoitteli (17.10.2008 12:55): Ok, thanks for ideas,...
14)
Geoff Galitz Are you sure you are comparing apples to apples? There is nothing particularly Centos specific...
15)
Ralph Angenendt Than he doesn't have as many files in the directory as you have: #define ARG_MAX 131072 /* # bytes...
16)
Jeremy Sanders This limitation has been removed from more recent kernels....
17)
Les Mikesell It is probably still best not to expect the ability to build infinitely long command lines. You can...
18)
Mark Hull-Richter This is usually not a kernel issue at all - it is a shell issue. The limitation is the len
19)
Paul Bijnens I believe you gave a bad example! In the command rm -rf /var/amavis/tmp the argument list is not at...
20)
Jussi Hirvi Yes, you are right - my example was misleading. Thanks for the very easy solution (cd into...
21)
Scott Silva This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --==============!31096155=Content-Type:...
22)
John Kordash I don't believe this is correct. The command "rm -rf /path/to/dir" doesn't expand on the shell the...
23)
mouss Jussi Hirvi a écrit : I doubt this. "argument list too long" is a shell error, and in your command...
24)
Kevin Krieser Possible to learn something new every day. I would have expected the for loop to fail too, thinking...
25)
DamianS I'm not going to repeat some of the good advice given to you by others as to how to avoid this...
spacer
View PostFlat  Thread  Threaded | < Prev - Next >