How to remove a directory recursively?

  • Thread starter Thread starter carbon333
  • Start date Start date


You do need to make sure that you have write permissions to remove the directory, sub directories. If you run into permission problems, you can do

chmod -R +w directory-name

and then

rm -rf directory-name
 
Be aware that 'rm -rf directory-name' is powerful. As in, dangerous. Use with caution.

-Bob "Know from experience"
 
The meanest prank to pull on a Linux beginner is getting them into root and telling them to run "rm -rf /".

Also, this works too:
find . -exec "rm -rf {}"\;

I believe that's the command anywho. Been a while since I used find's exec switch.
 
I have a rule that I always type in the full path to whatever i'm using 'rm -rf' on.. I'll also preach it to anyone i'm teaching..

IE: if you're root and you are in /home/rob/Downloads/ and want to remove the /home/rob/Downloads/etc/ directory, type in the full path to it.. you don't want to accidently wipe out /etc/ :)

(also, don't run around as root unless you have to!)
 



Top