How to delete a non-empty directory in Terminal?

Use the below command :

rm -rf lampp

It deletes all files and folders contained in the lampp directory.

In case user doesn't have the permission to delete the folder:

Add sudo at the beginning of the command :

sudo rm -rf folderName

Otherwise, without sudo you will be returned permission denied. And it's a good practice to try not to use -f while deleting a directory:

sudo rm -r folderName

Note: this is assuming you are already on the same level of the folder you want to delete in terminal, if not:

sudo rm -r /path/to/folderName

FYI: you can use letters -f, -r, -v:

  • -f = to ignore non-existent files, never prompt
  • -r = to remove directories and their contents recursively
  • -v = to explain what is being done

rm -R lampp

However, you need to be careful with a recursive command like this, as it's easy to accidentally delete a lot more than you intended.

It is a good idea to always double-check which directory you're in, and whether you typed the command correctly, before pressing Enter.

Safer version

rm -R -i lampp

Adding -i makes it a little safer, because it will prompt you on every deletion. However, if you are deleting many files this is not going to be very practical. Still, you can try this first.

Note about -f option:

Many people suggest using -f (combining it into -Rf or -rf), claiming that it gets rid of annoying prompts. However, in normal cases you don't need it, and using it suppresses some problems that you probably do want to know about. When you use it, you won't be warned if your arguments supply a non-existing directory or file(s): rm will just silently fail to delete anything. As a general rule, try first without the -f: if there are problems with your arguments, then you'll notice. If you start getting too many prompts about files without write access, then you can try it with -f. Alternatively, run the command from a user (or the superuser using sudo) that has full permissions to the files and directories you're deleting to prevent these prompts in the first place.


There are lots of ways to delete a directory through CLI mode. It depends on which way you are comfortable with.

rm -rvf /path/to/directory  
  • -r = remove directories and their contents recursively
  • -v = explain what is being done
  • -f = ignore nonexistent files, never prompt

If you are new in Linux, use the man pages of commands (man rm) for more option and more accuracy.

Tags:

Command Line