How do I delete the following directory?
I typed:
rmdir lampp
This error comes up:
rmdir: failed to remove `lampp': Directory not empty
Is there a command to delete all the files in the directory and delete the directory folder?
How do I delete the following directory?
I typed:
rmdir lampp
This error comes up:
rmdir: failed to remove `lampp': Directory not empty
Is there a command to delete all the files in the directory and delete the directory folder?
Use the below command :
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 :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:Note: this is assuming you are already on the same level of the folder you want to delete in terminal, if not:
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 doneHowever, 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
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.
-r
= remove directories and their contents recursively-v
= explain what is being done-f
= ignore nonexistent files, never promptIf you are new in Linux, use the man pages of commands (
man rm
) for more option and more accuracy.I was having some trouble with that today, but I overcame it with sudo.
Caveat: Be very certain you want to delete the entire thing before using the command below.
I successfully did this today, and removed many non-empty directories that I confirmed I didn't want/need.
I'm using 14.04 LTS