Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > I accidentally removed rm

I accidentally removed rm
Thread Tools
foobars
Mac Elite
Join Date: Jan 2001
Location: Somewhere in the land surrouding Fenway Park
Status: Offline
Reply With Quote
Oct 31, 2002, 05:13 PM
 
This is kind of embarrasing seeing as I have quite a few years of UNIX expierence but I guess we all make mistakes...

Today I was removing X11 from my system and I accidentally typed "sudo rm sudo rm ..." which then removed the rm command from my system.

I'm a developer and the version of OSX that I'm running right now is a little more current than what you guys are running, so I don't think re-installing the BSD subsystem using Pacifist is an option.

I'm not totally sure but isn't rm just a binary program like any other? If so I'd really appreciate it if someone could email it to me at [email protected]. Any other suggestions?

Thanks.
     
piracy
Mac Elite
Join Date: Mar 2001
Status: Offline
Reply With Quote
Oct 31, 2002, 05:20 PM
 
This shouldn't have rermoved rm from your system...unless you were in the /bin directory at the time, where rm resides...if that was the case, yes, it can come from any other OS X system.

Or, you can just take it from your OS X install disc. It's at

/bin/rm

on the disc as well. Make sure you set its permissions, etc., correctly again:

-r-xr-xr-x 1 root wheel
     
foobars  (op)
Mac Elite
Join Date: Jan 2001
Location: Somewhere in the land surrouding Fenway Park
Status: Offline
Reply With Quote
Oct 31, 2002, 05:27 PM
 
In fact I was in the /bin directory at the time because thats where X11 is.

Thanks for the tip it worked great.
     
Diggory Laycock
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Oct 31, 2002, 07:53 PM
 
Glad your problem is fixed - That means I can admit that I found it funny in a perverse sort of way - You know rm-ing rm.
     
wataru
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Oct 31, 2002, 07:58 PM
 
Originally posted by Diggory Laycock:
Glad your problem is fixed - That means I can admit that I found it funny in a perverse sort of way - You know rm-ing rm.
I'm kind of surprised that you can use a command to delete itself. Shouldn't it return an "in use" error?
     
Lew
Senior User
Join Date: Dec 2001
Location: England, UK
Status: Offline
Reply With Quote
Oct 31, 2002, 08:14 PM
 
Won't that have also removed the 'sudo' binary?
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
Oct 31, 2002, 08:37 PM
 
Originally posted by wataru:
I'm kind of surprised that you can use a command to delete itself. Shouldn't it return an "in use" error?
Ha, rm doesn't care about such petty distinctions as whether a file is in use or not. Its job is to delete, and dammit, it doesn't ask stupid questions, it deletes. That's why it's such a dangerous tool and should be used very sparingly and carefully.

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
Oneota
Professional Poster
Join Date: May 2000
Location: Urbandale, IA
Status: Offline
Reply With Quote
Oct 31, 2002, 11:29 PM
 
Well, actually, the reason you were able to rm 'rm' is because Unix programs use the 'unlink()' system call to delete files, which simpy removes the directory entry's pointer to the inode of a given file. Then, as soon as the file is no longer in use, the OS's garbage-collection mechanism notices that there's a file with no names pointing to it and deletes the file. So any program can unlink any file, and the file itself will continue to exist until the OS notices that no one's using it anymore.

Wilfredo Sanchez presented his excellent paper on the challenges of integrating the Unix and Mac OS environments to the 2000 USENIX conference. His paper talks about the differing semantics of Mac and Unix deletes (among other things).

It's a great read! I actually just did a presentation on that paper myself for my Operating Systems class on Tuesday.
"Yields a falsehood when preceded by its quotation" yields a falsehood when preceded by its quotation.
     
Xeo
Moderator Emeritus
Join Date: Mar 2001
Location: Austin, MN, USA
Status: Offline
Reply With Quote
Nov 1, 2002, 12:09 AM
 
Originally posted by GFive:
Won't that have also removed the 'sudo' binary?
No, because sudo is in /usr/bin and he was in /bin.
     
Lew
Senior User
Join Date: Dec 2001
Location: England, UK
Status: Offline
Reply With Quote
Nov 1, 2002, 04:37 AM
 
Makes sense. I should have checked before I posted that
     
DeathMan
Mac Elite
Join Date: Aug 2001
Location: Capitol City
Status: Offline
Reply With Quote
Nov 1, 2002, 04:46 AM
 
One time I was trying to extract a tarball backup that I had, but sent tar the wrong parameter (-c instead of -x, duh) and it overwrote the file with an empty one (at least I think that's what happened, it was really late, and all of the sudden my tarball was gone, and the only command I found that might have done it was that) For future reference, not that I think I'll make that particular mistake again, is there a way to recover something like that?
     
DaveGee
Mac Enthusiast
Join Date: Mar 2001
Status: Offline
Reply With Quote
Nov 1, 2002, 08:55 AM
 
That's one mistake you can't make twice...
     
Oneota
Professional Poster
Join Date: May 2000
Location: Urbandale, IA
Status: Offline
Reply With Quote
Nov 1, 2002, 10:34 AM
 
Originally posted by DaveGee:
That's one mistake you can't make twice...
Oooooo.... </me throws rotten fruit in DaveGee's general direction>
"Yields a falsehood when preceded by its quotation" yields a falsehood when preceded by its quotation.
     
Jeff Binder
Junior Member
Join Date: Feb 2002
Status: Offline
Reply With Quote
Nov 1, 2002, 06:26 PM
 
Originally posted by CharlesS:

Ha, rm doesn't care about such petty distinctions as whether a file is in use or not. Its job is to delete, and dammit, it doesn't ask stupid questions, it deletes. That's why it's such a dangerous tool and should be used very sparingly and carefully.
I do most of my work at the command line, so what do you expect me to do? I use rm whenever I have the need to remove a file. Of course you should be careful with it, but it's not so dangerous that you should only use it when you have no other option.

rm'ing in super-user mode is another matter, of course.
self = [[JeffBinder alloc] init];
     
Mithras
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Nov 2, 2002, 09:52 AM
 
Originally posted by Jeff Binder:

rm'ing in super-user mode is another matter, of course.
Actually, I find that I care least about the things I can screw up as the superuser.

If I trash my /System folder -- so what? Reinstall the OS, and all is well.

On the other hand, if I'm sitting in my home directory and accidentally rm * -- aack! There goes whatever I've worked on today*, which means much more to me than some pile of Apple programs.


*today only, since like a Good Boy I have set psync to back up my Documents folder every morning, and a crontab task that saves an archived copy of the backup every month
     
eno
Banned
Join Date: Sep 2000
Location: Fightclub
Status: Offline
Reply With Quote
Nov 2, 2002, 10:52 PM
 
Bah, all this would be no problem if you could do this:
Code:
#rm /bin/rm #undo #ls rm rm
     
   
 
Forum Links
Forum 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 On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:17 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,