You can use two commands for removing directories. The first one,
rmdir, is the safer of the two, because it refuses to remove directories that still have files or directories inside them. Use it with the name of the directory you want to remove, for example
books, like this:
If you want to prune a whole branch of your directory tree, you can use the
rm command to remove a directory and delete anything inside it and its subdirectories. Used with the recursive option (
-R), it works its way down the directory tree, and with the force option (
-f), it deletes any files in its way. It’s a rampaging beast of a command. Here’s an example:
rm –Rf books
It acts silently and swiftly, deleting the books directory and anything in it.
You can add the interactive option to cut the risk, which prompts you for confirmation of each deletion, as you can see in this example where we’ve left a file in the folder work/writing/books:
pi@raspberrypi ~ $
rm –Rfi work
rm: descend into directory ‘work’?
rm: descend into directory ‘work/writing’?
rm: descend into directory ‘work/writing/books’?
rm: remove regular file ‘work/writing/books/rapidplan.txt’?
rm: remove directory ‘work/writing/books’?
rm: remove directory ‘work/writing’?
rm: remove directory ‘work’?