Preventing Accidental File Deletion in Linux and UNIX
Categories: Information Technology, System Administration, UNIXA little trick that some Linux users like to implement to prevent accidental file deletion is via the use of an alias. Aliases are similar to variables and can either be set in a session or by placing the alias command in the .profile or .bash_profile file with a text editor.
By adding this alias the user will be prompted to confirm each file before it is deleted; otherwise Linux, unlike Microsoft Windows, will delete whatever files match the filename criteria without warning!
$ alias rm='rm -i'
$ touch touch1.fil touch2.fil touch3.fil
$ rm touch*
rm: remove regular empty file `touch1.fil'? y
rm: remove regular empty file `touch2.fil'? y
rm: remove regular empty file `touch3.fil'? y
For more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.Buy it now!
6 Responses to “Preventing Accidental File Deletion in Linux and UNIX”
-
al Says:
November 14th, 2006 at 9:46 pmOr do it globally on a Linux system in /etc/profile
-
Jon Emmons Says:
November 15th, 2006 at 9:41 amGood point Al. That should work on most other UNIX and UNIX-like platforms as well.
-
al Says:
November 15th, 2006 at 4:13 pmActually I should have clarified and specified not for Linux but for BASH shells. Every other shell has it’s own variation …
-
Jon Emmons Says:
November 15th, 2006 at 4:53 pmIt works for bash, Bourne and Korn shells. Possibly some others, but not csh or tcsh.
-
Norman Molhant Says:
May 24th, 2007 at 8:16 pmHi Al! Do you know a simple way to recursively find and remove all bad soft links (soft links to deleted/moved/unexistant files, for instance) from a directory? I’m still doing it by hand, halas!
-
Jon Emmons Says:
May 27th, 2007 at 10:56 amNorman,
Finding the symbolic links seems to be fairly easy. You can use “find ./ -type l” to find all symbolic links, but testing them is another story. I don’t see any really easy way to do that.
Hope this helps. If I think of a way to test it I’ll let you know.
