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.

I'm a new user and Im trying to remove a specific folder. I am using sudo rm /path/ but its not working. What is the correct command to use?

It is a file catolog I am attempting to remove but im geting a message that it is empty

share|improve this question
add comment

5 Answers 5

Be sure the folder is really empty (hidden files/folders might be in there). Look at the file contents again with

sudo ls -lha /path/

If you're absolutely certain that it doesn't contain anything you want to have (including subdirectories), delete it with

sudo rm -r -f /path/

The -r makes it delete the folder (and subfolders), even if it is non-empty, -f is for force (this might be unnecessary).

share|improve this answer
3  
note that -r means recursive (handles sub-directories indeed), but does not address the folder contents (thus -f is necessary). –  Eliran Malka Oct 17 '12 at 11:33
add comment

One thing to note is that the folder should be empty, then run the following command

rmdir directory_name

Another thing to note is that the command your are typing should not start with a slash(/) not unless the folder is under root.

The last option and you should be very careful while using this one, is to force removal of the directory in question including any other files/directories in it.

rm -rf directory_name

Cheers.

share|improve this answer
add comment

For a beginner I would not recommend getting into the habit of using rm -Rf or rm -r -f, this will bite you in the face sooner or later. Safer would be to create a systemwide alias. Open terminal (Ctrl+alt+T) then type:

alias rm='rm -i'

So you get prompted before wiping out all your vacation photo's by accident. The second recommendation I would like to add is to use rmdir , it will complain about non-empty directories and that is exactly what you want as a newbee.

But in the sense of the question, the answer is as given here already, use -f to erase a folder.

share|improve this answer
add comment

If you are sure that the directory exists, then:

(sudo) rm -rfv /path/

To delete the entire directory to your folders and files

share|improve this answer
1  
Don't use spaces in paths as you may end in trying to delete the whole filesystem recursively from / –  cauon Oct 17 '12 at 14:24
    
worked for me. I used for removing hadoop folder <code>sudo rm -rfv hadoop/ </code> –  sumitramteke Jan 10 at 14:09
add comment

If u want to delete all the files in directory and just want to keep the directory or some files use(with -i flag u can keep the file or delete it)

rm -i *

-i is for interactive and will prompt u each and every time there is a file to delete

If you need to delete sub directories along parent directory Use

rm -rf NameOfDirectory

share|improve this answer
add comment

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.