There are only a few Unix commands that you will need to master to
make it through COS 126. The following is a brief tutorial
covering the most important ones.
Briefly, Unix is an operating system, which means it is a program that
interacts with the hardware (such as
processors, disks, keyboard, mouse) and manages their resources (such
as keeping track of where a file is on a disk). The
operating system you are most familiar is probably Microsoft DOS,
Windows, or Mac OS. Just like
these other operating systems, Unix organizes the files you create and
the application programs you will use.
Unix works at a lower level than Windows. This means that you
will have more control over the machine.
The disadvantage is that it is less user-friendly.
Unix comes
with thousands of commands, most of which you will not need to use in
COS 126.
After following this brief tutorial (about 15 minutes), you will be
acquainted with enough Unix to get you through COS 126.
You enter Unix commands in a terminal window.
The Unix prompt should look something like:
phoenix.Princeton.EDU%
This is where you type commands.
The boldface type below (that follows the Unix prompt) is what you
should type as you work through this tutorial.
The printing and PostScript viewing commands below
assume that you are working in the 101 lab.
Working with Files and Directories
|
Unix organizes files into a directory hierarchy.
A directory can contain both files and other directories.
They are completely analogous to folders in Windows.
Two important abstractions in Unix are standard input and standard
output. By default standard input is your keyboard, and standard
output is your monitor. For example, in Assignment 1, we wrote a
program that read input using scanf and wrote output using printf. To run our
program, the user types the command "trace126"
and enters four integers from the
keyboard. The results appear in the terminal window.
phoenix.Princeton.EDU% trace126
Enter the parameters a, b, c, and M in that order.
11 37 1 100
1 48 65 52 9 36 33 0 37 44 21 68 85 72 29 56 53 20 57 64
41 88 5 92 49 76 73 40 77 84 61 8 25 12 69 96 93 60 97 4
81 28 45 32 89 16 13 80 17 24 1 48 65 52 9 36 33 0 37 44
21 68 85 72 29 56 53 20 57 64 41 88 5 92 49 76 73 40 77 84
61 8 25 12 69 96 93 60 97 4 81 28 45 32 89 16 13 80 17 24
Another useful abstraction in Unix is piping. Piping is when the
output of one program is used as the input of another program.
Writing COS 126 Programs With Emacs
|
A C Program is a text file
(similar
to an .html file) that can be created using any word processor. Emacs is a
powerful word processor specifically designed for writing code. It offers many
features not found in Word or Notepad, including auto-indenting, auto-compiling,
and syntax highlighting.
Written by Jake Brenner and Kevin Wayne.
Copyright © 2000,
Robert Sedgewick