How do I make rm not give an error if a file doesn't exist?

Solution 1:

The -f option is definitely what you want to be using.

The confirmation about file permissions it refers to is this:

$ touch myfile    
$ chmod 400 myfile
$ rm myfile       
rm: remove write-protected regular empty file `myfile'?

So rm will warn you if you try to delete a file you don't have write permissions on. This is allowed if you have write permissions on the directory but is a little weird, which is why rm normally warns you about it.

Solution 2:

Another solution is this one: https://stackoverflow.com/questions/11231937/bash-ignoring-error-for-a-particular-command

Just add an OR-statement after your command:

rm -rf my/dir || true

This way, when statement #1 fails (throws error), run statement #2, which is simply true.

Solution 3:

I'm way late to the party, but I use this all the time. In a makefile, add - to the beginning of a line to ignore the return value of that line. Like so:

-rm lexer.ml interpparse.ml interpparse.mli