UNIX Basics
The following is in part lifted from the tutorial in Chapter 2 of Glass.
Some UNIX philosophy
You will almost certainly find UNIX cryptic, using very short and often incomprehensible abbreviations
for complicated commands. UNIX was developed as an environment/operating system for experienced
programmers who were used to short abbreviations from working with assembly language, and who felt
that short command sequences were preferable to more comprehensible but longer sequences.
Unfortunately, this makes the learning curve very steep.
Some conventions
It is important to remember that UNIX is case-sensitive. That is, it will matter whether you type
“echo”, or “ECHO”, or “Echo”, or “EcHo” --- all of these are different, and you must use the
case indicated.
In these notes, I will use angle brackets --- < > --- in places where what I use is not what you should
type, but a placeholder for what you should type, so, for example, < filename> stands for the
name of the file you are interested in.
Getting started
Logging in
While the log-in process may possibly differ on different systems (particularly systems running UNIX
lookalikes), and your first log-in may invoke some system bookkeeping, the basic process is the same:
You will see a prompt:
login:
after which you should type your user name (note, do not retype the word “login”, as is required for the
SHU network) and press Enter. You should then see the prompt:
password:
You should type your password [Warning: it will not appear on the screen.] and then press Enter.
Thereafter, you will be in a shell, and you will see a prompt, such as $, # or > .
Shells and the kernel
The UNIX kernel provides the basic functionality of the operating system. However, most of the
functionality we actually use is provided by a shell. There are several shells, of which the C-
shell, the Bourne shell, and the Korn shell are common. Glass mostly uses the Korn shell, while I will
stick mostly to the C-shell.
Many UNIX commands are really utilities provided by the shell, and many of these are common
across all of the shells.
passwd
If this is your first log-on (or periodically on some systems), the system may ask you to change your
password. You can also do this on your own. If the system is not leading you through the process, you
can start the process by typing
passwd
at the prompt. The system will then ask you to type your old password (to make sure you’re you), and
then to type your new password twice (the second time basically to make sure you didn’t misspell the first
time --- this could be disastrous).
Running a utility
At the prompt, type
date
and press Enter.
The most useful commands in UNIX
The single most useful commands in UNIX invoke the help facility. However, the entire file will run
through the screen without stopping. To make the file display one screen at a time, we will use
more.
more < filename>
will display the file one screen at a time. To see more screens of information, just press Space. To quit
scrolling through the file, press q.
To view the results of another command with more, we “pipe” the results through more,
as in DOS:
man passwd | more.
There are basically two commands:
- The man command takes the name of a command, and returns a description of the
command.
- Type man passwd at the prompt. If the output takes more than one screen, repeat, typing
man passwd | more
- The apropos command (or the command man -k ) takes a term, and returns a list of
the commands that have something to do with the term.
- Type apropos password | more at the prompt.
To save the results of a command in a file, we use a redirect character:
man passwd > passwd.out
will save the “man page” in a file passwd.out instead of displaying it on the screen. You can then
display the file as often as you like using
more passwd.out
Flags on commands
Most UNIX commands allow (and some require) options. Options are almost always specified with a
minus sign followed by a symbol, possibly followed by text. For example, the man -k command
above is the “apropos” option of the man command. For another example, lpr is the
print command. To specify a given printer, use lpr -P< printer name> followed by a list of
things to print. Other lpr flags control single-sided versus double-sided printing, number of
copies to print, printing lengthwise or sideways, and so on.
- Listing files
- Options on the ls command
- Creating and removing directories
- Changing directories
- Specifying paths
- Creating files
- Moving files around: mv, cp, rm
- File protection: chmod, groups, chgrp, chown
- Printing files: lpr, lpq, lprm
Miscellaneous
Some Useful Utilities
- clear
will clear the screen. Some terminal emulators may leave garbage on the screen; this
will eliminate it. Control-L may work in some cases.
- wc < filename>
will give the count of lines, words, and characters in < filename>
.
- file < filename>
describes (the system’s best guess as to) the attributes of <
filename> .
Logging Out
Type logout or exit. logout will log you out even if you are in a subshell; exit
closes only the most recently opened foreground shell. Most UNIX users prefer using exit;
otherwise, any pending work in open shells may be discarded. Control-D will work if
ignoreof is not set.