Archive for August, 2003

Five things not to do at the command line

Thursday, August 7th, 2003
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.