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 -- Jussi Hirvi * Green Spot Topeliuksenkatu 15 C * 00250 Helsinki * Finland Tel. & fax +358 9 493 981 * Mobile +358 40 771 2098 (only sms) jussi.hirvi at greenspot.fi * http://www.greenspot.fi
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. > > - Jussitry something like: for i in /var/amavis/tmp/* do rm -rf $i done Laurent
piping ls to xargs should do the trick. man xargs for details. Jussi Hirvi wrote:> 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 > > -- > Jussi Hirvi * Green Spot > Topeliuksenkatu 15 C * 00250 Helsinki * Finland > Tel. & fax +358 9 493 981 * Mobile +358 40 771 2098 (only sms) > jussi.hirvi at greenspot.fi * http://www.greenspot.fi > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos > >
On 2008-10-17 11:30, Jussi Hirvi wrote:> 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.I believe you gave a bad example! In the command rm -rf /var/amavis/tmp the argument list is not at all "very long". However if you did: rm -rf /var/amavis/tmp/* then the argument list could be very long depending on the number of entries there are in the subdirectory. You have to understand that globbing is done by the shell before starting the command. The result of the glob is what makes the "argument list too long"; it needs to fit in a buffer (about 128K bytes on a default CentOS install I believe). If you want the to remove the subfolders and files, and not the parent folder itself, on CentOS 5, try this: cd /var/amavis/tmp rm -rf * Doing a "cd" makes the resulting of the globbing much shorter, maybe fixing your problem already. If still too long, then try: find . -maxdepth 1 -exec rm -rf {} + You could even try things like: cd /var/amavis/tmp rm a* rm *0 ...etc... Any glob pattern resulting in less arguments for the command to avoid overflowing the 128K buffer is good. On CentOS 4, the '+' variant of -exec does not exist, and you need to do: find . -maxdepth 1 -exec rm -rf {} \; # one rm command for each arg or find . -maxdepth 1 -print0 | xargs -0 rm -rf # less resource intensive -- Paul Bijnens, xplanation Technology Services Tel +32 16 397.511 Technologielaan 21 bus 2, B-3001 Leuven, BELGIUM Fax +32 16 397.512 http://www.xplanation.com/ email: Paul.Bijnens at xplanation.com *********************************************************************** * I think I've got the hang of it now: exit, ^D, ^C, ^\, ^Z, ^Q, ^^, * * F6, quit, ZZ, :q, :q!, M-Z, ^X^C, logoff, logout, close, bye, /bye, * * stop, end, F3, ~., ^]c, +++ ATH, disconnect, halt, abort, hangup, * * PF4, F20, ^X^X, :D::D, KJOB, F14-f-e, F8-e, kill -1 $$, shutdown, * * init 0, kill -9 1, Alt-F4, Ctrl-Alt-Del, AltGr-NumLock, Stop-A, ... * * ... "Are you sure?" ... YES ... Phew ... I'm out * ***********************************************************************
on 10-17-2008 2:30 AM Jussi Hirvi spake the following:> 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. >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. And yes, Fedora would have the same limitation. -- MailScanner is like deodorant... You hope everybody uses it, and you notice quickly if they don't!!!! -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 250 bytes Desc: OpenPGP digital signature URL: <http://lists.centos.org/pipermail/centos/attachments/20081017/3855b016/attachment-0003.sig>
> > 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
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. >
> and get only "argument list too long" as feedback. > > Is there a way to go round this problem? > > I have CentOS 5.2. >I'm not going to repeat some of the good advice given to you by others as to how to avoid this error, but will instead tell you this is related to the ARG_MAX variable. The standard limit for linux kernels up to 2.6.22.xxxx is 131072 chars. This can be confirmed by typing: getconf ARG_MAX Until CentOS uses the 2.6.23 kernel (or later) in which the length of arguments is constrained only by system resources, you'll need to use scripting techniques which are more parsimonious.