347
33
I'm writing a makefile that will clean up some useless files at the end of the compilation. If a target has already been made, it will of course skip that target and the useless file may not be there. So if I do this:
rm lexer.ml interpparse.ml interpparse.mli
I may get errors because one of the files doesn't exist. Is there any way to tell rm
to ignore these files?
In reading the man page, I see the following option:
-f Attempt to remove the files without prompting for confirma-
tion, regardless of the file's permissions. If the file does
not exist, do not display a diagnostic message or modify the
exit status to reflect an error. The -f option overrides any
previous -i options.
That sounds like almost what I want, but I'm not really sure about the permissions part. Is there a way to do this?
just for completeness: there is
– lesmana – 2019-04-08T07:11:34.133rm --interactive=never
which acts likerm -f
except it does return an error exit status. see here for more details: https://unix.stackexchange.com/questions/72864/how-to-avoid-the-need-to-issue-y-several-times-when-removing-protected-file/438486#438486Since you mentioned Makefile in the question, I think @robertLi's answer suits the best. Prepending with '-' is a make way of doing this; others dealing with Makefiles will likely recognise it. – akauppi – 2019-11-27T13:34:36.020
If the permissions won't allow it, rm will with the
-f
option still try to delete it. It will fail. It won't tell you it failed. Useful if the filename is a variable or a glob. – LawrenceC – 2012-06-13T01:24:56.070Did you try some
rm
in a sandbox? It looks like-f
does exactly what you want, regardless of the globbing. – JMD – 2009-11-27T17:02:06.193