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.
  1. 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".
  2. !r. An attempt to repeat a command beginning with r, not realising that the last such command was an rm command.
  3. mv or cp. You forgot you already had a file called "foo", and overwrote it by moving or copying another file to it.
  4. 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.
  5. 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".
  6. 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.
  7. 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.

Log in or registerto write something here or to contact authors.