Use rm to delete a directory

To delete a file or directory in terminal (command line) use the rm command.

Here is how to delete an entire directory:
rm -dfr directory

-d, –directory
unlink FILE, even if it is a non-empty directory (super-user only)
-f, –force
ignore nonexistent files, never prompt
-i, –interactive
prompt before any removal
-r, -R, –recursive
remove the contents of directories recursively
-v, –verbose
explain what is being done
display this help and exit
output version information and exit

To remove a file whose name starts with a ‘-‘, for example `-foo’, use one of these commands:
rm -- -foo
rm ./-foo

To remove a file whose name contains a ‘*’ (or other special character), you will need to escape it. For example, I wanted to delete all directories starting with ‘~*w’:
rm -dfr ~\*w*

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Please enter 10 numbers for Captcha: * Time limit is exhausted. Please reload the CAPTCHA.