LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How-To Delete File/Directory in CentOS console (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-delete-file-directory-in-centos-console-350557/)

tyyp88 08-06-2005 09:52 AM

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

Nylex 08-06-2005 10:00 AM

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.

tyyp88 08-06-2005 10:13 AM

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?

Nylex 08-06-2005 10:19 AM

Use:

# rm -rf httpd-2.0.48/*
# rmdir httpd-2.0.48

tyyp88 08-06-2005 10:28 AM

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 :rolleyes: Does there is some explanes howto remove dir that contains files? :study:

hfawzy 08-06-2005 11:30 AM

use
# rm -rf httpd-2.0.48

tyyp88 08-06-2005 11:44 AM

Hi hfawzy, thanks dude! This command workz!!! :D :D :D

Command for deleteing non-emty's directory's
Code:

rm -rf "dir name"
:twocents: :twocents: :twocents: :twocents: :twocents:

jrdioko 08-06-2005 08:36 PM

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.

got_nix 05-02-2007 03:22 PM

Thanks this kinda helped me out today.. i didn't know it varied across distros

jrdioko 05-02-2007 04:20 PM

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.

got_nix 05-02-2007 04:50 PM

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

natechan 06-27-2012 10:15 AM

yes, it works in CentOS 6.2 today...rookie here...

chrism01 06-27-2012 09:25 PM

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.

i3ringit 12-15-2013 07:35 AM

re: OP
 
For future inquiries:
Code:

rm -r -f dir_path
worked for me in CentOS 6.5


All times are GMT -5. The time now is 09:19 AM.