It depends on your intention. Without the -f
flag, you'll end up with an error message and error return value if the file does not exist. Makefiles do not proceed after an error (unless you have configured them to do so). If the file may or may not exist and you want to delete it in all cases, -f
is the correct behavior. If the file should exist because of an earlier step in the toolchain and you want to delete it at this point (i.e. it is an error for it to not exist at this point), don't use -f
.
Now if you prefix a line with -
the command executes as normal but its errors are ignored and processing continues.
Most commands don't have a -f
flag in the first place, and that's why the -
prefix exists. But rm
does. In this case, you would use the -
prefix vs the -f
flag based on whether or not you want rm to complain that the file doesn't exist. It's probably a matter of style and preference at this point, but think about your intentions, the file you're deleting, etc. I personally prefer to have a makefile without any -
prefixes anywhere because I consider them more of a hack, and would rather use rm -f
instead, but after this explanation, it is your call.