Artusi Project: rm -r vs rm -rf

https://www.codecademy.com/courses/learn-the-command-line/projects/artusi

Question 25 wants us to remove the “dough” directory. Can someone explain why ‘rm -rf dough’ is the answer, instead of ‘rm -r dough’? I used ‘rm -r dough’ and it worked but this f is throwing me off. Thank you!

I’ve not seen this lesson before but the -f flag is to force removal which ignores nonexistent files/directories (no warnings), ignores write protection (on files but not directories) and removes the warning prompt. If you’re confident about the contents you’re trying to delete then it can make removal much less hassle.

3 Likes

Hi @blog3542724870: -r does the specified action recursively. This means if it is specified on a folder, it will go through all the folders and try to delete them, which may not be always successful in deleting all the files. If you use -r with -f, basically you are going through all folders and forcefully removing them permanently.

Hope this helps!

3 Likes