What to do if you get a bash: /usr/bin/rm: Argument list too long error.

If you have directories which you contain millions of files you might get in trouble when you want to apply an operation on a bunch of files. For example rm *.jpg will not work in that case due to memory limits.

An easy way is you to use find for the job you want to do:

If you want to move all files in a directory which have the extension jpg.gif to gif only  you can use the following command:

> find -name “*.gif.jpg”  -exec mv ‘{}’ jpg \;

Another useful application is to easily remove all files with the extension .jpg

This can be done with the following command:

> find -name “*.json”  -exec rm ‘{}’ \;

In principle you can apply find to any other job you want to perform.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>