rm (remove)

Article by:
Date Published:
Last Modified:


rm is a UNIX command for deleting files and directories on the file system.

Dealing With Special Characters

See Bash - Dealing With Special Characters for more information.

Argument list too long

If you provide too many files to delete to a single invocation of the rm (e.g. you use the wildcard expression rm *.jpg in bash to match a large number of images), you may get the following error:

unable to execute /bin/rm: Argument list too long

This is because bash expands the command to rm file1.jpg file2.jpg ... and rm only supports a limited number of arguments.

A workaround is to use find instead:

$ find . -maxdepth 1 -name "*.jpg" -delete

-maxdepth 1 is required to prevent find from recursively going into subdirectories and deleting files from in there.


Instead of using the delete option, you could use find in combination with piping and xargs. However, this is likely to be less performant than -delete as you are passing data between multiple processes. It is also more to type!


Geoffrey Hunter

Dude making stuff.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License .

Related Content


comments powered by Disqus