Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 05-05-2009, 03: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, 03:21 PM   #2
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,634

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

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
rm -rf /path/to/directory
be careful: very dangerous command!!!
Old 05-05-2009, 05:51 PM   #4
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

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

Rep: Reputation: 337Reputation: 337Reputation: 337Reputation: 337
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, 06:32 PM   #6
LQ 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, 07:24 PM   #7
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,060

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
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, 07:35 PM   #8
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,198

Rep: Reputation: 2310Reputation: 2310Reputation: 2310Reputation: 2310Reputation: 2310Reputation: 2310Reputation: 2310Reputation: 2310Reputation: 2310Reputation: 2310Reputation: 2310
One safe way is :

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, 12:00 PM   #9
Paul F.
LQ Newbie
Registered: May 2009
Posts: 2

Original Poster
Rep: Reputation: 0

Thank you all so much! Great info.


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 01:47 PM
Remove ALL files from specific Directory bianchi Programming 9 11-23-2005 11:27 PM
Automatically Copying files from the ftp directory into the html directory swatward Linux - General 3 04-17-2005 10:55 PM
Remove directory w/ files kfrancisco Linux - Software 13 10-02-2003 01:40 AM
Remove Files from the Directory .... shib_s Linux - Security 2 08-28-2001 05:53 PM

All times are GMT -5. The time now is 04:50 PM.

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