Ooops.
github.com
github.com
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.
(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.
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.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...
BEGIN TRAN
DELETE FROM ...
SELECT FROM ...
ROLLBACK TRAN -- things look bad, itchy finger, etc
COMMIT TRAN -- things look good, skip previous line
That, and I have 15-minute backups for all databases I care about.For starters, DELETE FROM should never be allowed without a WHERE clause. DBs should simply define that as malformed sql.
touch -- --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.
$ ls | wc -l
5
$ rm * -i
rm: -i: No such file or directory
$ ls | wc -l
0In 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.
rm -rf /usr /lib/nvidia-current/xorg/xorg # KABOOM!
rm -rf "/usr /lib/nvidia-current/xorg/xorg" # Harmless.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.
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.
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?
sudo chown -R username:group $WEBAPP
For various reasons, $WEBAPP got set to "/ usr/local/blah/blah" (note the space)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.
rm -rf ./*
rm -rf *.*
To stay on topic, because of this thread, I just added alias rm="rm -I" to .bashrc, and I have never yet needed -f.This wouldn't delete the correct directory, but at least it won't delete "/usr" either:
rm -rf "/usr /lib/nvidia-current/xorg/xorg"
There are lots of other pitfalls associated with not quoting things in shell scripts, like this common one: if [ $foo -eq "bar" ];
will cause an error if $foo isn't set or is an empty string, while this will work correctly: if [ "$foo" -eq "bar" ];
Bonus that your syntax highlighter can highlight the arguments. My rule is that flags aren't quoted, but paths and other parameters are. 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.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 ;)
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."
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.
... and the first reporter to try software, for reasons I'll never totally understand, chose to install it in C:\. Worked great until he went to uninstall it.
At the time, the main thing hosted on that machine was my WoW guild's website, which I had been working on for close to a year, and was beginning work on converting the site over to a general purpose guild hosting site.
I was doing some work for a client, setting up a mirror of sorts for some kind of yearbook thing I had built for them. For that, I made a script that would mirror the online yearbook with wget, zip up the whole directory, then clear out the mirrored pages (all I cared to store and serve was the zip file).
All of my websites were stored in /www on the server, and the raw yearbook was located at /www/clientname/www. Inside the clientname directory, I had the mirror script which was something like this:
wget -whatever_options http://whatever.address www
zip yearbook.zip www
rm -fr /www
Unfortunately, because of how frequently I type / before www to get to my web dev directory, I instinctively put "/www" in the script where I just wanted to do "www". I ran the script, checked to make sure and it looked good, and deployed it to a cronjob.My heart sank when I tried loading my guild page a few minutes later (just to see what was going on on the forum, if anything), and it served up a bunch of 404s.
I went to /www/guildsite and saw it completely empty, and almost immediately figured out what had happened. At that point, I had to get my composure and figure out what I was going to do (I did not have backups or source control). I unmounted the directory, and went off to lunch with a friend, shaking with anxiety.
Upon return, I started writing out a perl script to scour the device byte for byte looking for PHP scripts, looking for instances of <? and then capturing the following 2000 lines or so, assuming that would be a sufficient buffer. When the script was done, I set it to run on the partition, and 45 minutes later I had a few hundred files to work with.
I had to manually go through every file (which were named numerically in the order they were found in the filesystem) and determine if it was the most recent (or recent enough) copy of the code, clear off any trailing bytes, and rename it to the filename it used to have. Luckily I could remember the name of almost every file in the system. It took about 8 hours to go through the few hundred files and recover them.
Needless to say, I learned my lesson after that, but the feeling of victory I got from recovering those files from the device was epic.
6 years later, I realize that that's a rather trivial thing to do, but at the time, I didn't know what I was going to do, and remembering that the file system doesn't clear all the bytes of the a file just it's reference gave me tons of hope.
Ha - I'll bet everybody here has a story that starts like that. (Although your heroic save was heroic!)
My sad delete story was in 1982 - I had a fantastic graphical robot-vs.-robot game stored on tape on an HP portable computer (I was in high school). For some reason, the delete command on the HP had a variant that deleted from a given block forward on the tape, as I recall, and for some other reason, my fingers just decided to type that variant even though I had never done it before.
I still miss that game. It just may have grown in my memory, but I'm pretty sure that was the coolest piece of software ever written anywhere at any time.
Hah! I literally (not figuratively) laughed for a minute at that. I'm still smiling a few minutes later. Well played.
Let's mourn together at the memories of long lost code.
I'll drink to that.
Having to explain what I'd done to the boss was so scary, I slunk home with the drive and traced the power circuit with my oscilloscope until I found a capacitor that had blown short. I soldered on a through-hole replacement and it worked!
I pulled the data and felt like king of the whole frikkin world for the next week or so.
yep this could cause you to lose a job.
> Having to explain what I'd done to the boss was so scary, I slunk home with the drive and traced the power circuit with my oscilloscope until I found a capacitor that had blown short. I soldered on a through-hole replacement and it worked!
pulling this off, however, could land you a job!
lesson: mistakes are human. talent and initiative are rare.
While yes technology is getting smaller I have found that with many parts I can now easily find replacements online, I can get advice from other professionals, I can easily figure out how something works so that I can fix it. I've currently got a power supply sitting on my work bench that has a weird issue and I am slowly going through, making a net list and building a schematic with part numbers in an attempt to isolate the fault.
Maybe I am a rare breed, but seeing as how the interest at Maker Faire keeps going up, and interest in electronics also keep going up I will assume that eventually more and more people will get into experimenting in this field.
At least that is my hope.
That's the feeling. It's almost euphoric. It's the "FUCK YEA" meme (http://knowyourmeme.com/memes/fck-yea).
In actual content, it's convenient that you had timestamps to work with. That eliminates a lot of the need to trim off trailing bytes. Kudos to you for the epic save, and on a live (mounted?) disk too? Living dangerously :)
There’s an important motto to bear in mind here: data you haven’t backed up is data you don’t want. To be fair, this does bite us all at one point or another, but once it’s got you once you make damn sure it doesn’t get you twice.
Also, these days I get shaky just doing FTP deploys. Give me capistrano and git, or even better a direct Heroku push any day of the week.
I rebuilt the partition table and saved all of our backups.
It was laziness, nothing more, and I got burnt playing with fire.
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...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.
http://packages.debian.org/sid/molly-guard
which prevents you from running halt/shutdown etc. via SSH without first confirming the hostname.
I've done that before with pretty traumatic consequences, so it's now on my list of must-have's for any important remote box.
(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.
I forgive them.
And the day you will be ssh'd on another computer, you may forget that you are using a command which is really deleting.
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.
alias rmmmmmmmmmmmmmmmmmmmmmm='rm -i'
rm() { D="~/.Trash/`date +%s.%N`"; mkdir -p $D; mv "$@" $D; }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.
rm -- -r -f # removes files -r and -fI once had a script something like this:
mksquashfs /usr /squashed/usr/usr_tmp.sfs -b 65536
umount -l /usr
umount -l /squashed/usr/ro
rm /squashed/usr/usr.sfs
mv /squashed/usr/usr_tmp.sfs /squashed/usr/usr.sfs
rm -rf /squashed/usr/rw/*
mount /squashed/usr/ro
mount /usr
Guess what happens if you hit Ctrl-C during the mksquashfs? That's right, bash runs all the rest too, including the deletion of the old squashfs file. I was left without a /usr, and it was brutal. Managed to recover (it's incredible how resilient a linux system is, as long as /bin and /lib are intact), and immediately put "set -e" in almost every bash script on my machine (I also fixed the script to keep the system in a recoverable state at all times...).Myself, I use TimeMachine and bitbucket on my Mac, and every-15-minutes snapshots on all Amazon EC2 EBS volumes. Similar solutions can certainly be found for your platform of choice.
"Usability? What's that? I'm really smart, so I don't make mistakes. If lesser humans do - that's their problem". That seems to be the attitude of many Linux programs and rm is among the worst of them. No doubt I'll get downvoted for saying this, but I've rarely, if ever, heard of such things happening in Windows. (And people still manage to delete files in Windows without too much difficulty.)
1. find . -name "pattern" <enter> <look carefully> <up arrow> | sudo xargs rm -f
2. WHERE some_id = 36; <home> DELETE FROM table_name
It could be something as simple as a file with paths on each line it - match one path or a path with a glob - and the script fails before destroying anything important.
Overriding it might involve adding a --override=/path/to/something but at least then it would be very explicit
Great minds etc :)
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.
# rm -rf /path/to/^IAnyway, it accidentally removed rm-rf'ed /, I only discovered it in time because it gave errors about removing nodes in /proc...
Is there no way to prevent bugs like this at the source, by modifying Linux, rather than hoping there isn't any extra white space in a command that might delete your usr directory?
rsync -a --delete /home/project/ /mnt/backupDisk
Left unnecessary slash after "project" and rewrite all content on "backupDisk" by project files (instead of sync project folder on it)
on the other hand, delete the boot.ini[1] and most windows systems cant even boot. now deploy that boot.ini deleting build on an MMO (eve online) and watch the fur fly. that, ladies and gentlemen, is how you earn a :golfclap:.
The home directory is the full path to a directory on the system in
which the user will start when logging on to the system. A common
convention is to put all user home directories under /home/username
or /usr/home/username. The user would store their personal
files in their home directory, and any directories they may create
in there.
All of my irreplaceable data is stored in `/usr'. `/home' is a symlink to `/usr/home', as created by the installer.an RPM I had at one point had / as one of its trees. There's a reason I moved to debian.
I was working on some file saving logic. A customer had a problem where they'd overlaid a new logical file on top of an old logical file. Where these actual files, this would just have overwritten the old file, but since these were directories, we got a mishmash of pieces of two different logical files overlaid in the same directory, and of course our software got confused as hell. So, I wrote code that, in case you saved a new file as an extent filename (really directory name), would perform the equivalent of
rm -rf $dirname; mkdir $dirname;
You can see where this is going... Some grad student didn't understand this, and named a pseudo file as the root directory of a tree of research. Two years of research vanished into the ether, despite a dialog box that had red text in it. That sucked. long jmp();
longjmp(); EAR LYTOB EDEAR LYTOR ISEM AKE SAM ANHEAL THYWEAL THYAN DWISEM
Ihaveactuallyprogrammedinlanguagesthatdisregardedwhitespacee ntirely.OldversionsofMicrosoftBASICforexampleusedaonelevelpa rserwhichdidnothaveaseparatetokenizer.Fortranalsoignoredwhit espace(asidefromthewhitespaceneededtogetyourcodeintotheright columnonthecard!)withtheunfortunateeffectthatthesetwostateme ntswereequivalent: do 20 i = 1. 10
do20i = 1.10
Thefirstoneisanobvioustypoofthefollowing: do 20 i = 1, 10
Which,ifmymemorydoesnotfailme,istheoldFortranwayofwriting for (i = 1; i <= 10; i++) {
withline20beingthecorresponding"}".¶Ihopethiscommenthasbeenh elpfulinunderstandingwhySteveBournethoughtmakingwhitespacesi gnificantinhislanguagedesignwasagoodidea!