6 Answers
Reset to default
133
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/
-r
is for recursive, so it will delete the folder and subfolders, even if it is non-empty-f
is for force (this might be unnecessary).
edited Dec 15, 2016 at 3:08
wjandrea
14.5k44 gold badges5050 silver badges102102 bronze badges
answered Oct 16, 2012 at 16:33
phoibosphoibos
22.1k55 gold badges4949 silver badges4747 bronze badges
3
-
2
@EliranMalka The
-f
flag is not necessary forrm
to delete items directly contained in the specified folder, which I presume is what you mean by "address the folder contents." Instead-f
stands for force, causingrm
never to prompt for confirmation even if the file to be deleted has no write permission (rm: remove write-protected regular file ‘foo’?
), and also causingrm
not to warn on an attempt to delete a file that already does not exist. It's best only to use the-f
flag when it's really needed.rm -r
without-f
absolutely does "address the folder contents."–Eliah Kagan
Commented Apr 16, 2015 at 4:35
-
wat? i honestly don't know what i was saying... forget it :)
–Eliran Malka
Commented Apr 16, 2015 at 18:12
-
1
i had to remove the leading / to get it to work for me. ie:
sudo rm -r -f path/
–simsketch
Commented Mar 2, 2016 at 20:19
Add a comment |
28
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.
answered Oct 17, 2012 at 13:52
tmwaniktmwanik
37522 silver badges77 bronze badges
Add a comment |
12
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.
edited Feb 25, 2016 at 11:38
andrew.46♦
39.1k2828 gold badges162162 silver badges239239 bronze badges
answered Oct 17, 2012 at 11:58
Glenn PlasGlenn Plas
24911 silver badge66 bronze badges
Add a comment |
5
If you are sure that the directory exists, then:
(sudo) rm -rfv /path/
To delete the entire directory to your folders and files
edited Sep 9, 2017 at 8:47
muru
206k5656 gold badges512512 silver badges766766 bronze badges
answered Oct 17, 2012 at 14:19
KakashiSanKakashiSan
17133 bronze badges
2
-
1
Don't use spaces in paths as you may end in trying to delete the whole filesystem recursively from
/
–cauon
Commented Oct 17, 2012 at 14:24
-
worked for me. I used for removing hadoop folder <code>sudo rm -rfv hadoop/ </code>
–Sumit Ramteke
Commented Jan 10, 2014 at 14:09
Add a comment |
2
If you want to delete all the files in directory and just want to keep the directory or some files use (with the -i
flag you can keep the file or delete it).
rm -i *
-i
is for interactive and will prompt you each and every time there is a file to delete.
If you need to delete sub directories along parent directory, use:
rm -rf NameOfDirectory
edited Aug 12, 2017 at 20:17
Eliah Kagan
119k5858 gold badges324324 silver badges504504 bronze badges
answered Oct 17, 2012 at 14:07
OmiPenguinOmiPenguin
2,33299 gold badges3535 silver badges5252 bronze badges
Add a comment |
If you would like to delete the contents and overwite the data on your drive try using shread. It only removes files so to remove everything in the directory use;
sudo find <directory_name> -depth -type f -exec shred -vz -n 5 --remove=wipe {} +
then remove the empty directory
rm -rf <directory_name>
answered Sep 25, 2020 at 19:24
chaggychaggy
13133 bronze badges
Add a comment |
You must log in to answer this question.
Start asking to get answers
Find the answer to your question by asking.
Ask question
Explore related questions
- delete
- command-line
- rm
See similar questions with these tags.