Removing an entire directory/folder (that still contains files) in Linux

This one’s easy, but I’ve just been asked by someone new to Linux so here it is:

$ rm -r <path to directory>

So for example if you want to delete a folder called temporary from your home directory:

$ rm -r ~/temporary

The -r switch stands for recursive, so you’re not actually deleting the directory with the files within it, you’re deleting each file within the directory first, then removing the directory afterwards.

Simples.

Leave a Reply

Your email address will not be published. Required fields are marked *