-bash: /bin/rm: Argument list too long

No, its not fedora-devel-list, its what I got this morning after our asterisk server ran out of space and I tried to trash the entire recordings directory. rm fail?

Solved with:

ls | xargs rm

by the way as apparently unix rm has a 128k buffer. Or something.

Advertisements

8 thoughts on “-bash: /bin/rm: Argument list too long

  1. IIRC, this has been discussed in Linux Kernel Mailing List quite some time back, and Alan Cox mentioned the exact solution – to use xargs.

  2. You must be running an old kernel, I think it is solved in recent ones and argument lists can be virtually unlimited.

  3. it’s not an rm limit. it’s an execve system call limit (fixed size buffer for the size of command line arguments). one of my favorite linux interview questions is “how big is the command line?” :-). do “man xargs” to find out the canonical way to work around the problem.

  4. The shell is probably to blame. I often use:

    find . -type f -exec rm {} \;

    In large directories like that (limit to one directory level if you don’t want recursion).

  5. This is a bash limitation, not an rm limitation. I think bash has a limitation of 32k worth of arguments. You can do rm “/tmp/*” instead, and this will avoid the bash expansion.

  6. Hey, I should have asked this question before running the above. FWIW, there were 12’730 files in the directory. Would have been interesting to test a few of the above about, or maybe try it in csh, zsh etc?

  7. I used put the xargs vs rm * example in my shell scripting class, but with new kernels this limitation (related to the kernel and exec’s max number of arguments) doesn’t exist anymore.

    I wonder if the kernel developers know they ruined my class 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s