Alexander Mills
Alexander Mills

Reputation: 99960

rm -rf always exiting with 0, even if dir does not exist

I have this command:

rm -rf ~/.quicklock; echo $?
rm -rf ~/.quicklock; echo $?
rm -rf ~/.quicklock; echo $?
rm -rf ~/.quicklock; echo $?

always exits with 0, even if directory does not exist. I am on a Mac. I thought it would exit with 1 if the directory does not exist?

Upvotes: 5

Views: 1988

Answers (1)

John Zwinck
John Zwinck

Reputation: 249093

rm -f does not consider it to be an error if the file does not exist (nor if the directory does not exist, in the case of rm -rf).

man rm says about -f or --force:

ignore nonexistent files and arguments

Upvotes: 7

Related Questions