Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rm -rf versus -rm -rf

Tags:

makefile

In a Makefile, I read:

-rm -rf (instead of rm -rf). What does the first "-" mean at the beginning of the line in a Makefile ?

like image 437
user255607 Avatar asked Jun 07 '10 12:06

user255607


1 Answers

It means that make itself will ignore any error code from rm.

In a makefile, if any command fails then the make process itself discontinues processing. By prefixing your commands with -, you notify make that it should continue processing rules no matter the outcome of the command.

For example, the makefile rule:

clean:     rm *.o     rm *.a 

will not remove the *.a files if rm *.o returns an error (if, for example, there aren't any *.o files to delete). Using:

clean:     -rm *.o     -rm *.a 

will fix that particular problem.


Aside: Although it's probably not needed in your specific case (since the -f flag appears to prevent rm from returning an error when the file does not exist), it's still good practice to mark the line explicitly in the makefile - rm may return other errors under certain circumstances and it makes your intent clear.

like image 131
paxdiablo Avatar answered Oct 04 '22 21:10

paxdiablo