LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to remove a directory with files in it. (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-remove-a-directory-with-files-in-it-723955/)

Paul F. 05-05-2009 03:18 PM

How to remove a directory with files in it.
 
Trying to delete a directory with files in and I don't want to be prompted for a yes answer.

jlliagre 05-05-2009 03:21 PM

"rm -rf directory" should do it.

colucix 05-05-2009 03:22 PM

Code:

rm -rf /path/to/directory
be careful: very dangerous command!!!

mpiekarski 05-05-2009 05:51 PM

A tip to keep in mind when deleting files would be the structure of directories and how they are referenced. For instance, if you are in "/foo" and inside that directory, there is another named "bar" you would run:

rm -Rf ./bar

From foo. The ./ just makes sure you are deleting from your working directory. If at any point, you need to know where you are, run `pwd` to print your working directory.

There are countless times that I ahve seen people mistakenly delete /etc because there was an etc dir inside their current working directory and they typed 'rm -Rf /etc' instead of 'rm -Rf ./etc' or 'rm -Rf etc'.

In short: Be careful. Its hard to un-do that type of mistake. Especially on ext3 :).


Michael Piekarski
Network Engineer
mpiekarski@hostmysite.com
www.hostmysite.com

linus72 05-05-2009 06:26 PM

Damn...I just use the trash can...what's the difference?

Is there a difference between that and the trash can and delete?

jay73 05-05-2009 06:32 PM

Yeah, if you dump it in the trash can, it can easily be recovered as long as you don't clean the trash. An rm -rf deletes things permanently.

For safety, you may want to use rm -rfi. Unlike plain -rf, it will prompt for confirmation. Always place the i option last!

i92guboj 05-05-2009 07:24 PM

The trash can is just another folder. When you send something to the can you are moving it, not deleting it.

chrism01 05-05-2009 07:35 PM

One safe way is :

Code:

cd <dir to delete>
rm -rf .    # deletes everything inside this dir
cd ..      # move back up one level
rmdir <dir to delete>    # dir is empty

you can create a fn for this an put it in your .bash_profile

Paul F. 05-06-2009 12:00 PM

Thanks
 
Thank you all so much! Great info.


All times are GMT -5. The time now is 12:31 AM.