Classic tip · Classic
/bash/rm: argument list too long
I can't tell you how many times I've seen this complaint from the bash shell when trying to remove a bunch of files. In this case, I was trying to clear a directory where log rotating had run amuck a…
I can't tell you how many times I've seen this complaint from the bash shell when trying to remove a bunch of files. In this case, I was trying to clear a directory where log rotating had run amuck and there was a 10 second lag in typing ls ∗.gz and seeing any output.... So, I did rm ∗.gz and got bash/rm: argument list too long in response.... So, then I though I could "surgically remove" some files and shrink the list a bit... rm ∗5∗3∗2∗.gz -f; rm ∗5∗3∗1∗.gz -f, etc, etc, etc after about 4 of these it became obvious I'd need to find another way because even some of THOSE gave the "argument list too long" error. (What's more, it looked like I was going to have to deal with files matching ∗∗∗∗gz - yuck...)
I found an interesting solution on a redhat mailing list... it uses find and xargs....
find . -name '∗.gz' | xargs rm
Make sure to put the single quotes around the ∗.gz.... but that has saved me about thirty minutes of trying to delete smaller blocks of files manually.