Thursday, December 28, 2006

Essential Commands

One of the great difficulties in getting people to learn Linux, or any Unix-like system, is that they think they will have difficulty running programs from the command line. This despite that fact that all computer users of a certain age started out with nothing but the command line — even DOS, after all, was run from a (not-quite) Unix-like shell.

I thought a good way to overcome this phobia would be to list a few of the essential commands needed to operate a Unix shell. Then I started writing. When I got up to one screen per command and hadn't even gotten past the fifth command I decided to stop, cheat, and reference someone else:

Some Basic UNIX Commands by Donald Hyatt. This is a nice list. I only want to add one more command at the moment, though others are free to add more in the comments:

The find command:

Someplace, some time ago, you created a document about the 1985 World Series. You've forgotten exactly where you saved the file, but you're pretty sure the title was something like "The Denkinger Disaster." You might have saved it in Word, Abiword, or format. So how do you find the file?

Enter the find command. Given that you're obviously a Cardinals fan, the key word in the title is probably Denkinger. A brief visit to the find man page, and a little bit of knowledge of regular expressions, tells you that the proper command is:

find $HOME -name "*[Dd][Ee][Nn][Kk]*" -type f

which means, "Starting in my $HOME directory and looking in all its subdirectories, look for an ordinary (non-directory) file ('-type f') that has one of the strings DENK, denk, DeNK, DenK, ... in the name. ([] means match any of the characters in the brackets, and the '*' are wildcard symbols.)"

If you have such a file, the find command will print out its location.

I'd give you an example here, but I'm a Royals fan, so no such file exists on my machine.