Using UNIX - A Guide For Beginners

by Paul Twohey

Shells and Terminals

The UNIX shell is a command line interface similar to DOS, but much more powerful. The UNIX shell is difficult to learn, but once mastered can be made to do almost anything. There are actually several different UNIX shells, but they all very similar. Your accounts are setup to use the csh shell.

One of the most important tasks the shell performs is launching programs. To launch a program, type its name at the shell prompt, followed by the arguments to the program and then hit enter. For example, to launch emacs with the argument cool-file.txt type:

% emacs cool-file.txt

When you launch a program it will run until it is finished and then return you to the shell where you can run another program. If you want to run more than one program at a time you need to tell the shell not to let the program monopolize it. To launch a program so that it does not take over the shell type the program name, followed by the program arguments, followed by an ampersand:

% emacs &

There are times when you will want more than one shell running. To accomplish this you need to launch a terminal. A terminal is a window that contains a shell. To launch a terminal from the shell type:

% xterm &

When your programs have cluttered your terminal with there output, you can clear the terminal screen with the clear command:

% clear

When you are done working you will want to log out from your computer.To do this you need to go to your log in shell and type:

% logout

The log in shell is the window named shell . If you have minimized your log in shell it will be a white rectangular box with the word shell in the middle.

Emacs and Scheme

Emacs is a thermonuclear text editor, it can do almost anything. Emacs was created before graphical user interfaces were common and text based terminals were the norm, consequently you can do almost everything in Emacs with the keyboard. Emacs keyboard shortcuts are difficult to learn because they are different than the standard shortcuts of most other applications, but they do follow a pattern.

Most of the commonly used emacs features are control sequences, while the less commonly used features are M-x sequences. M-x is the standard notation for the meta key. On the HP and Solaris computers M-x is obtained by pressing the alt and x keys at the same time.

To start the scm scheme interpreter, type M-x run-scheme . You will notice that after you type M-x, the text cursor has moved to a separate area at the bottom of the Emacs window. This area is called the Mini-Window and is where Emacs expects text input for its commands. To quit scm, either kill the buffer it is contained in, or type (quit) at the scheme prompt.

To create a new file, go to the File menu and select Open File (C-x f) and type the name you want the file to have and hit enter.

To open an already existing file, do the same thing you would do to create a new file, but use the name of an already existing file instead of a new file name.

To save a file, make sure the cursor is active in a window that is editing the file and select Save Buffer (C-x s) from the File menu. When Emacs prompt you if you want to save changes to the buffer, type y and hit enter.

To save all open files, use the keyboard shortcut (C-x C-s) . When Emacs prompts you if you want to save changes to a particular file, type y and hit enter.

If you have more open files than windows, you can select which file you want to view in a window by clicking in the window and then selecting the appropriate file from the Buffers menu.

To close a file, select Kill Buffer (C-x k) from the File menu.

To quit Emacs select Exit Emacs (C-x C-c) from the File menu.

Emacs contains several features that can make text editing easier. When you are in the Mini-Window and have type part of a long meta command or file name, Emacs will guess which command you want if you hit the tab key.

Emacs can view more than one file at a time. It calls each of these views a window. To split the Emacs window with the cursor in it horizontally, select Split Window (C-x 2) from the File menu. To split the Emacs window with the cursor in it vertically use the keyboard shortcut (C-x 3). To switch between open windows use the keyboard shortcut (C-x o). To collapse all the Emacs windows into one window, select One Window (C-x 1) from the File menu.

Unix Copy and Paste

To copy text, hold down the middle mouse button and select the desired text. To paste text, click the middle mouse button where you want the copied text to start. This form of copy and paste works across different UNIX applications.

Files and Directories

The UNIX file system is organized around files and directories. Every user has a home directory. Your home directory is where you should save your files. Your home directory has a two special names: $HOME and ~.

The location of a file is specified by a path. Forward slashes are used to delineate directories in a path. If I had a file named answers.scm in a directory named Private in my home directory, its path would be: ~/Private/answers.scm . You can specify more than one file with a path by using wild cards. The path that would specify all the scheme files in the directory answers is: ~/answers/*.scm . Files are case sensitive, BOX and box are two different file names.

When you are working within the shell, the shell keeps track of the directory you are using. This directory is called the current working directory, or the current directory.

To find the current directory, type:

% pwd

To list the files in the current directory type:

% ls

To list all the files in the current directory, including normally hidden files, type:

% ls -a

To list the files in the current directory and other additional information, such as the files owner, type:

% ls -l

To list the files in a directory, type:

% ls directory

To change the current directory to another directory, type:

% cd new-directory

To move up a directory, type:

% cd ..

To create a new directory named foo, type:

% mkdir foo

To create a copy of a file name foo called bar, type:

% cp foo bar

To move file bar into directory foo, type:

% mv bar foo

To remove a file foo, type:

% rm foo

To remove a directory you must first ensure that the directory does not contain any other files or directories, then type:

% rmdir directory

To prevent the servers from running out of disk space, your accounts are only allowed to store a limited amount of data. To find out how much room you have left, type:

% quota -v your-user-name

Printing

All the printing commands will print to the nearest printer to the computer you are logged into unless you tell them otherwise. All of the examples will assume that you want to print to this printer. If you do not want to print to this printer, look at the man page of the print command you are using.

If you want to print an acrobat file, use a viewer to print it or save it to a postscript file and then print it. Do not ever use enscript on a binary file, it will make the printer spew out random stuff for thirty minuets and it will make everyone behind you in the print queue very angry.

To print out a postscript file, type:

% lpr postscript-file

To print out a text file, type:

% enscript -2rG text-file

After you have issued a print command, your print job is put into a queue and printed when all the print jobs before it are done printing. Near homework and project deadlines the queue is often large (over 100 print jobs), so be prepared and print early.

To see your uncompleted print jobs, type:

% lpstat

Remote Access

One of the strengths of the UNIX operating system is that it works very well over a network. You can be using a Solaris box in Australia and log in to a HP box in Tokyo and use the programs on the HP box, without having have them on your computer. The best way to log in to a remote computer from another UNIX computer is to use the ssh command. It uses strong encryption and is secure against most attacks. You may have heard of other programs like rlogin and telnet. These are insecure, do not use them, it is too easy for a hacker to intercept your password and steal your account. To log in to a remote computer named dilbert, type:

% ssh dilbert

If you have never logged in to dilbert before ssh will ask you if you really trust dilbert, you should answer yes and hit enter. ssh will then prompt you for your password, enter it and ssh will set up your terminal so that you can use the remote computer.

If you want to log in to the CS computing facilities from home, you will need X Windows software. This is available for free from www.depot.berkeley.edu. X Windows is slow over a modem, expect sluggish responses.

Processes

Every time you launch a program, it is given a process id number (PID), this number distinguishes this process from all other running process.

To list all the process you have launched from a shell, type:

% ps

To list all the process you are running on the computer a shell on which a shell is executing on, type:

% ps -u your-login

Occasionally a program crashes or refuses to quit, if this happens you can kill it. To kill a process, type:

% kill PID

If the kill command didn't kill the process, try again. If the process is still alive, type:

% kill -9 PID

Be careful when you use kill -9, it is very powerful and should be used with extreme caution.

Email

Netscape Communicator is a good web browser, but it is overkill for reading email. pine is a small, fast, text-based email reader. pine is (relatively) easy to use and it loads much more quickly than Communicator. To use pine, type:

% pine

Getting More Help

This guide is designed to ease you through some basic UNIX tasks, but it can't help you do everything. When you have a problem, don't be helpless. There are many resources available to you, use them.

If you need to know more about how a certain program works, type:

% man program-name

If you need help with a certain subject, but don't know the appropriate command, type:

% apropos subject-name

apropos will give you a listing of commands related to a subject. Use man to find out more information on the command once you have located it using apropos.

If the online help isn't helpful, there are real people who can help you. The Computer Science Undergraduate Association (CSUA) is located opposite the vending machines on the third floor of Soda Hall. The people that staff the CSUA office are very skilled in the use of UNIX and should be able to help you. If all else fails, you can always email root@cory for help. Only mail root if you have a serious problem, the instructional support staff are very busy and do not take kindly to people who waste their time.

Other Useful Commands

more - quickly view text files
who - find out which people are on a computer
which - find the path to a program
find - find the location of a file
chmod - change a file's permissions
grep - search text files
talk - online chat with other users
ghostview - view and print acrobat and pdf files
xpdf - view and print acrobat files
acroread - view and print acrobat files

Copyright 1999 Paul Twohey. All rights reserved.