next up previous contents
Next: Security Up: No Title Previous: Files

UNIX miscellany

Usernames

You identify yourself to the operating system with your username. Normally your username will be your initials, and it must be entered in lowercase. To find out who is logged onto the computer, use one of the commands u, w, who, wh or finger (which can be abbreviated to f). To find out who is logged on to a remote computer, use finger as in the following example:

f @usage.csd
f @aardvark.harvard.edu
To change the information displayed by finger for your username, use the chfn command. However, please do not alter the name that finger displays to something stupid since it inconveniences other users who may need to speak with you if, for example, you have a tape drive allocated.

Non-standard features of our UNIX

There are several non-standard features of the local implementation of UNIX on the School workstation that you should be aware of. The most important ones are:

If you don't like the way these commands have been aliased, then you are free to change them in your .cshrc file. You should also have a close look at the .login, /usr/local/.cshrc, and /usr/local/.login files. Note, however, that if you elect not to run the system default .cshrc and .login files then you will get no sympathy if you have problems (e.g., if the local directory for TeX\ changes).

Control characters

In similar fashion to other operating systems, UNIX interprets some control characters that you type in a special way. Here is a list of the default settings. You can change some of these using the stty command, and you can print out a list of the current settings using stty -a. There are also many special control sequences which you can use to edit command lines, see man tcsh for a complete list.

tabular429

Miscellaneous useful commands

tabular449

What is a shell?

  UNIX manuals quite often talk about the ``shell'', and it sounds like some sort of mysterious entity. It isn't really. The ``shell'' is simply the program that you are running when you are entering UNIX commands. Normally you think of computers running programs such as big FORTRAN packages, however, even when the computer is not running one of your programs it is still running something (otherwise it wouldn't be able to communicate with you). This program is called the shell. On other computers it is sometimes called ``the operating system'', although there is more to the UNIX operating system than just the shell.

UNIX gives you a number of different shells to choose from. Common ones are the Bourne shell, the C shell, and the Korn shell, all of which are available on the Physics workstation. By default the shell that you will be running is called tcsh, and it is an improved version of the C shell.

So what does the shell do for you? Its most useful feature is the maintenance of the history file (containing the last 20 or more commands that you have typed) and its ability to let you edit and resubmit previous commands by using the arrow keys. Try using the up and down arrow keys to move around the history list. Use the left and right arrow keys to move within a command. You can edit a command by using the delete key and inserting text. Resubmit the command by typing carriage-return (you don't have to be at the end of the line to do this).

Another very useful feature of tcsh is filename and command completion. To explain, suppose that you want to perform the operation

less ~/tex/thesis_chapter2_part5.tex
Rather than typing out the whole filename you only have to type the characters at the beginning of it that are unique, and then hit the TAB key. When you hit TAB, tcsh fills in the rest of the filename for you (or beeps if it can't find the file or if there are multiple choices) If there is more than one file that matches what you have typed so far, tcsh will fill in as much of the filename as it can, and then beep for you to respond with further characters. You can type &#;'136 D at any time to see a list of all the possible files that match what you have typed so far.

The shell has numerous inbuilt commands (such as jobs, fg, bg, time). To find documentation on these commands use man csh and man tcsh.

If a command isn't recognized by the shell, it is then assumed to be a UNIX system command and is searched for in the directories listed in your PATH environment variable. Type printenv PATH to see what PATH is currently set to.

UNIX equivalents to autoexec.bat, login.com

Most computer operating systems have a way of executing a file of commands when you first login. With MS-DOS you have an AUTOEXEC.BAT file, with VMS you have a LOGIN.COM file. UNIX is no exception, and the file is called .login. Everyone has one of these files in their login directory. To examine it type

less ~/.login
to make it show up in a directory listing, you have to use the -a switch on the ls command, e.g.,
ls -a ~
The .login file is executed every time you login (you can also create a .logout file if you wish--it will be executed when you logout). In addition, there is another file, called .cshrc (which stands for C shell run commands) which is run every time you start up an invocation of the UNIX C shell (which occurs almost every time you type a command, see the discussion on shells in §gif). You should take care what you put in your .cshrc file since it is an overhead on every command that you type.

Input/output redirection

For each program that you run UNIX assigns three input/output ``streams'' to it. They are

You can reassign these streams to be files or devices (such as magnetic tape drives). For example, the command

ls -l

will list all the files in your current directory. The output of the command will appear on your terminal screen. To redirect it to a file, use

ls -l > filename

Note that you don't have to put spaces around the > character. To redirect standard input use the < character, and to redirect standard error as well as standard output use >&. To append to an output file rather than to truncate it, use >> and >>&. To stop for user input in a shell script, use <<. If the file that you want to write to already exists, then you should put an exclamation mark after the > or >& to force the shell to overwrite the file (see man csh for information on the ``noclobber'' shell variable that affects this behaviour). When using an exclamation mark in this manner, you need to put a space after it to avoid the shell interpretting it as a request to extract text from the history list.

As a final example, suppose that you have a program called model which normally requires input from your terminal, and writes its output to the screen. To force model to take its input from filein and write its output to fileout you would type,

model <filein >fileout
See man csh for the definitive discussion on input/output redirection.

Pipes

To direct the standard output of one program to the standard input of another you use a pipe, represented by a vertical bar. For example to search the process list for jobs belonging to a particular user, you can use

ps -aux|grep user
where the output of the ps -aux command (which lists all the running processes), is piped to the input of the grep command which prints out those records which contain the word user. You can have multiple pipes on the one command line.

It is worth knowing about the UNIX program ``tee''. This program accepts a filename argument, and makes two copies of its standard input: one goes straight through to the standard output, and the other goes into the file. For example, suppose that you wanted to keep a log of a telnet session to a remote computer, then you could type

telnet cray.nasa.gov | tee logfile


next up previous contents
Next: Security Up: No Title Previous: Files

Michael C. B. Ashley
Fri Jun 28 13:34:23 EST 1996