This release fixes the install script; it no longer deletes the /usr directory in its entirety. But how on earth did this get through even basic testing? Absolutely shocking!
Seems non-trivial to test. First, its in a bash install script - i wouldn't know where to start. Second, if you tested the behavior, you might just test that it "deletes /urs/lib/nvidia-current/xorg/xorg" by running the install script and checking that the folder is gone. Guess what, the folder is gone...test passes.
You can use GNU remove, which lets you put arguments last for safety, on any Linux box:
Eg:
rm /whatever -rf
Ie, if you hit enter too early, you still haven't forced.
I've been using Linux for 14 years and have never accidentally rm'd recursively. I'm not sure when they added it, but I've been using it for a very long time.
I just use it for my boxes. It doesn't stop me putting something silly in a make file (as in the example here), but it does stop me getting burnt by it.
I don't remember the exact details, but a few years ago there was a Perl module that did something like:
my $path = something_that_can_return_undef_on_failure;
`rm -rf /$path`;
during the execution of its test suite. The author didn't catch it in testing because he never ran "make test" as root (who would?). But people on the Internet ran "make test" as root, with disastrous consequences.
I'm not sure if you're being sarcastic with the "who would?" portion of your comment, but doesn't cpan run tests, by default, whenever installing something? And, most people who aren't Perl developers with their own private Perl installation install CPAN modules as root, so they are available to all users. So, to answer the question seriously: Most people.
rm: use --no-preserve-root to override this failsafe
Brilliant, at long last at least a bit of protection! :) Sadly, I can still remember doing this to my one of my first Linux installs, albeit via the classic:
rm -fr .*
On the plus side, that day I learned one hell of a lot about how Linux works ;)
I knew someone who, in the days of Windows 3.1, managed to accidentally invoke "format c:" from inside Microsoft Word - I was in the same room as them when they did it and heard the cries for help. What they couldn't do was explain to me what they had done to accompish such a feat.
Windows users that aren't privy to *nix culture generally don't find all of the "rm -rf ..." jokes all that funny. They get it, but it's sort of like telling a german joke in English to an English speaker only; they get it, but it looses it's humor if you aren't privy to the culture.
"Double-edged sword" has never worked for me, as a cliche. Do you often find yourself inadvertently smacking against the dull side of a single-edged sword, such that you stay away from double-edged swords for your own safety? rm is like a double-ended knife, i.e.: http://image.shutterstock.com/display_pic_with_logo/4253/425...
(Fun fact: many knife throwers grip the blade end anyway, rendering the cliche to an even simpler "rm is like a knife".)
This is completely unrelated to the original topic at hand, but I thought it might be interesting to shed some light on knife throwers' grips. For a given thrown weapon, whether a knife or an axe (or anything else that is meant to spin end-over-end), the number of revolutions is roughly fixed and is a function of the distance from the thrower to the target. Thus if you happen to be at a distance where you're getting a half revolution, you'll throw from the knife blade, or turn the axe around (so it's pointing towards you on throw). That enables it to hit the target the right way around. Of course, many people prefer to take a half-revolution step forwards/back so that they can throw from the tip regardless, just as a matter of form -- I did this for a while, although I feel I get better control when throwing from the handle.
I have always been amazed by knife-throwers' ability to calculate the amount of revolutions between their hand and their target when throwing. It just seems like one of those things that the human brain couldn't possibly calculate correctly on a consistent basis. Does it take a very long time to get comfortable with it when training?
It took me a couple months to get decent at it, though I'm still a quarter revolution or so off frequently. Axes came far more naturally to me, where I generally get very close to perfect on my first throw. If distances are marked I'm fine with either, though.
Are there specific techniques to learning it, or is it just experience? For example, do you have to be very familiar with the specific weapon you're using? Does "visualizing" help? Are there tricks or points of reference that you use to help out?
I just practiced a lot, really. Familiarity with a specific weapon helps in terms of knowing how it flies, how it's balanced specifically, etc but you pick that up after a few throws. Biggest piece of advice I can give is to not rush -- I have a tendency to get too "into it" and lose focus on my technique, so I had to slow myself down, take a few breaths, and think through the whole process.
If you want to get into it, I recommend two things: first, find someone who does thrown weapons and can talk you through the basics and point out mistakes in your form (SCA events are a great way to do this, and that's how I got into it), and the second is just to get a slice of a tree trunk and some weapons and start practicing regularly.
I found it to be a great way to relax and get my brain away from tech. It's one thing I miss in moving to NYC.
I had a friend who actually knew proper sword technique, and he was not impressed by my machete with saw teeth on the other edge. With a single-edged sword you can use your forearm to support it when blocking, but with a double edged sword, not only can you not do that, but trying to block with the sword itself allows your opponent to overpower you and press your own sword against you.
For what it's worth, you can use your arm to support it if you're armored as well. If you're in chainmail/plate, the force is distributed well enough that there's no reason you can't do this, even with a double-edged weapon. That said, there are many swordfighting styles where armor hinders you significantly, and you frequently see single-edged weapons in these. It's actually really interesting to study the history of swords, their techniques, and the armor commonly used along side them -- used to have a really good book about this, but can't find it now.
While we're on the subject, has anyone successfully found/created a replacement for rm on OS X that moves files to the trash, but doesn't break the interface of rm for use in scripts?
Normal Unix method of doing this is via LD_PRELOAD, then you wrap unlink() in something that moves things to a folder. I used something - think it was libtrash - when I used Linux on the desktop, but haven't investigated what the OS X equivalent would be.
I use trash-cli (http://code.google.com/p/trash-cli/) on Linux, it is in Python so it shouldn't be too hard to get running on OS X (although I guess you might have to modify the location of the trash folder)
It is great. Quality linux support for nvidia optimus cards is pretty important for a lot of people I know, and bumblebee appears to provide it. (Apparently, optimus cards act /really/ strangely without a proper driver.)
To be fair, it was only rendering the machine unusable, not wiping out your home directory. A simple OS reinstall should get people back to square one. (Unless the OS reinstall script was botched and formats your disk when you've told it not to, which I've heard the latest Ubuntu does.)
Perhaps because I'm not a GitHub user, and because I've only ever peeked at HNers' GitHub accounts, but I was always under the impression that given the nature of the service, it would have an early-days-of-HN feel wrt to user behaviour.
It was a little disheartening to see the number of Reddit-esque comments that are simply a couple of words along the lines of "omfg" and a constant stream of meme abuse. I expected better from the programming community.
Sigh. Am I just becoming old, jaded and too elitist for my own good?
No, that was exactly my impression as well. Those comments remind me more of the Daily WTF where everyone points and laughs, but people rarely step forward to explain exactly what the problem is, and more importantly the solution.
I laugh at Daily WTF but I always cringe thinking about some of those its3AMgottalaunchat8AMshitI'msotired nasty kludgy hacks I've been responsible for.
Or just the times I was well rested, under no pressure, and just coughed up some stupid.
It's like reading Youtube comments--not for the faint of heart.
And the jab at reddit from the HN pedestal is probably misguided... reddit used to be more like HN, and HN is becoming more like the bad parts of reddit every day.
Every site tends toward Youtube level comments as time passes, and the people who don't like it eventually jump ship to a new site, and then the process repeats itself.
I've only been here for almost 2 years (well close enough to 2) however I would say the average HN thread is still more insightful than the average Reddit thread (including filtered sub-Reddits)
"And the jab at reddit from the HN pedestal is probably misguided... reddit used to be more like HN, and HN is becoming more like the bad parts of reddit every day."
There's nothing more irresistible to a tech geek than recursive irony, regardless of where they fall (or wish they fell) on the YouTube/Digg/Reddit/HN commenter spectrum.
Not really the same thing. I'm saying that HN shouldn't look down its nose at reddit, since it appears to be heading the same direction. I'm taking a jab at both sites (and all sites, really).
The change is a few weeks old, and all of the comments are about an hour old. Seems safe to say that the comments reflect more on "people linked to this change from HN/Reddit/etc" than "people that use Github"
I'm not about to go looking at all of their accounts but considering the comments most left it looks like they were already logged in. I doubt they all signed up just to post a 'lol'. I'd put my money on these comments being from an intersection of github and reddit/hn/digg users.
> I doubt they all signed up just to post a 'lol'.
Well, actually /b/ often raids web pages and do such things. If anybody working at GitHub can correlate the comments and the age of the accounts, I wouldn't be surprised to be surprised.
Plus, to me, it appears more like /b/ than reddit. I have a very limited experience in reddit though (yes, those anonymity-driven, fast-flowing communities are interesting).
I suppose what you're seeing here is actually a reflection of Reddit, 4Chan & friends, i.e. I suppose this very commit has been posted in some of those places as well. I still have some hope for Github-in-general.
HN is mirrored on tons of sites. The fact that it's the default on somewhere like jimmyr.com for 'coding' should tell you how well-known news.yc has become. Don't think it's full of erudite hackers only anymore.
You're not too much of an elitist, you're too much of a crank. Does it really dishearten you to see a bunch of people having a good laugh? Does every word written on the internet need to be researched/profound to be worthy of reading? This is the internet, it will forever dishearten you if you think in these terms.
Exactly. This isn't representative of 'the github community', it's more like 'the subsection of the reddit/hn/etc communities that feel the need to post funny pictures using their github accounts to do it'
>It was a little disheartening to see the number of Reddit-esque comments that are simply a couple of words along the lines of "omfg" and a constant stream of meme abuse. I expected better from the programming community.
You don't get good discussion from a commenting system. Github's comments aren't designed for with-each-other discussion, they're designed for at-the-author/audience commenting.
HN takes comment quality extremely seriously, and with-each-other discussion is perhaps the main focus.
reddit is somewhere in between: most of the users of reddit don't seem to be interested in discussion, but in open-ended polls a la AskReddit, IAMA, DAE, etc. The fact that reddit threads only last for a few hours, and that the volume of comments is so huge that it's hard to expect the people you're aiming your comment at to get anywhere, these both reward commenting rather than discussion; /r/bestof does as well. That said, reddit's topical breadth draws in lots of smart people, who are usually looking to talk about something interesting.
The vBulletin/phpBB model of forums doesn't really scale too well (unless you go the SomethingAwful route and impose a fee and lots of super-strict moderation) but it works well with up to around 150 active users. The best forums have the highest SnR on the Internet.
4chan-ish anonymity works up to around 5000 before you get chaos, hence the longing for "old /b/" and the value in the other boards.
I learned a rather unusual trick to keep myself safe from unintended glob matches. It is not "fool"-proof, but it will probably dilute an unmitigated disaster into an incomplete disaster: Keep a file named -i in the sensitive directories. When glob picks it up, which should be fairly early, it will be treated like a command line argument. Has saved me on occasions.
I also had a friend in school who used to, for whatever reasons, name his files using characters drawn from a pool of only two characters. One being "." the other "*". Please don't ask me why. He would then try to delete some particular file. You can well imagine what would happen next. This happened multiple times, till I went ahead and populated his directories with "-i" files. That worked great.
I usually keep rm aliased to 'rm -i', but once I did get burned. It was not because of hitting return early but because of having a space between a directory and the trailing "/".....while running rm as root. It was taking a bit longer than I had imagined, so I looked again at the prompt to see what had I typed..$#@!&~ :)
Over the years I've been steadily training myself to type "WHERE" earlier in the process, until I have finally settled on the obvious-in-hindsight solution: Always simply start with the WHERE clause.
(Of course every effort not to be on the SQL shell of a production server in the first place should be taken, but sometimes you need a sledgehammer and nothing else will work.)
The habit I learned was: before running any DELETE or UPDATE statement, run a SELECT with the same WHERE. (e.g. if I meant to say DELETE FROM puppies WHERE cute = 0, first run SELECT FROM puppies WHERE cute = 0.)
I find I remember to do that because of the direct benefit (getting a sneak preview of what I'm going to delete), but it also means I end up thinking twice about the WHERE statement, so I'm much less likely to miss it out or get it dramatically wrong.
I'm a couple of levels more paranoid than that.
First, I'll write the DELETE as a regular SELECT (to preview number of rows), then turn it into a SELECT INTO to save the soon-to-be-deleted rows into a table with a backup_date_ prefix (So old backups can be deleted occasionally). Next, before changing anything, I wrap the statement in a BEGIN TRAN, and ROLLBACK TRAN. After all that, I will finally modify the SELECT INTO into a DELETE statement, run it once while wrapped in the transaction (to verify that the number of rows modified hasn't changed), and then finally run without the transaction to delete the rows.
Overkill?
I do the same thing. Not sure that it has ever saved me from a disaster, but I do like the sneak peak and am DELETE FROM disaster free. knocking on my desk
I've always written my sensitive delete queries like this:
select *
-- delete x
from Table x
where x.whatever = 1
That way by default it's just a select, and then AFTER you verify the result set you can highlight from the delete on and then run the query (as long as you're in a shell that will run only the highlighted part. I was working in SMS.) This was a common idiom where I worked.
I always (with sql server at least) add a begin tran/commit/rollback before any prod statements, because of getting burned in the past.
Even if you add the WHERE, but put it on a second line and only run the first, the transaction will help...
Of course, if it's going to lock the data, do all of the statements together:
BEGIN TRAN
UPDATE ... WHERE ...
SELECT ... WHERE .... -- show that the update worked
ROLLBACK
well, the only difference is that truncate also resets the auto-increment to zero. But you could allow where 1=1 to make it explicit if people really wanted an unbounded DELETE FROM.
No entirely. DELETE will work with cascading foreign keys, while TRUNCATE will not, at least on SQL Server. Also, DELETE is logged and (I believe) TRUNCATE is not. Having said that, I agree that a WHERE clause should be required - you can always say "WHERE 1=1" or similar if you really mean to delete all rows.
For me it's not the stomach. First, breath stops, then for a few seconds numbness in chest and jaw, then face turns pale and soon red. A small nausea follows and then regret sets in. The rest of the day is ruined.
I've run a TRUNCATE in production by accident thinking I was logged into the dev system. I truncated the 4 core user / transaction tables. I've never felt the blood drain from my body so quickly.
Good old binary logs and an office floor to sleep on. I make copies of the data whenever deleting or truncating now. I think we all have to do something ridiculously stupid to start taking precautions.
Yeah, it is a GNU extension to rm/ls/and others to have the options at the end of the list. Never did like that, but it does mean that people who log into my BSD boxes can never force delete or recursive delete ;-)
The simplest hack I've ever used for this kind of thing is to keep a notepad on my desk and whack it instead of the enter key whenever I'm doing critical work.
In the time it takes to thump the notepad, it gives my brain a vital few seconds to triple check what I just typed before I blast monkies into space. Saved my behind more than a few times.
Never use rm's -f flag while operating as the root user. Never. Replace with -i until you are absolutely 100% certain the script you're writing works as expected. Always doubt yourself; be humble.
The reason we all know to be careful with rm -r is because of that one time we weren't.
Me, it was the time I rm r'ed the MySQL data directory for my company's customer service management system. Oops. Thankfully we had a backup from the month prior, but I learned two things that day: a) be really careful with rm and b) take it on yourself to make sure IT is backing up stuff that you're messing with.
Was asked to uninstall IBM/Rational ClearCase from our source code repository server. Apparently at the time, Clearcase's installer NFS mounted 127.0.0.1:/ to a subdirectory. Don't ask me what brain-dead system designer thought this was a good idea.
So, I did a simple /etc/init.d/clearcase stop (not sure that is the exact name) and:
# rm -rf /opt/clearcase
(hmm... that seems to be taking a little too long to run)
Panic - then ctrl-C - it was too late, /opt/clearcase/foo was NFS mounted 127.0.0.1:/ and it had already trashed /bin, /sbin, /etc, /var, and most of /usr.
Luckily I had good backups, but we did spend the rest of the day rebuilding the source repository while the developers couldn't check in any code.
I've also done this, but it was a cPanel server and the jailshell did bind mounts to various directories on the system. I tried to remove the jailshell instance, and ended up removing a whole lot more.
One of my first tasks after being given root access at my first n?x job at an ISP was "clear off all of the DNS stuff on $main_server since we have $dedicated_dns_server now".
So I merrily started mv-ing things to a scratch directory that we could wipe in 6 months if we didn't need anything from it.
Unfortunately, the zone file directory was NFS mounted from* $dedicated_dns_server. With pass root set.
I think I took all of A through to K of client zones offline before we noticed.
I'm just very very glad I decided to do it as an mv rather than an rm, since it meant all I needed to do was copy things back.
Not that I really learned my lesson that time; it took a couple more semi-disasters before I got sufficiently paranoid to be reasonably safe as root.
dead tired, 4am in the morning working on a client app for a huge client of theirs (I was subcontracting) was trying to remove everything inside a folder and instead of going
rm -rf ./*
I went
rm -rf . (can't get the wildcard thingamajig to show up)
It took me a second to understand why the command was taking so long to run, by the time I figured it out and killed the command, I had wiped out almost half of what was on the drive.
Biggest "oh. my. god" moment of my life. I think I had an actual panic attack for a bit even.
Luckily, media temple had a backup from just a few hours earlier (I was lucky, they only ran them periodically and it just so happened to fall on that day).
Back in the day, rm followed .. if you specified it on the command line. It went like this:
You are in .; The current directory listing include ..; Recursively deleting everything deletes everything on the drive.
Actually, I think the one time I saw someone do this, wildcards were involved. And I was going to explain, but the comment system is making my asterisks into bold markers.
A couple months ago I had to recover some rm'd files by basically grepping 512-byte blocks on the file system for the file headers then writing out the next few KB to a file on a separate partition to manually go through..
My command sequence was more like this though, rather than a straight rm:
find -name '*.java' | xargs grep --color 'something'
# guh, get rid of these old copied .svn dirs polluting output
find -name '.svn' | xargs rm -rf
# now what was that..
find -name '*.java' | xargs rm -rf
Forgot to edit the right side of the pipe back to the grep. Zealous use of the up-arrow burned me...
That's what I thought. I'd be happy if anyone chimed in with a legitimate reason, but I won't be surprised if the lack of a recycling bin is just one more symptom of the Linux developer community's apathy towards the actual human beings who use their software.
I would speculate that it is a historical reason. It's no secret that the Unix environment was not designed for personal use in homes, but on mainframe time shared computers inside universities and businesses. Space was limited, and just moving files to another location to deal with later added unnecessary steps to a process that didn't have much of a benefit, at the time.
As space has become less valuable on computers, and they have become less of a specialized tool, it may be wise to add one, but most of the desktop environments already implement it already so there is no need to recreate the functionality at a lower level.
You're operating at a layer below where a trash can makes sense. Pretend that this command had moved everything to a trash can. The command to move the files out of the trash can now resides in the trash can, where it isn't being very useful. It's still possible to recover the files, but then again, it's also still possible to recover the files you deleted with rm.
rm is on the same layer as the DOS del command. Neither goes to the trash can, because they operate on a lower level.
it's also still possible to recover the files you deleted with rm.
If you're lucky and didn't write too much to the hard-disk after deletion, yes, but with a recycling bin you have much higher chances of recovery.
Regarding `del` in DOS: You're the second one to bring up that analogy. I don't see how this is relevant. Just because Windows does it that way doesn't mean that it's good.
Because that's not what rm does. Changing it would be breaking all sorts of standards. Many, many things depend on rm simply unlinking files. Why don't you use a different program if you would like to have some sort of trashbin behavior?
I'd be cool with using a clone of `rm` that sends to the recycling bin instead of actually deleting. I think that Linux should include a clone like this by default.
Even if it did, you wouldn't use it in this case. Windows batch files delete files outright too, instead of sending them to the recycling bin. You don't want to have to depend on the user to clean up after your automation.
You don't want to have to depend on the user to clean up after your automation.
I don't see what's the big deal is. Once in a while when the recycling bin gets too big, the user can empty it. Or you can have a scheduled operation that deletes stuff after 30 days.
Mine does, now. I have a directory ~/.trash and a script rm that moves files to the trash. If I really want to permanently delete something I need to use /bin/rm (including for cleaning out my .trash dirs).
ADDED: Note that I have a .trash in each user's home directory including /root. And a copy of the rm script in each user's home/bin.
Looks like someone never read the Unix Hater's Handbook. Another fun thing is rm + shell expansion. A file named * or / can cause extremely unintended deletions.
246 comments
[ 2.7 ms ] story [ 247 ms ] threadEg:
rm /whatever -rf
Ie, if you hit enter too early, you still haven't forced.
I've been using Linux for 14 years and have never accidentally rm'd recursively. I'm not sure when they added it, but I've been using it for a very long time.
Anyway, it accidentally removed rm-rf'ed /, I only discovered it in time because it gave errors about removing nodes in /proc...
rm: it is dangerous to operate recursively on `/'
rm: use --no-preserve-root to override this failsafe
Brilliant, at long last at least a bit of protection! :) Sadly, I can still remember doing this to my one of my first Linux installs, albeit via the classic:
rm -fr .*
On the plus side, that day I learned one hell of a lot about how Linux works ;)
http://thedailywtf.com/Articles/Bourne-Into-Oblivion.aspx
http://arstechnica.com/reviews/01q4/pool_of_radiance/pool-1....
I suppose that /usr does store a good chunk of what the Windows directory has in it though.
it's like explaining jeep jokes to non-jeep owners.
ftfy.
Also, it's very unclear to me what that the situation you are describing entails.
/s
Grammatically, your sentence is no less ambiguous.
(Fun fact: many knife throwers grip the blade end anyway, rendering the cliche to an even simpler "rm is like a knife".)
If you want to get into it, I recommend two things: first, find someone who does thrown weapons and can talk you through the basics and point out mistakes in your form (SCA events are a great way to do this, and that's how I got into it), and the second is just to get a slice of a tree trunk and some weapons and start practicing regularly.
I found it to be a great way to relax and get my brain away from tech. It's one thing I miss in moving to NYC.
http://www.nightproductions.net/cli.htm
I prefer 'brew install rmtrash'
I like the idea of actually wrapping the unlink syscall, but I have no idea if/how darwin allows that.
I've never heard of BumbleBee, but it must be great if a user can have their machine wiped out and still thank the library author for their work.
"I thinking that something is messed up with bashrc or sh because in few seconds I cannot execute any command in other terminal.
Am I doing something wrong? Hope You can help me."
https://github.com/MrMEEE/bumblebee/issues/122
It was a little disheartening to see the number of Reddit-esque comments that are simply a couple of words along the lines of "omfg" and a constant stream of meme abuse. I expected better from the programming community.
Sigh. Am I just becoming old, jaded and too elitist for my own good?
Or just the times I was well rested, under no pressure, and just coughed up some stupid.
And the jab at reddit from the HN pedestal is probably misguided... reddit used to be more like HN, and HN is becoming more like the bad parts of reddit every day.
Every site tends toward Youtube level comments as time passes, and the people who don't like it eventually jump ship to a new site, and then the process repeats itself.
http://ycombinator.com/newsguidelines.html
I wonder if the only saving grace of HN is that it's not completely anonymous.
But you just did the same thing...
Well, actually /b/ often raids web pages and do such things. If anybody working at GitHub can correlate the comments and the age of the accounts, I wouldn't be surprised to be surprised.
Plus, to me, it appears more like /b/ than reddit. I have a very limited experience in reddit though (yes, those anonymity-driven, fast-flowing communities are interesting).
Github comments are usually on-point, because nobody comments on github-hosted projects unless they're actually working on the project.
The exception is when somebody does a funny commit, and it gets circulated through...you guess it, HN, reddit, etc.
You don't get good discussion from a commenting system. Github's comments aren't designed for with-each-other discussion, they're designed for at-the-author/audience commenting.
HN takes comment quality extremely seriously, and with-each-other discussion is perhaps the main focus.
reddit is somewhere in between: most of the users of reddit don't seem to be interested in discussion, but in open-ended polls a la AskReddit, IAMA, DAE, etc. The fact that reddit threads only last for a few hours, and that the volume of comments is so huge that it's hard to expect the people you're aiming your comment at to get anywhere, these both reward commenting rather than discussion; /r/bestof does as well. That said, reddit's topical breadth draws in lots of smart people, who are usually looking to talk about something interesting.
The vBulletin/phpBB model of forums doesn't really scale too well (unless you go the SomethingAwful route and impose a fee and lots of super-strict moderation) but it works well with up to around 150 active users. The best forums have the highest SnR on the Internet.
4chan-ish anonymity works up to around 5000 before you get chaos, hence the longing for "old /b/" and the value in the other boards.
I also had a friend in school who used to, for whatever reasons, name his files using characters drawn from a pool of only two characters. One being "." the other "*". Please don't ask me why. He would then try to delete some particular file. You can well imagine what would happen next. This happened multiple times, till I went ahead and populated his directories with "-i" files. That worked great.
I usually keep rm aliased to 'rm -i', but once I did get burned. It was not because of hitting return early but because of having a space between a directory and the trailing "/".....while running rm as root. It was taking a bit longer than I had imagined, so I looked again at the prompt to see what had I typed..$#@!&~ :)
Same thing when you forget the WHERE on a DELETE FROM.
http://sql-info.de/mysql/notes/I-am-a-dummy.html
(Of course every effort not to be on the SQL shell of a production server in the first place should be taken, but sometimes you need a sledgehammer and nothing else will work.)
I find I remember to do that because of the direct benefit (getting a sneak preview of what I'm going to delete), but it also means I end up thinking twice about the WHERE statement, so I'm much less likely to miss it out or get it dramatically wrong.
Unfortunately when I was working as a PHP programmer, I once made a typo in a variable name, a variable that had my WHERE clause in DELETE...
Back then I fixed it with a box of chocolates and flowers.
Even if you add the WHERE, but put it on a second line and only run the first, the transaction will help...
Of course, if it's going to lock the data, do all of the statements together: BEGIN TRAN UPDATE ... WHERE ... SELECT ... WHERE .... -- show that the update worked ROLLBACK
Then run the actual statement
Thank goodness for daily backups.
"Only let me update 5 rows at a time." or somesuch.
I now usually type the command out-of-order.
So I'll type:
where user_id = $f00 limit 10;
then prepend the "update foo set bar = " to it...
For starters, DELETE FROM should never be allowed without a WHERE clause. DBs should simply define that as malformed sql.
Good old binary logs and an office floor to sleep on. I make copies of the data whenever deleting or truncating now. I think we all have to do something ridiculously stupid to start taking precautions.
In the time it takes to thump the notepad, it gives my brain a vital few seconds to triple check what I just typed before I blast monkies into space. Saved my behind more than a few times.
And the day you will be ssh'd on another computer, you may forget that you are using a command which is really deleting.
Me, it was the time I rm r'ed the MySQL data directory for my company's customer service management system. Oops. Thankfully we had a backup from the month prior, but I learned two things that day: a) be really careful with rm and b) take it on yourself to make sure IT is backing up stuff that you're messing with.
You gotta hedge against your own stupid.
What about you, how'd you learn the hard way?
I had the Linode backup service, so got away with restoring the whole VM from the previous night's backup.
So, I did a simple /etc/init.d/clearcase stop (not sure that is the exact name) and:
# rm -rf /opt/clearcase
(hmm... that seems to be taking a little too long to run)
Panic - then ctrl-C - it was too late, /opt/clearcase/foo was NFS mounted 127.0.0.1:/ and it had already trashed /bin, /sbin, /etc, /var, and most of /usr.
Luckily I had good backups, but we did spend the rest of the day rebuilding the source repository while the developers couldn't check in any code.
So I merrily started mv-ing things to a scratch directory that we could wipe in 6 months if we didn't need anything from it.
Unfortunately, the zone file directory was NFS mounted from* $dedicated_dns_server. With pass root set.
I think I took all of A through to K of client zones offline before we noticed.
I'm just very very glad I decided to do it as an mv rather than an rm, since it meant all I needed to do was copy things back.
Not that I really learned my lesson that time; it took a couple more semi-disasters before I got sufficiently paranoid to be reasonably safe as root.
rm -rf ./*
I went
rm -rf . (can't get the wildcard thingamajig to show up)
It took me a second to understand why the command was taking so long to run, by the time I figured it out and killed the command, I had wiped out almost half of what was on the drive.
Biggest "oh. my. god" moment of my life. I think I had an actual panic attack for a bit even.
Luckily, media temple had a backup from just a few hours earlier (I was lucky, they only ran them periodically and it just so happened to fall on that day).
You are in .; The current directory listing include ..; Recursively deleting everything deletes everything on the drive.
Actually, I think the one time I saw someone do this, wildcards were involved. And I was going to explain, but the comment system is making my asterisks into bold markers.
My command sequence was more like this though, rather than a straight rm:
Forgot to edit the right side of the pipe back to the grep. Zealous use of the up-arrow burned me...As space has become less valuable on computers, and they have become less of a specialized tool, it may be wise to add one, but most of the desktop environments already implement it already so there is no need to recreate the functionality at a lower level.
I refer you to the original submission.
rm is on the same layer as the DOS del command. Neither goes to the trash can, because they operate on a lower level.
If you're lucky and didn't write too much to the hard-disk after deletion, yes, but with a recycling bin you have much higher chances of recovery.
Regarding `del` in DOS: You're the second one to bring up that analogy. I don't see how this is relevant. Just because Windows does it that way doesn't mean that it's good.
I don't see what's the big deal is. Once in a while when the recycling bin gets too big, the user can empty it. Or you can have a scheduled operation that deletes stuff after 30 days.
Many Linux systems don't even have a regular "user". They just sit in a corner and serve webpages, or do other tasks silently.
> Or you can have a scheduled operation that deletes stuff after 30 days.
Why not just keep backups for 30 days?
Be realistic. Setting up backups takes effort that many users are not going to expand, while the recycling bin mechanism can be set up by default.
ADDED: Note that I have a .trash in each user's home directory including /root. And a copy of the rm script in each user's home/bin.