Categories
Archives
Updated : SVN Notifier 1.0.1 | Home | Gaining Insight into Your Zend Queries
Filed under Quick Tips on April 21, 2008 by Matt WilliamsPreventing Accidental File Deletion in Unix
Every seasoned command-line user has at least one horror story involving an accidental file deletion.
Unfortunately, experience won't prevent this from happening again as fingers will still occasionally outrun (or outmaneuver) the preoccupied brain.
One way to defend against this is to use the -i flag with potentially destructive commands such as cp or rm. Even if it were possible, however, to train yourself into this habit 100% of the time, that's 3 extra characters to type with every file manipulation command - not exactly efficient.
The best line of defense is to modify the .bashrc (or .bash_profile) file in your home directory to alias these commands.
alias rm="rm -i"alias cp="cp -i"Great, but...
...deleting a directory containing many files can become a huge annoyance, since the -i flag will prompt you about deleting each file. This is what the less popular -I (uppercase i) flag is for. Unfortunately, this isn't available with every implementation of rm (looking at you OS X!), but if your *nix supports the flag (man rm and look for the flag if you're unsure), you'll get a single prompt when you try to delete a directory using the -r flag asking if you want to recursively delete. If you prefer this (I do) and if your *nix allows it (Debian does), just modify the alias that you just created.
Trackback Pings (TrackBack URL for this entry)
http://www.arc90.com/cgi-bin/mt4/mt-tb.cgi/137.
Updated : SVN Notifier 1.0.1 | Main | Gaining Insight into Your Zend Queries
