News for hackers. Stuff that matters.
Re:Man accidentally 'deletes his entire company' with one li... by erik14th on Thursday April 14, 2016 @03:14PM (#11499543)
Is there an alternative to allow scripted destructive actions without the risk of deleting important stuff?

Modern OS's will warn you if you try to delete stuff, but you can still ultimately do it anyway, I don't see it as something particular to UNIX.

The only similar problem I had was on windows, 98 I guess, I deleted all my files that weren't readonly by fiddling with a .bat script.

Re:Man accidentally 'deletes his entire company' with one li... by whitegrape on Thursday April 14, 2016 @04:01PM (#11499877)
Have an immutable filesystem, where "deletes" are recoverable by going back in time. At least until you do a scheduled "actual delete" that will reclaim disk space.

Another option (though last time I tried it, it didn't work..) is something like libtrash: http://pages.stern.nyu.edu/~marriaga/software/libtrash/ Deletes become moves and you can really delete when you like.

Practically speaking, if you're quick an 'rm' isn't totally destructive even without backups. There's a good chance your data is still there on the disk, it's just not associated with anything so it could be overridden at any point. Best to mount the disk read only and crawl through the raw bits to find your lost data (I recovered a week's worth of code this way several years ago).

Re:Man accidentally 'deletes his entire company' with one li... by derekp7 on Thursday April 14, 2016 @04:17PM (#11499990)
My favorite answer to the common interview question: "What was your biggest mistake, and how did you recover from it?" Answer: Back in 1993, I once deleted a critical data file. Fortunately, the AIX host was sitting next to me, so I quickly reached over and flipped the power switch off. The strategy being: writes were buffered and flushed out periodically, so hitting the power switch prevented that last write from hitting the disk. And if this didn't work (and caused more file system corruption), well I would have needed to restore from backup anyway.
Re:Man accidentally 'deletes his entire company' with one li... by nickpsecurity on Thursday April 14, 2016 @08:14PM (#11501220)
That's great. Straight out of an NCIS episode except it actually makes sense this time. :)
Re:Man accidentally 'deletes his entire company' with one li... by toomuchtodo on Thursday April 14, 2016 @04:08PM (#11499933)
> At least until you do a scheduled "actual delete" that will reclaim disk space.

And then you "actual delete" is where the data loss occurs :D

Re:Man accidentally 'deletes his entire company' with one li... by Avshalom on Thursday April 14, 2016 @04:20PM (#11500020)
Right but if you delete your entire file system there won't be anything to come along and do the "actual delete" so you're safe until some one comes along with a rescue disk or otherwise mounts it to a system that knows how to deal with this.

At the very least when you rm important-file.txt instead of importanr-file.txt you have a chance.

Re:Man accidentally 'deletes his entire company' with one li... by wruza on Sunday April 17, 2016 @02:09PM (#11515523)
Pre-delete would already hide files from apps and services for them to "fail fast", and actual delete would be just "i'm running fine for two days". Of course this implies that active open files should not be pre-deleted on unix at all (at least not by rm process). Even if you delete the entire filesystem with backups, there will be a chance to boot into recovery mode and undelete everything back. We can even go further and apply small-file-versioning on fs level to prevent misconfig accidents in /etc.

That's very simple and powerful, I can't tell why it is still not implemented today.

Re:Man accidentally 'deletes his entire company' with one li... by Avshalom on Thursday April 14, 2016 @03:35PM (#11499698)
well there's some safe guard checks you can do to prevent the easy abuses like require an additional flag for rm -rf-ing everything in the root or /home/*/, or across device boundaries as some one said.

You can redesign rm so people don't find themselves typing -rf as force of habit.

You can have multiple delete commands: mark as overwriteable if need and remove from 'ls -a', actually delete, overwrite sectors with zeros; like we have in guis.

You can have a permission system that isn't just "this account can do literally anything" or "this account can't do anything"

Re:Man accidentally 'deletes his entire company' with one li... by Avshalom on Thursday April 14, 2016 @04:03PM (#11499894)
here's a dumb idea off the top of my head: /etc/rmblacklist.conf autopopulated (by the distro) with a list of files (/boot and the actual bootimage for instance) that requires a GNU style long option --nuke to delete. It's still easily scriptable but you'd rarely ever actually need it and requiring a long option would serve as a double check that you meant it when you did.

Sure it's still possible to --nuke something due to a bug or negligence but I bet it'd cut down on fatal errors. Plus the user could have their own ~/.rmblacklist.conf to guard against particularly persistent dyslexias.

You could even erase the contents entirely if you really think being able to delete root on a whim keeps your kung fu strong.

Re:Man accidentally 'deletes his entire company' with one li... by nickpsecurity on Thursday April 14, 2016 @08:30PM (#11501279)
Good to see you fighting the fight with many sensible ideas. I've been posting this one in most responses as it's pretty simple:

https://launchpad.net/safe-rm

Re:Man accidentally 'deletes his entire company' with one li... by Avshalom on Thursday April 14, 2016 @09:37PM (#11501507)
Hah! Beat me to the punch by 5 years.
Re:Man accidentally 'deletes his entire company' with one li... by nickpsecurity on Thursday April 14, 2016 @10:14PM (#11501630)
Darn, I didnt notice it was that old. Makes situation even worse for UNIX rm defenders. Like when Trusted Xenix eliminated setuid vuln's mostly by clearing setuid bit during a write w/ admin having to manually reset it. Simple shit. Mainstream response? "Just audit all your apps for setuid and be extra careful in..." (sighs)
Re:Man accidentally 'deletes his entire company' with one li... by Tiksi on Thursday April 14, 2016 @10:14PM (#11501632)
You could just make the file immutable and read only:

http://paste.click/qMpmyO

Then remove the immutable flag if needed

Re:Man accidentally 'deletes his entire company' with one li... by justinlardinois on Thursday April 14, 2016 @08:04PM (#11501178)
This isn't a bad idea.
Re:Man accidentally 'deletes his entire company' with one li... by nickpsecurity on Thursday April 14, 2016 @08:30PM (#11501276)
https://launchpad.net/safe-rm

Use something like that with scripting. It really is that easy to protect critical stuff with otherwise easy-to-use rm. UNIX has always been resistant to do stuff like this. However, it's architecture makes it fairly easy for developers to do it themselves. That's to its credit.

Re:Man accidentally 'deletes his entire company' with one li... by blakeyrat on Thursday April 14, 2016 @04:28PM (#11500073)
There's no reason the Recycle Bin couldn't work for scripting languages, except for lazy OS and language developers haven't bothered to wire-it-up.