Review your favorite Linux distribution.
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, 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
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,716

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

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
rm -rf /path/to/directory
be careful: very dangerous command!!!
Old 05-05-2009, 06: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 08:24 PM.
Old 05-05-2009, 07:26 PM   #5
LQ Guru
Registered: Jan 2009
Location: Gordonsville-AKA Mayberry-Virginia
Distribution: PocketWriter/MinimalX
Posts: 5,087

Rep: Reputation: 338Reputation: 338Reputation: 338Reputation: 338
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
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, 08:24 PM   #7
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,074

Rep: Reputation: 386Reputation: 386Reputation: 386Reputation: 386
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
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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, 01: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 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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:15 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