The
Unix-Haters Handbook describes how easy it is to
lose files under
Unix. Although I have not yet lost a vitally important
file, I know that there are many ways to
delete a file accidentally. Here are seven that I can think of - if you know of any more,
including on operating systems other than Unix, node them here.
- rm. The classic irreversible delete command. Problems arise when you run "rm *" in the wrong directory, or (if you're
root) "rm -r /bin" by mistake for "rm -r ./bin". To avoid this problem, and the next two, you can alias "rm" to "rm -i", "cp" to "cp -i", and "mv" to "mv -i".
- !r. An attempt to repeat a command beginning with r, not realising that the last such command was an rm command.
- mv or cp. You forgot you already had a file called "foo", and overwrote it by moving or copying another file to it.
- tar. The command to unpack a tar archive is "tar xvf archive.tar". A simple typo changes this to "tar cvf archive.tar",
which tries to create an archive of no files, ruining your tar file.
- Output redirection. You redirect output to the wrong file, perhaps as a typo for redirecting input from this file. The tcsh and bash
shells protect you against this if you use "set noclobber".
- The compiler. If you do "gcc -o foo.c foo" instead of "gcc -o foo foo.c", and foo already exists, you will lose foo.c.
- Running out of disk space. I once lost a file this way - the disk was full, so when emacs tried to save my file it truncated
it to nothingness instead, and then I VERY foolishly exited emacs. To avoid this, pay attention to the error messages emacs gives you when attempting to save your file.