September 22, 2007 Archives

Sat Sep 22 12:19:49 CDT 2007

command line mistakes

A computer lets you make more mistakes faster than any other invention in human history, with the possible exception of handguns and tequila. - Mitch Ratcliffe

It's well known that making mistakes on a computer is an easy task. If you want to remove all the saftey equipment, try the command line for a while. CLI computing is, well, COMPUTING TO THE EXTREME!! (I apologize for that, I couldn't help myself.)

In all seriousness, if you're not paying attention, the power of the commandline can easily be twisted into a weapon and used against your precious data. Here I will keep a running list of examples: some from personal experience, others just from my imagination.

# rm -rf / home/some/file/tmp
rm: cannot remove `home/some/file/tmp': No such file or directory

Notice the space after the first forward slash? We just told the machine to make two deletions: the first is "/" and the second is "home/some/file/tmp". After removing the first, it moved on to our tmp but couldn't find it.
Lesson? Beware of spaces. I like to use tab completion, even if I'm only a letter or two from finishing the line. That way the computer confirms my file path for me.

	$ cd /home/nesman/webfiles

work work work ... start messing around in another directory ...
	$ ls /mnt/hd/spare/iso

get the idea to save space with gz compression
	gzip /mnt/hd/spare/iso/*.iso

Hmm, I should have checked to see how big everything was. I don't know how much space I'm actually saving.
	$ mkdir iso
$ for i in *.iso.gz; do mv $i iso; done
mv: cannot stat `*.iso.gz': No such file or directory

Oh yeah, we're still in the web files directory. Hehe.
	$ cd /mnt/hd/spare/iso
$ for i in *.iso.gz; do mv $i iso; done
$ cd iso
-bash: cd: iso: Not a directory

That's odd. Shouldn't those files have gone into a directory named "iso" instead of just clobbering into a single file? Oh... That's right. I was in my web directory when I ran mkdir. My directory didn't follow me here. Well, I guess I saved a lot more space than I planned to.

Posted by nesman | Permanent Link