Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

First of all, the whole point of the "-f" option is to disable confirmation, which really means "I know exactly what I'm doing". The easiest fix is to stop using that option all the damned time.

When you have strong permissions (e.g. running as "root"), you should never use patterns in destructive commands, period.

At best, you should perform a nondestructive pattern command such as a "find" and generate a precise list of target files that can be audited. For example, here is one way to produce a script of commands that deletes an exact list of matching files:

    find * | awk '{print "rm \047"$0"\047"}' > delete.sh && chmod +x delete.sh


Better yet: don't remove things. Move them to a folder. My rm is aliased to a 'mv to a trahs folder' function. I have aliased rrm for real rm.

Guis know this, but somehow this piece of UX is forgotten on command line tools.


It's really more effective to have a very regular backup (e.g. ".snapshot" directories are really nice), because you can't control all the ways a file may be deleted.

Just because you protect one "rm" command doesn't mean there isn't another. Someone might have used unlink() in a Perl script or a C program. Maybe "mv" was used to write one file over another, or "cat >! filename", or a dozen other things.

In the end, if a file needs to be safe then it needs a backup (and the sooner it can be restored, the better). And then given a good backup the file still needs an appropriate Unix group, owner, file access control list, etc. to minimize the chance that you'll ever need the backup.


Note that 'sudo rm' doesn't care about your aliases. It would be safer to replace the binary.


Cool idea. I usually move folders and files to the /tmp/ folder instead of deleting them. The next time I boot up, they are gone.


The problem with using /tmp is that you may not realize something critical has been deleted until you reboot. Using an explicit trash or backups folder is safer.


> somehow this piece of UX is forgotten on command line tools

Because command line tools were first, and are used by people who do need to remove files, to clear disk space.

If you're never deleting anything, how do you clear disk space?


Use a script to alias rm to a mv command. Then to really delete something explicitly use /bin/rm.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: