Trapped in a frame and can't get out? Escape!

The MSRI Computing Handbook

UNIX Basics



Some Useful UNIX Commands

Getting Help on UNIX

One of the most useful of all UNIX commands is man. The man command accesses the online manuals, e.g. man man will display the entry describing the man command itself. An entry is referred to as a ``man page'' even though it might be many pages long. UNIX man pages are generally fairly informative, though their styles vary. Some remind me of a Comptes Rendue note where the author is trying to show that she has thought of everything without revealing what she actually thought, while others are more like Bourbaki in their abstract theoretical wanderings. You will sooner or later hear the acronym RTFM in answer to some question about UNIX; RTFM stands for Read The Fine Manual.

Filenames

You may give your files any name you wish (well, almost any name). The name may be as long as you wish, but the following characters are forbidden:
 / " ' ` ~ * > < | $ @ [space] [tab]

Good filenames Not Acceptable Why not?

ozzie ozzie nelson contains a space
why-me why-me? contains a ?
draft.9_6_93 draft.9/6/93 contains a /
bonzo-4 -bonzo-4 starts with -
great "great" contains a "
program1 program1* contains a *
dinner.at.8 dinner@8 contains a @

Working with Files

Task Example Comments

Show a file listing ls Show a list of all your files.
ls -l Show the list in ``long'' format. It shows the permissions of the files. (see below)
ls -l foo Show the attributes of the file foo (see below)
List a file's contents cat file1 Display the file's contents all at once.
more file1 Display the file one screenfull at a time.
less file1 less is more, with bells and whistles
Copy a file cp file1 file2 file1 and file2 are now identical
Rename a file mv file1 file2 now file1 no longer exists
Move a file mv file1 /special/ the file is still called file1, but now lives in the special directory at root level. The leading / make this an absolute path.
mv file1 foo/bar/ the file is still called file1, but now lives in the subdirectory bar of the directory foo of the current directory. The lack of a leading / makes this a relative path.
Delete a file rm file1 Warning! Once you do this, file1 is gone. The only remaining copy will be on the nightly backup tape. If you need to recover a file from a backup, see the computing staff.

Permissions, Privacy, ls, and chmod

Each UNIX file and directory has associated with it a set of permissions, or mode, which govern who can read, write, or execute a file. They are most easily examined using the ls command, e.g.

yourPrompt% ls -l UnixCommands.tex
-rw-r--r--  1 joe         5445 Sep  5 09:54 UnixCommands.tex

yourPrompt% ls -l /bin/cp -rwxr-xr-x 1 root 65536 Sep 1 1993 /bin/cp

For any given file, there are three classes of people - the user who owns the file, the members of the user's group, and the rest of the world. Accordingly, permissions come in three triples, the first for the owner of a file, the second for the members of the owner's group, and the third for others.

Here we see that the file UnixCommands.tex is owned by the user joe, and is readable and writable for him, but merely readable for members of his group or for others; the file /bin/cp (which is the executable for the cp command above) is owned by root and is executable by the owner, the owner's group, and all others. If the permissions are interpreted as bits, then each class of people corresponds to a single octal digit, so the permissions of UnixCommands.tex could be abbreviated to as ``644'', while the mode of /bin/cp as ``755''.

All MSRI members belong, by default, to the member group, though they can be members of other groups as well. You can find out what groups you are part of with the groups command. You can find out about what group owns a file or directory using the -g option to ls. For example, the summer graduate student program had its own group, sgw. Here is an example of ls -lg:

yourPrompt% ls -lg /u/summer
total 219
drwxrwxr-x  4 ligocki  sgw           512 Aug 23 18:56 Notes
lrwxrwxrwx  2 joe      sgw           512 Aug 18 17:04 RCS -> /usr/local/src/RCS
drwxrwsr-t  2 root     sgw          1024 Aug 19 00:16 contestPix
drwxrwsr-t  2 stas     sgw          1024 Aug 30 12:19 day1
drwxrwsr-t  7 edoeff   sgw          1024 Aug 26 14:29 day2
drwxrwsr-t  3 hoffoss  sgw           512 Aug 12 11:25 day3
-rw-rw-rwT  1 root     sgw         58267 Aug 23 20:31 mail.log
drwxr-xr-x  2 wpt      sgw           512 Aug 10 17:56 thurston

Here we see that inside the directory /u/summer there is a directory (that's what the initial d is telling us) called Notes. Notice that Notes is owned by user ligocki and writable by anyone in the sgw group. This allows members of the sgw group to collaborate on the project of writing up lecture notes. Note also that, for techno-historical reasons, directories are always executable. The leading l in the listing for RCS shows that it is a symbolic link, that is a reference to a directory (in this case) which resides elsewhere in the file system, /usr/local/src/RCS. The file mail.log is an example of a world-readable file; absolutely anyone who can find this file can read or write to it. The peculiar s's and t's in this example are more complex modes; see the ls man page.

By now you should be beginning to worry about the tension between collaboratively sharing files and privacy. By default, member's home directories are world readable, so as to encourage the sharing of information, though one could easily create a directory, private, which has mode 700, i.e. is readable (and writable) only by the owner. Your mail spool file is also mode 600, that is readable and writable only by you.

While we make every effort to protect the privacy of MSRI members, for example with the private subdirectory and the firewall guarding our network, a dedicated and knowledgeable cracker with access to our network could still read the files in your private directory. If you have truly sensitive documents, you should consider your mode 600 and 700 files and directories no safer than papers sitting out on the desk of your locked office.

After that chastening note, how do you change the permissions of of files? By using the chmod command to change their mode. Chmod understands permissions both symbolically and numerically. Here are some examples:

chmod u+x myProg make myProg executable for the user who owns it
chmod g+x myProg make myProg executable for the owner's group
chmod +X myProg make myProg executable for everyone
chmod g-r o-r foo make foo unreadable by the owner's group and the rest of the world
chmod 600 bar make the file bar readable and writable by its owner only
chmod 700 keepOut make the directory keepOut readable and writable by its owner only

Working with Directories

Task Example Comments

List the contents of a directory ls bar
ls -l bar This shows the permissions of the files.
Move to a directory cd /foo more to the directory /foo at root level
cd move to your home directory
cd ~/foo move to the directory foo in your home directory. Here ~ is a UNIX metacharacter which expands to `the home directory of (you by default)'.
cd ~foo move to user foo's home directory
cd /u/foo move to user foo's home directory, specified here using MSRI's /u/ convention.
Create a directory mkdir special
Rename a directory mv special xyz
Delete a directory rmdir xyz This only works if the directory is empty
rm -r xyz This works even if the directory xyz is not empty

Printing

Where Are the Printers?

MSRI has three laser printers available for member use. The printers are named after the floor they are on, and have mnenomic names as well --- 1: prints in duplex mode by default and is located in the library; 2: prints single-sided only and is located in room 225. If your office is on the second floor, this is your default printer; 3: prints single-sided only and is located in room 325. If your office is on the third floor, this is your default printer.

The lpr command is the native UNIX command to send output to the printer. Used alone, lpr will send output directly to your default printer. To direct output to another printer, use the -P option to the lpr command:

lpr -P1 myfile

Printer Name Location
libhp 1 Library
hplj 2 225
Zapf 3 325

Printing a UNIX Text File

To print a text file (such as an electronic mail message), you simply specify the name of the printer, and the name of the file. You may specify as many files if you wish. Here are some examples:

lpr file1 Send the job file1 to your default printer.
lpr -P3 xyz Send the job xyz to the third floor printer.
lpr -s huge Send the job huge to your default printer. For really big files, you should use the -s flag to avoid overflowing the spool directory.
lpr -P2 file1 file2 file3 Send the following three files. to the second floor printer: file1, file2, file3.

If you don't specify the name of a printer, as in the first example, the output will be sent to your default printer - the one on your floor.

Printing a TeX File

The command to print a TeX file is: dvips. Note that the lpr -d command is not implemented at MSRI. Instead, we use a specific software package, lprng, that has filters that will automatically detect the file type and should do the right thing to print the file. However, should you encounter a file that is not printed correctly, and instead shoots out reams of wasted paper, please do not continue to resubmit the job -- instead, notify a member of the computing staff immediately, and we will do what we can to get your job printed. For more information on printing TeX files, see section on dvips.

Printing a PostScript File

A PostScript file is simply a text file, albeit of a special form. PostScript is a page description language developed by Adobe Systems. Modern printers have interpreters that enable them to understand this language and render a page on paper. The ghostview previewer also understands the language and can render a PostScript file on screen. The way that dvips actually prints a dvi file is by converting it to PostScript and sending PostScript to the printer. Printing a PostScript file is immediate:

lpr filename.ps

You must be sure, especially if you received it via email, that the very first characters in the file are:

%!PS

Even a blank line at the top of the file will render it uniterpretable to the printer, which will then print the underlying PostScript source code. The case of the PS doesn't matter; i.e. %!ps is also ok.

If the file refuses to print, you should examine it with ghostview:

ghostview filename.ps

The ghostview interpreter will usually give some diagnostic messages which will help us isolate the problem.

Canceling a Print Job

You can cancel any printing job which is still in the print queue, i.e. which hasn't yet made it to the printer's internal memory. Therefore, the first step to canceling a print job is finding its place in the printer queue; once it is located in the queue, then either the originator of the printing job or an administrator can cancel it.

To locate a job in the print queue, use the lpq command. Once you know the job number, you can remove the print request using the lprm command.

Imagine that I am regretting having printed the file baz; here's how I would cancel it;

myPrompt% lpq
hplj is ready and printing
Rank   Owner      Job  Files                     Total Size
active joe        455  foo                       3191 bytes
1st    dave       456  bar.dvi                   10581 bytes
2nd    joe        458  baz                       1458 bytes
3rd    lisa       459  quux                      718 bytes

myPrompt% lprm 458 wocket.msri.org: dfA458reptar.msri.org dequeued wocket.msri.org: cfA458reptar.msri.org dequeued

At this point I could not cancel printing foo; its Rank, active, indicates that it is already in printer memory.

By default, the lpq and lprm commands address one's default printer. To operate on another printer, use the -P flag, just as for printing (see section on Printing a UNIX Text File above).

To understand the output of lprm, note that I am printing from my office workstation, reptar, on the second floor. The default printer, 2, on the second floor has the mnemonic name hplj (for Hewlett Packard LaserJet) and the workstation wocket is the host of the printer queue for this printer. Associated with each print job there are two files on the queue, one a control file and the other the actual thing to be printed.

Paper and Toner

The two most common problems with printing are lack of paper and low toner.

In the first case, there is a small mountain of paper under the table holding each printer. Adding paper is utterly trivial: simply slide the empty paper tray out of the printer and place an entire package of paper inside (unwrapped, of course).

When the toner gets low, the message panel on the printer will show a message to that effect. There are actually several messages to that effect of increasing severity. All should occur long before you actually perceive any degradation in quality. At the highest severity, the printer will refuse to print, but can be fooled into printing a few more pages by opening the printer and gently rocking the toner cartridge about its long axis. When the time does come to replace the toner, the printer should be cleaned, so please refer the problem to the computing staff.

In Case of Emergency

If there is a printing emergency (for example, the printer is spewing out hundreds of pages of garbage),

Customizing Your Environment

Many of the visible aspects of the UNIX user interface are controlled by so called ``dot files'', e.g. .cshrc or .xsession. This is primarily the playground of UNIX experts. MSRI periodically covers customization in its User Education Seminar.

Warning If you use customized .cshrc or .login files, proceed with care. MSRI's default .cshrc and .login files carefully set important system paths and variables. If you change them, many things may no longer work. We suggest that you study the following files: /usr/local/Setup/Login and /usr/local/Setup/Cshrc

If you would like to add your personal customizations to MSRI's login files, we recommend that you do it in files called .login.extra and .cshrc.extra. Activate the ``extra'' files by uncommenting the final lines of your .cshrc and/or .login files.

If you want to customize your window manager, typically, the .xsession file is the location to do this; however, with the kde window manager, the .xession file is not required. Customization of the kde window manager is discussed in the KDE help file. Customizations of the other available window managers will make use of the .xsession file. You are welcomed to customize as desired; however, should you encounter problems, and can no longer log in, use the failsafe login procedure (see section on Logging In), then please consult with the computing staff.

One customization which many members request is to be able change fonts. X-windows allows this on an application by application basis.

Suppose that you are interested in customizing the font for xterm, the basic xterm window. Other applications are completely analogous.

First, examine the system file that governs the window-related features of the application. It is located in either /usr/X11R6/lib/X11/app-defaults/XTerm on the Linux PCs or /usr/X11R5/lib/app-defaults/XTerm elsewhere.

Create a directory under your account called app-defaults and copy the above file to that directory. Edit the file and add the line: *font: -sony-fixed-medium-*-normal-*-24-*-100-*-*-120-*-* to the end of the file, save and exit. Next time you start the application, you should see a difference in the font sizing. This is just an example of a font that is useful for this application. It may be too large for your liking.

The command xlsfonts will give you a listing of all of the commands that are available on the system. You can play with these by cutting/pasting the lines into the XTerm app-defaults file. The last font description read will be the one activated. So, best to comment out those that you don't actually want used. The ! is the comment character.



Last modified by Joe Christy on $Date: 1999/09/16 22:38:24 $