LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 11-02-2003, 03:07 AM   #1
Micro420
Senior Member
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986

Rep: Reputation: 45
rm command - deleting directories


In the console, how do I remove an entire directory using the rm command? I can't figure it out.

I know how to remove single files by using the command rm <filename>.
 
Old 11-02-2003, 03:10 AM   #2
scott_R
Member
 
Registered: Jul 2003
Location: Brighton, Michigan, USA
Distribution: Lots of distros in the past, now Linux Mint
Posts: 746

Rep: Reputation: 31
rm -f <dir name>

that should remove your directories, even if they aren't empty. The -f means force.
 
Old 11-02-2003, 03:10 AM   #3
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
rm -r <directory name>

depending on how your distro aliased your rm command, it may ask you if you want to descend down the directory and subdirectories and prompt you if you want to delete all the files inside the parent directory including the subdirectories. if you're totally sure (rm can be dangerous), you can use instead:

rm -rf <directory name>

that will just delete the directory and everything in it without prompting you (again can be dangerous).
 
Old 11-02-2003, 03:11 AM   #4
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
Quote:
Originally posted by scott_R
rm -f <dir name>

that should remove your directories, even if they aren't empty. The -f means force.
actually that will not. it will pop up an error saying the <dir name> is a directory. you need the recurse option (-r).
 
Old 11-02-2003, 03:14 AM   #5
dalek
Senior Member
 
Registered: Jul 2003
Location: Mississippi USA
Distribution: Gentoo
Posts: 2,058
Blog Entries: 2

Rep: Reputation: 79
Do NOT do this

Code:
rm -rf /
If you do, you will reinstall. After you stop and and .

Be careful now ya here.

Later
 
Old 11-02-2003, 03:19 AM   #6
Libu
Member
 
Registered: Oct 2003
Location: Chennai
Distribution: Slackware 12.1
Posts: 165

Rep: Reputation: 36
rm -f cannot be used to remove directories, u wud have to use the recurse option (-r) to remove directries. If that does not help then use the force option along with it.
e.g rm -rf
man rm shud be able to tell u more w.r.t to ur distro..
 
Old 11-02-2003, 03:19 AM   #7
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
Quote:
Originally posted by dalek
Do NOT do this

Code:
rm -rf /
If you do, you will reinstall. After you stop and and .

Be careful now ya here.

Later
well as root anyway. as a user, you may lose something like /tmp or some other write-accessible-to-all-user files and directories. but yes rm with the force flag and/or the recurse flag is dangerous.
 
Old 11-02-2003, 04:16 AM   #8
Micro420
Senior Member
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986

Original Poster
Rep: Reputation: 45
What the heck?? this is confusing! First someone tells me to do rm -rf, and then another user says that I will lose everything and may have to reinstall?

Let's say that I didn't read the warning before hand and actually type rm -rf. What if I lost everything? Man, I would be SO pissed. I'm kind of upset that someone would give out a dangerous command like this if it could easily and potentially force me to reinstall Mandrake.

I think I'll forget the console since it seems dangerous and stick with just deleting via KDE. I just wanted to see if I could make my way around the console, but apparently it sounds like a bomb waiting to go off.

Thank God for drag-n-drop in the trash can icon.
 
Old 11-02-2003, 04:24 AM   #9
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
Quote:
Originally posted by Micro420
What the heck?? this is confusing! First someone tells me to do rm -rf, and then another user says that I will lose everything and may have to reinstall?

Let's say that I didn't read the warning before hand and actually type rm -rf. What if I lost everything? Man, I would be SO pissed. I'm kind of upset that someone would give out a dangerous command like this if it could easily and potentially force me to reinstall Mandrake.

I think I'll forget the console since it seems dangerous and stick with just deleting via KDE. I just wanted to see if I could make my way around the console, but apparently it sounds like a bomb waiting to go off.

Thank God for drag-n-drop in the trash can icon.
no,

rm -rf /

will delete all your linux installation if you do it as root. / is the parent directory of everything. it's just a warning that using rm -rf can be dangerous. especially using rm -rf over the sytem directories. a single misspelling will spell disaster. for instance, what if you just want to delete a directory in /tmp called tmp that was owned by root? as root, you'd use:

rm -rf /tmp/tmp

what if you "misspelled" the directory adding a space after the first "/"

rm -rf / tmp/tmp
this is bad. since rm can remove multiple files. to rm it looks like you want to delete "/" and some directory called "tmp/tmp". well it will delete "/" first. whoops! reinstall time.

just be careful using rm -rf. but the command to remove a directory is still:

rm -rf <directory name>
 
Old 11-02-2003, 04:24 AM   #10
dalek
Senior Member
 
Registered: Jul 2003
Location: Mississippi USA
Distribution: Gentoo
Posts: 2,058
Blog Entries: 2

Rep: Reputation: 79
Well if you are not carefull you can type it in wrong in windoze. I did that once.

The one I posted is the WRONG way. It deletes everything, if you are logged in as root.

The ones they gave should delete the directory you want and nothing else.

I do what you did, I put it in the trash can and wait a while before I empty. If I need it, at least I know where it is.

Sorry if I confused you. I just didn't want you to type it wrong and say you didn't know. Sometimes it's not knowing what to do, but knowing what not to do.

Later

 
Old 11-02-2003, 02:06 PM   #11
Micro420
Senior Member
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986

Original Poster
Rep: Reputation: 45
Quote:
Originally posted by dalek
Well if you are not carefull you can type it in wrong in windoze. I did that once.

The one I posted is the WRONG way. It deletes everything, if you are logged in as root.

The ones they gave should delete the directory you want and nothing else.

I do what you did, I put it in the trash can and wait a while before I empty. If I need it, at least I know where it is.

Sorry if I confused you. I just didn't want you to type it wrong and say you didn't know. Sometimes it's not knowing what to do, but knowing what not to do.

Later

I still don't understand why I can't just type 'rm <directory name>' and it's gone. Why all these weird '-rf' marks???

In MS-DOS, it was just 'del <directory>' or 'deltree <directory>'.

I don't see how MS-DOS was dangerous unless you used the command 'format'. I guess my ignorance with the linux console is making me be extra cautious now.
 
Old 11-02-2003, 02:18 PM   #12
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
Quote:
Originally posted by Micro420
I still don't understand why I can't just type 'rm <directory name>' and it's gone. Why all these weird '-rf' marks???

In MS-DOS, it was just 'del <directory>' or 'deltree <directory>'.

I don't see how MS-DOS was dangerous unless you used the command 'format'. I guess my ignorance with the linux console is making me be extra cautious now.
deltree /y c:\

is dangerous. rm -rf / is just as dangerous.

-rf means that you rm will recurse down the parent directory and all subdirectories and delete all the files, subdirectories, and the parent directory without prompting.

the -r is the same thing as calling deltree and the -f is the same thing /y. but instead of calling a new function, deltree, you use flags on one command, rm.
 
  


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
Deleting directories NomadABC Linux - Newbie 2 02-10-2005 02:11 PM
Deleting Directories J_Bone Linux - Newbie 4 08-17-2003 04:19 PM
deleting directories AZDAVE Linux - Newbie 1 08-15-2003 10:05 AM
Deleting full directories? AekaGSR Linux - Newbie 5 06-19-2003 05:50 PM
Deleting directories with files in them AMDPwred Linux - General 7 02-16-2003 12:06 PM


All times are GMT -5. The time now is 04:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration