Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
I'm unable to remove a directory like "New Folder" using all the above detailed commands. It's double worded. But I want to remove that directory. Any suggestions will be welcomed. T.Divakara, Bengaluru, India –  user307933 Jul 22 '14 at 7:33
Its the blank space in the file name, try using 'quotes' > rmdir 'New Folder' < then the folder disapers, or use escape characters for non-vissible characters. –  Ken Mollerup Feb 5 at 13:25

5 Answers 5

up vote 175 down vote accepted

Using this may helpful:

rm -rf lampp

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

share|improve this answer
In my humble opinion, it's a good practice never to add the "f" on first attempt. Its purpose is to ignore certain warning prompts that may be important, especially if you've accidentally done it on/from the wrong directory. In my opinion it's good to try without the "f" first, then only if you are encountering a lot of warning prompts and you're sure it's OK to ignore them all, Ctrl+C out of it and repeat the command with the "f". –  thomasrutter Aug 27 '13 at 2:52
rm -R lampp

However, you need to be careful with this command, as it makes it 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 I think it's best not to use it. 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. It can be helpful in the specific case when you know you're going to delete a bunch of files that you do not have "write" permission for, and yet you do have write permission on the containing directory. Without -f, you'll be prompted for each such file removed. But even in this situation there are better ways than just to add the -f immediately. Firstly, start it 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 Ctrl+C that and re-start it with the -f. Alternatively, run the command from a user (or the superuser using sudo) that does have write access to the file.

share|improve this answer
Note: lowercase -r can be used too and has the same effect here. I only tend to use uppercase -R because it's consistent with other commands I use such as grep and chmod, some of which only support the uppercase form. –  thomasrutter Sep 20 '13 at 4:04

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.

share|improve this answer

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.

$ sudo rm -R [Directory name]

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

share|improve this answer
"SUDO" is not a command - "sudo" is. Nevertheless, you do not use sudo to delete a non-empty directory, you use it to delete a file that is not owned by you. Doing this as a matter of course is dangerous and not very smart, as you should not be blindly deleting files you do not own. –  Marty Fried Sep 28 '14 at 23:53

By the way I personally wanted to delete a directory containing a write protected file/s (.git and sub directories) and eventually realised I also needed to become a super user in order to successfully delete these files. Here is what I did:

#became super user
sudo su -

#deleted contents of, and then the directory, harvey_snake/
rm -R harvey_snake/
share|improve this answer
I don't think you need sudo su here. Just prefix the rm command with sudo. For security it's a good practice (according to proponents of sudo) not to remain in a root prompt when not necessary. –  thomasrutter Feb 10 '14 at 0:09
Also, be very very very sure which directory you are in if you sudo rm -r. –  Tony Martin Oct 7 '14 at 23:18

protected by Community Dec 13 '14 at 17:16

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.