by Bruce Hamilton <bhami@pobox.com>, 14 November 1995




The answer to "what can I find on the Internet about...?" is nearly

always, "Start with yahoo!"


The Sun Microsystems home page includes the "Sunworld Online"

magazine, and pointers to many other resources.


This USENET newsgroup is a good place to ask relatively

basic questions. There are countless other newsgroups for

more advanced topics, e.g. under comp.sys...



-Prentice-Hall books

Gail Anderson and Paul Anderson, The Unix C Shell Field Guide,

1986, ISBN 0-13-937468-X

This is the book I recommend if you want to sit down and spend a few hours working through and getting comfortable with the csh command line.

-O'Reilly books. O'Reilly is the premier publisher of Unix-related books.

Daniel Gilly et al, Unix in a Nutshell: System V Edition, 1992,

ISBN 1-56592-001-5

This is a handbook, not a tutorial. It serves as a highly condensed version of the online "man" pages, and works best if you already have a working knowledge of Unix.

Paul DuBois, Using csh and tcsh, 1995, ISBN 1-56592-132-1

This is good as a follow-on to Anderson and Anderson. tcsh is a marvelous extension of csh whose highlights include command-line editing (either emacs or vi mode; the arrow keys work for command recall as with "doskey" in DOS).

-Hayden books

Stephen G. Kochan and Patrick H. Wood, Unix Shell Programming:

Revised Edition, 1990, ISBN 0-672-48448-X

The Bourne shell (sh), not csh, should be used for any extensive shell programming (for a huge list of reasons documented in Tom Christiansen's famous essay ftp://convex.convex.com/pub/incoming/csh.whynot ). This Kochan and Wood book is a basic tutorial and reference for sh programming, with an introduction to the Korn shell (ksh) as well.

-IDG books

Simson Garfinkel, Daniel Weise, and Steven Strassmann, eds.,

The Unix-haters Handbook, 1994, ISBN 1-56884-203-1

This is an advanced book. It is written by people who know Unix deeply enough to hate it for the right reasons (of which there are plenty!).



HISTORY: Unix was created 25 years ago at Bell Labs by a small group including Brian Kernaghan and Dennis Ritchie, who also created the C programming language. Its early goals were simplicity and portability. Complex applications could be created by combining simple utilities.

Unix grew quickly because it was made available free to universities. UC Berkeley Unix became widespread on VAX computers in the early '80s, and later on Suns. Implementations of networking (TCP/IP) and windowing (MIT Project Athena's X Windows) were most commonly done on Unix. Unix versions are available for all common platforms, and in recent years free Unix and Unix-clone systems such as Linux have become available on PCs.

DOS half-borrowed a few ideas from Unix (pipes, redirection).

PROBLEMS: "I love standards. There are so many to choose from." Unix has no consistent syntax for command-line arguments or regular expressions. There are often groups of commands that do similar things (e.g. grep, egrep, fgrep).

SHELLS: "shell" is the Unix term for a command interpreter. Common shells include Bourne (sh), C (csh), Korn (ksh), tcsh, and bash. The first three are available on wahoo. csh is the default shell on wahoo. The various shells are very similar, but differ in various advanced features such as command history and command line editing.

FILENAMES: The maximum filename varies on different varieties of modern Unix systems, but is typically something like 128 characters, and so is, for all intents and purposes, unrestricted. Filenames may contain arbitrary characters, but you will have problems trying to reference filenames containing spaces or other unusual characters, so it is advisable to limit filenames to use only the following set of Scharacters: a-zA-Z0-9._-

FILE PERMISSIONS: Unix has a very primitive system of file attributes. For each file, there are three types of access: read, write, and execute, and three categories of permissions: Owner, Group, and World (sometimes called User, Group, and Other, respectively). The "ls -l" command discussed below displays permissions, and "chmod" is used to change them.


. (dot) refers to the current directory, same as in DOS.

.. (two dots) refers to the parent of the current directory, same as in DOS.

/ (forward slash) delimits subdirectories in a fully-qualified filename (in contrast to DOS's backward slash).

COMMAND SYNTAX: Each command line you type to the shell starts with a one-word command name, followed by one or more spaces or tabs, followed by an optional list of switches and arguments which will depend on what command you are running, and terminated by pressing ENTER. Option switches are usually prefixed by a hyphen. By convention, command and filenames are usually lower-case. Unix names are case-sensitive.

THE LOGIN PROCESS: When you first login, if csh is your default shell, then the command file .cshrc in your home directory (if it exists) is executed, followed by the .login command file. As you learn more about Unix, you will encounter other files with the "rc" suffix, which stands for "run command" and usually refers to a file containing commands or parameters used at the start of some program.

ABORTING A COMMAND: If a command hangs, or is producing more output than you want, you can ordinarily abort it simply by typing CTRL-C.

ERASING A LINE: CTRL-U is usually defined to erase the current line being typed.

ERASING A WORD: CTRL-W is often defined to erase the last word typed.

MAKING BACKSPACE WORK: It is likely that your default terminal settings do not make the backspace key erase the last character typed. To fix that for the current login session, type

stty erase BS

where BS indicates pressing the backspace key (followed by ENTER, of course).


[In all the following examples, I use double-quotes ("") to set off commands for readability. The quotes themselves are never typed.]

"pwd" is short for "print working directory". It shows where the system will try to read or write any files if you do not specify another directory as part of the filename. When you first log in, your current directory is your home directory.

"more": The "more" command is used to browse text files. We'll introduce it early because the "man" command uses it to display online help. While displaying a file with "more", the following keystrokes are operative:

q quit back to the shell

<space> display next page

b display previous page

CR display next line

/pattern find next occurrence of string "pattern"

ONLINE HELP: The help command is "man", which is short for "manual pages". "man intro" will give you a list of all the basic built-in Unix commands. "man commandName" for any of the commandNames discussed below will give you far more detail than we have time to discuss here.

In Unix literature, you will often see cryptic-looking notation such as "ls (1)". The number in parentheses simply means that "ls" (in this example) is documented in section 1 of the manual. This notation is useful because sometimes the same name will refer to two distinct things; e.g. to both a user command (section 1) and a system call (section 2).


"ls" lists the files in your current directory. "ls -l" gives a long listing showing permissions, number of names linked to the same file, owner, group, size in bytes, and timestamp when the file was written. "ls -a" or "ls -la" shows "hidden" files as well (i.e. filenames beginning with a dot).

The "chmod" command is used to change file permissions, and is beyond the scope of this introduction. Please read the man page ("man chmod").

"mkdir dirName" creates a directory called dirName.

"cd newDir" changes the current directory to newDir. "cd .." to back out into the parent directory.

"cp oldFile newFile" makes a copy of oldFile and calls the copy newFile.

"mv oldName newName" renames a file. "mv" stands for "move".

"rm fileName" deletes a file. Be careful, because there is no "undelete" built into Unix. ("rm" actually stands for "remove". If there were several names ("links") pointing to one file, "rm" would remove the specified link, but would not actually delete the file until the last link was removed. The "ln" command creates links, and is beyond the scope of this introduction.)

"cat fileName" types the contents of fileName out to the terminal. With multiple argument, "cat" cat be used to combine several files into one. ("cat" is short for "concatenate".)


"du -sk ." summarizes the disk usage in kilobytes (KB) of the current directory.

"df -k ." shows the used and available space in KB for the current filesystem. E.g. if you are in your home directory, it shows how much space is available for your home directory and all the other home directories sharing the same filesystem.

"df -k" summarizes systemwide disk usage for all filesystems. Note that some filesystems such as "/usr/sparta" appear local but are actually on other computers and are mounted over the network using NFS (Network File System).


PATH: If you type a fully-qualified command name such as "/usr/bin/ls", the shell knows exactly where to find the command. But it is much more common to type simply an unqualified name. Your "path" refers to the ordered list of directories in which the shell looks to find a command when you type such an unqualified name. "echo $path" will show you your current path, which is usually specified in your .cshrc file at login time.

HISTORY: Your .cshrc file ordinarily sets a shell variable called "history" to specify how many previous commands to save for possible later reuse. This is a great feature which can save a lot of typing. "echo $history" to see how many commands your shell is currently saving. Type "history" to actually display the list of previous commands.

The C shell has lots of features for recalling previous commands and optionally substituting arguments. See Anderson and Anderson or "man csh" for details. For now, simply note that "!!" repeats the last command, "!$" recalls the final argument of the previous command, "!*" recalls all arguments from the previous command, and !<number> re-executes command <number> from your history list; e.g. !3 would re-execute your command number 3.


If you would like your prompt to show your username, host, current directory, and history number, execute the following commands to (a) back up your current .cshrc, (b) copy my new one, and (c) execute your new one:

cp .cshrc .cshrc.old

cp ~bhamilto/.cshrc.sample .cshrc

source .cshrc

If you don't like the verbose prompt, restore your original .cshrc as follows:

cp .cshrc.old .cshrc

ALIASES: You can save typing long commands by defining your own command aliases. Type "alias" to see what aliases are currently defined. Define a new alias for your current session by doing "alias yourAliasName commandName". This is great for people coming from another operating system. E.g. if you are used to typing "dir" instead of "ls", simply "alias dir ls". If you wish to make an alias permanent, add the alias to your .cshrc using an editor such as "pico".


"finger", "who", and "w" all give slightly different displays of who is logged on and what they are doing. "finger userName" can be used to show when userName was last logged on, even if he or she is not currently logged on. The message "No plan" means that there is no file ".plan" in that user's home directory. If there were, the "finger userName" command would have displayed it. The .plan file is a handy way of letting random people know where you are and what you are doing, should they "finger" you.

"talk userName" can be used to set up a real-time "chat" session between two users. Each user gets half the screen, and each character is echoed in real time (i.e. you even get to see each other's typos). If you see a message indicating someone is trying to set up a "talk" session with you and you want to respond, you should exit any current application such as "pine" and then enter "talk userName", for the appropriate value of userName.


A pipe (indicated by the vertical bar key; shift-backslash on most PCs) is used to string several commands together and send the standard output of the first to the standard input of the next. E.g. to get a sorted list of the people currently logged on, try "w | sort". (The spaces are optional here, but help readability.)

Redirection allows us to direct output to a new file, or append to an existing one. E.g. to save the output of the previous command to a file called "w.txt", type "w | sort > w.txt".

To append to an existing file, we would use >> instead of > . Besides appending command output as above, we can also append terminal input. To append directly from terminal typein to the file w.txt, without using a text editor, we could simple do "cat >> w.txt", type our input, and terminate by typing a CTRL-D at the beginning of a line (indicating end-of-file).


The "grep" command is one of the most valuable, because it allows you to do string searches of large text files and pull out only the lines of interest. I keep a large text file into which I throw phone numbers, e-mail addresses, file locations, you name it, and then run "grep" against it. Sometime a database is overkill!

Simple example: to see if userName is logged on you could type "w | grep userName". (Of course we could also have done "finger userName", which demonstrates a common Unix theme (and the official motto of the Perl scripting language): There's More Than One Way To Do It.)