LinuxQuestions.org
Review your favorite Linux distribution.
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 08-06-2005, 10:52 AM   #1
tyyp88
LQ Newbie
 
Registered: Aug 2005
Location: Estonia
Distribution: CentOS 3.5 x86_64
Posts: 11

Rep: Reputation: 0
Question HowTo Delete Directory in CentOS UNIX?


What is the command that i need to use, if i want to delete file or dir's?
I'm using Cent OS 3.5 inUNIX The Red Hat Enterprise Server

Last edited by tyyp88; 08-06-2005 at 11:49 AM.
 
Old 08-06-2005, 11:00 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You should be able to use standard Linux commands: rm and rmdir.

To delete a file: rm filename
To delete a directory: rmdir directory (directory must be empty though)

See the man pages for rm and rmdir for more info.
 
Old 08-06-2005, 11:13 AM   #3
tyyp88
LQ Newbie
 
Registered: Aug 2005
Location: Estonia
Distribution: CentOS 3.5 x86_64
Posts: 11

Original Poster
Rep: Reputation: 0
Code:
[root@masterServer root]# rmdir httpd-2.0.48
rmdir: `httpd-2.0.48': Directory not empty
So, how can I remove the directory if its not emty?
 
Old 08-06-2005, 11:19 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Use:

# rm -rf httpd-2.0.48/*
# rmdir httpd-2.0.48
 
Old 08-06-2005, 11:28 AM   #5
tyyp88
LQ Newbie
 
Registered: Aug 2005
Location: Estonia
Distribution: CentOS 3.5 x86_64
Posts: 11

Original Poster
Rep: Reputation: 0
Code:
[root@masterServer root]# rm -rf httpd-2.0.48/*
[root@masterServer root]# rmdir httpd-2.0.48
rmdir: `httpd-2.0.48': Directory not empty
Still same s**t Does there is some explanes howto remove dir that contains files?

Last edited by tyyp88; 08-06-2005 at 11:48 AM.
 
Old 08-06-2005, 12:30 PM   #6
hfawzy
Member
 
Registered: Aug 2002
Location: Egypt
Distribution: Debian Sarge, Slackware 10.0
Posts: 163

Rep: Reputation: 30
use
# rm -rf httpd-2.0.48
 
Old 08-06-2005, 12:44 PM   #7
tyyp88
LQ Newbie
 
Registered: Aug 2005
Location: Estonia
Distribution: CentOS 3.5 x86_64
Posts: 11

Original Poster
Rep: Reputation: 0
Hi hfawzy, thanks dude! This command workz!!!

Command for deleteing non-emty's directory's
Code:
rm -rf "dir name"
 
Old 08-06-2005, 09:36 PM   #8
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Just be careful with that command, as one little slip can destroy everything if you're doing it as root. The options given to rm tell it to delete all files and directories within directories recursively and force deletion even when you'd normally get a warning. If you type the wrong thing to delete, your system can easily be gone.
 
Old 05-02-2007, 04:22 PM   #9
got_nix
Member
 
Registered: Oct 2004
Location: Jamaica
Distribution: Ubuntu 6.0.6 (Dapper Drake)
Posts: 59

Rep: Reputation: 15
Thanks this kinda helped me out today.. i didn't know it varied across distros
 
Old 05-02-2007, 05:20 PM   #10
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
It doesn't vary across distros, it's just a matter of whether you're directly deleting the directory with everything in it or deleting its contents before deleting the directory.
 
Old 05-02-2007, 05:50 PM   #11
got_nix
Member
 
Registered: Oct 2004
Location: Jamaica
Distribution: Ubuntu 6.0.6 (Dapper Drake)
Posts: 59

Rep: Reputation: 15
but generally rm -r dirname would get rid of a dir and all its files. thats what i do in ubuntu anyway. however I was helping a friend of mine with a centos server today and i had to use this method
 
Old 06-27-2012, 11:15 AM   #12
natechan
LQ Newbie
 
Registered: Jun 2012
Posts: 1

Rep: Reputation: Disabled
yes, it works in CentOS 6.2 today...rookie here...
 
Old 06-27-2012, 10:25 PM   #13
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
Note that -r = recursive and -f = force(!), which may be required, depending on the file ownerships/perms at the time.

As warned above, a relatively simple typo can remove more than you want or even the entire system.... It has really been happened to people.
Try not to use root when doing that, it should only be required if the files are owned by root.
 
Old 12-15-2013, 08:35 AM   #14
i3ringit
LQ Newbie
 
Registered: Dec 2013
Posts: 1

Rep: Reputation: Disabled
re: OP

For future inquiries:
Code:
rm -r -f dir_path
worked for me in CentOS 6.5
 
  


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
Script to delete files with 0k file size in a directory justgiver Linux - Newbie 4 01-28-2008 05:56 AM
How to delete directory/file (operation not permitted)? lvgamer1 Linux - Newbie 4 12-28-2004 11:53 AM
How do you delete a corrupted file or directory? BrianK Linux - General 8 10-23-2004 01:33 PM
delete file via console psa Linux - Newbie 3 08-24-2004 03:24 AM
how to delete a file or directory completely ty263 Red Hat 1 07-18-2004 02:34 PM


All times are GMT -5. The time now is 03:08 PM.

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