LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 05-05-2009, 04:18 PM   #1
Paul F.
LQ Newbie
 
Registered: May 2009
Posts: 2

Rep: Reputation: 0
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.
 
Old 05-05-2009, 04:21 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
"rm -rf directory" should do it.
 
Old 05-05-2009, 04:22 PM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Code:
rm -rf /path/to/directory
be careful: very dangerous command!!!
 
Old 05-05-2009, 06:51 PM   #4
mpiekarski
LQ Newbie
 
Registered: May 2009
Location: Newark, DE
Distribution: Gentoo,ubuntu,rhel
Posts: 25

Rep: Reputation: 16
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

Last edited by mpiekarski; 05-05-2009 at 08:24 PM.
 
Old 05-05-2009, 07:26 PM   #5
linus72
Guru
 
Registered: Jan 2009
Location: Gordonsville-AKA Mayberry-Virginia
Distribution: PocketWriter/MinimalX
Posts: 5,084

Rep: Reputation: 336Reputation: 336Reputation: 336Reputation: 336
Damn...I just use the trash can...what's the difference?

Is there a difference between that and the trash can and delete?
 
Old 05-05-2009, 07:32 PM   #6
jay73
Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
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!
 
Old 05-05-2009, 08:24 PM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,049

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
The trash can is just another folder. When you send something to the can you are moving it, not deleting it.
 
Old 05-05-2009, 08:35 PM   #8
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
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
 
Old 05-06-2009, 01:00 PM   #9
Paul F.
LQ Newbie
 
Registered: May 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks

Thank you all so much! Great info.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rm: cannot remove directory `ff': Directory not empty blancs Linux - General 17 08-29-2011 02:47 PM
Remove ALL files from specific Directory bianchi Programming 9 11-24-2005 12:27 AM
Automatically Copying files from the ftp directory into the html directory swatward Linux - General 3 04-17-2005 11:55 PM
Remove directory w/ files kfrancisco Linux - Software 13 10-02-2003 02:40 AM
Remove Files from the Directory .... shib_s Linux - Security 2 08-28-2001 06:53 PM


All times are GMT -5. The time now is 06:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration