Jul
5
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
or
find . -name "*.tmp" -print0 | xargs -0 /bin/rm
or
find . -name "*.tmp" -delete
if you have space in file name.
Depending on the number of files and your system speed after a while all files will be erased.
Done .
UPDATE0:
(Siby) If you get Argument list too long on all commands – probably you should look at you .bashrc file.
More specifically at PATH. Did you modify it to look at subfolders?
UPDATE1:
I’m adding information from the comments to main post. Thanks to “Scriptster” and “Swynndla”
UPDATE2:
Another solution is to use -delete option applied to find command.
Comments
14 Responses to “bash: /bin/rm: Argument list too long – How to fix it (Update 2 )”
Leave a Reply
You must be logged in to post a comment.
thank you very much, helpul command, helps me a lot!
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
Thanks a lot. Helpful command.
It works. Thanks
find . -name ‘sess_0*’ | xargs rm
For a less discriminate deletion of EVERYTHING in the directory one can just use ‘ls’ command with -rf keys to delete any directory that may come up in the listing:
ls | xargs rm -rf
BE VERY CAREFUL USING IT!!! Run in a wrong location this will destroy your system!
Also, in your post, it’s best to remove the period (.) from the end – it should not be in the executed command:
find . -name “*.tmp”| xargs /bin/rm (no period at the end)
Cheers!
Thanks a lot. This helped me…..
I’ve just lost all of my files and folders on my server in just 2 seconds while trying to find the right use for my situation!
I think you should seriously warn visitors before using this command. They might not lose a lot of data. They might lose everything!!!
Thanks anyway!
Actually the warning is there as you can see first I use less to check the files that are in the list…
Thank a ton… This helps big time… 🙂
Thanks a lot , it worked for me !!
Hi all..
I am getting an error message “Argument too long” in the fedora 17 OS.
ls, mv, rm -f, rm -rf, su etc nothing working at all.
These are the details of output which i am getting:
[cpl@cpl ~]$ ls
bash: /usr/bin/ls: Argument list too long
[cpl@cpl ~]$ pwd
/home/cpl
[cpl@cpl ~]$ su
bash: /usr/bin/su: Argument list too long
[cpl@cpl ~]$ ls
bash: /usr/bin/ls: Argument list too long
[cpl@cpl ~]$ mkdir 1
bash: /usr/bin/mkdir: Argument list too long
[cpl@cpl ~]$ pwd
/home/cpl
Pls do the needful
Thanks in advance..!
Best
You should check your .bash file
You can try using the Long Path Tool. It can fix filename too long, path too long or even access denied issues.