Today I’ve decided to cleanup the hard drive on my Linux workstation and “surprisingly” found 8G of temporary files in one folder.

After quick review I’ve decided to erase them with rm command.

For my surprise when running the command:

/bin/rm *.tmp

I got following error message:

bash: /bin/rm: Argument list too long

Conclusion:Even rm command has his limits!

Solution: Get Plumber(Joking)
Actually only Pipe is needed.
By typing following command:

find . -name "*.tmp"|less

You will see list of the files and by replacing less with xargs /bin/rm those files will be erased. Can you skip previous step? Yes you can and it is not required, but you risk to erase a lot of data if you have syntax error.

find . -name "*.tmp"| xargs /bin/rm.

Depending on the number of files and your system speed after a while all files will be erased.

Done .

Comments

3 Responses to “bash: /bin/rm: Argument list too long – How to fix it”

  1. nap on November 5th, 2009 9:26 am

    thank you very much, helpul command, helps me a lot!

  2. Swynndla on December 15th, 2009 10:41 pm

    If some of your filenames have spaces in them then the above wont work, so do this instead:
    find -name “*.tmp” -print0 | xargs -0 /bin/rm

  3. Gopikrishna on February 18th, 2010 5:42 am

    Thanks a lot. Helpful command.

Leave a Reply