CS50 UNIX Review Notes

Working with UNIX

The best way to learn the fundamentals of UNIX is to try things- get a copy of Learning the UNIX Operating System, log on to one of the HP UNIX machines (such as course1), and work through some of the examples and exercises.

Basic UNIX Commands

Most of these programs are standard UNIX utilities, and are described in the the Learning the UNIX Operating System text. If you are new to UNIX, I strongly recommend that you buy this text and work your way through it. The elm and pine mail programs, on the other hand, are not standard UNIX utilities, but are very common. These programs are documented in the online manual pages, and other texts.

A few of the programs that you'll use, such as checkin, and checkout, were written specifically for this course. To learn about these programs, consult the online manual pages and the course handouts.

The good news is that once you are familiar with these commands, you will have learned most of the UNIX commands that you really need to know for this course. We're not going to make you learn a dozen new UNIX commands every week (instead, we'll soon move on to the real goal of this course- learning Computer Science). However, it is necessary to learn the basic skills of using these computers in order to progress on to bigger and better things.

vi Tips and Tricks

If you've been using vi then you should be familiar with the basic commands by now. There are tons of commands, however, so you're probably just scratching the surface (unless you've bought the vi book and memorized it already).

vi Miscellany

The tag operations of vi are very handy when writing (or debugging) programs that span several files. To use this feature, run the program ctags on all of your .c files in your beanie directory, i.e.

	ctags *.c
This program will create a new file named tags in your current directory, which contains information about where each of the functions in your program are located. Once you've got this info, vi can use it with the tag command. This command is used to jump to the definition of a function. For example, imagine that you have a function foo somewhere in your program. To look at the definition of foo, simply execute the vi command :tag foo and vi will open the appropriate file and move the cursor to the beginning of the function.

Note that you'll need to rerun the ctags program each time you make any major changes to your code (i.e. every time you add a function, or change the arguments to a function) if you want the tags to be up to date for the corresponding functions.

As usual, see the man page for ctags for more information.

UNIX Mysteries

UNIX Utilities


The spell program is the original spell checker for UNIX. It makes it easy to check your text files (such as the answers to your written exercises) for spelling errors. See the manual page for more information.


UNIX also includes a tool named adjust, which helps to format text so that it looks good on the screen or printed page. The manual page for adjust includes instructions for running it from inside vi.


The indent reformats C programs into a ``standard'' form. Most people don't personally prefer the standard form (which is one reason why this command has so many options) but nearly everyone agrees that this tool is very useful for cleaning up ugly C code.

Different people use different styles, and most are readable. However, someone may someday hand you a piece of code that is indented in a hideous manner, and rather than waste time reformatting it, you can use this tool. Remember to always checkin code before using indent, just in case you change your mind!

My favorite options are:

		-cd41 -i8 -d-1 -br
Note- indent is only for C. If you run MIPS assembly language files through indent, it will be very, very confused.

Please bring any errors or inconsistencies in this document to the attention of the author.

Dan Ellard - (ellard@deas.harvard.edu)