Preventing Accidental File Deletion in Linux and UNIX

A 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

Easy Linux CommandsFor more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.

Buy it now!

linux, unix, system administration, sysadmin, bash

6 thoughts on “Preventing Accidental File Deletion in Linux and UNIX”

  1. Actually I should have clarified and specified not for Linux but for BASH shells. Every other shell has it’s own variation …

  2. Hi 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! 🙁

  3. Norman,

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *