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 –  T. Divakara Jul 22 at 7:33

4 Answers 4

up vote 85 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
19  
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". –  neon_overload 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
1  
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. –  neon_overload 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

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
2  
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. –  neon_overload Feb 10 at 0:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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