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

1

5

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?

Burgwell answered 2/3, 2018 at 5:32 Comment(0)
L
7

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

Lowder answered 2/3, 2018 at 5:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.