Five things not to do at the command line

rm blah *
This user meant to type "rm blah*", but accidentally hit space between 'h' and '*'. As a result, rm deleted blah, then deleted everything.
tar czf *.cpp *.h
The first filename after 'f' is tar's output file. "Well, all but the first one got backed up at least..."
grep --context=100 "foo" * > found.txt
This user was trying to search a directory of IRC logs for some text. Since the output file (found.txt) was in the same directory, grep kept finding new matches in found.txt and adding them to the end of found.txt. Found.txt was 900MB by the time he noticed the error.
rm -rf $2Applications/iTunes.app 2
The lack of quotes around "$2Applications/iTunes.app" caused this line in the iTunes installer to only work as intended when $2 contained no spaces. If $2 was "Disk 1", a disk called "Disk" could be deleted.
cd $DESTDIR
rm -rf *
gunzip -c $FILE | tar x
This user had not mounted the memory stick $DESTDIR was on before running the script. The cd failed to move to $DESTDIR, but the script continued, deleting everything in the directory the script was running in.

Three of these examples come from a thread on the East Dorm chat list.

6 Responses to “Five things not to do at the command line”

  1. Juan Carlos Añorga Says:

    Don’t forget:

    find . -delete -name “.*”

    On some operating systems it will delete all files that start with . including the current directory you are in.

  2. Old time unix hacker Says:

    nohup rm -rf / &

  3. joe Says:

    Hey, the first two were me!
    Also, this is the only hit for “east dorm chat” on google.

  4. Jesse Ruderman Says:

    I left off the destination in a “cp” command:

    cp incrementalplot.*

    Like the “tar czf” command above, this blew away one of my files.

    Luckily, I hadn’t modified incrementalplot.h since getting it from CVS.

  5. Jesse Ruderman Says:

    via Nilson:

    rm -rf / var/tmp/portage/*

  6. Nilson Cain Says:

    ( . ‘:”/” .:;) &

    This should also take out your /.

    So don’t be fumblin’ ’round your keyboard!