>> Other Pages:
>> 61a Reader
Enough UNIX to Make You Dangerous
by Kurt Meinz
This is a short introduction to the UNIX operating system for CS61A students. It is by no means a complete guide, but should tell you all you need to know to do your course work.
Command names, shell interactions and keyboard shortcuts are in a monospace font. Fields which require you to fill in a piece of data are in brackets, as in "whois [your name]".
The latest version of this guide is always available online at http://www.kurtm.net/misc/using_unix.php.
First Things First
On the first day of class you should have been given an account form. Your login name should be on the account form. If you forget your login name while you are logged in, you can find it by typing:
at the shell prompt. Note that you are not supposed to type the %, it is the shell prompt. Before you start playing around with your account, you should change your password as follows. First, connect to the po.eecs computer by typing
When you do this, the computer will respond with something along the lines of "Do you trust po.eecs?". Please say whatever looks like "Yes". Next, we want to tell po to change your password
Po will respond by asking you to type in your old password [the ugly one on your account form]. After that, it will ask you to type in your new password. Make sure that your new password is easy to remember, contains more than 5 digits, and contains both letters and numbers. After you type in your new passowrd and confirm it, po will say something along the line of Accepting NIS+ credentials. This is good. It will take about 10 minutes for your password change to propagate through the system, so you may have to use your old password once or twice more.
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 several different UNIX shells, but they all share a similar interface. Your account is setup to use the csh shell by default, but popular shells like bash and zsch can also be installed
Shells run in windows called "terminals". When you want more than one shell running, launch a new terminal by typing:
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
When you launch a program it will run until it is finished and then return you to the shell. Even if the program you launched starts up in a new window, the shell will wait until the program has finished before it will let you type in a new command. If you want the shell to return immediately (so that both the launched program and the shell are listening to what you have to say), do so by typing the launch command as you normally would and tack an ampersand on the end
When your programs have cluttered your terminal with their output, you can clear the terminal screen with the clear command:
When you are done using a shell close it by typing:
You can also type ctrl-d to kill a shell. When you are done working you will want to log out from your computer.To do this you need to go to your login shell (the one that was first opened when you logged into the machine) and type:
Emacs and Scheme
Emacs is an ugly yet powerful text editor. emacs was created before graphical user interfaces were common and text-based terminals were the norm, meaning your primary interface to emacs is through the keyboard. emacs keyboard shortcuts are difficult to learn because they are different from the standard shortcuts of most other applications, but they do follow a pattern.
Most of the commonly used emacs features are control sequences (C-x) , while the less commonly used features are meta sequences (M-x). C-x is the standard notation for control sequences, it is obtained by pressing the control key and then the x key. 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 STk scheme interpreter, within emacs 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. You can always hit (C-g) to quit out of the Mini-Buffer if you make a mistake. To quit STk, either kill the buffer it is contained in, or type (quit) at the STk prompt.
To open an already existing file, go to the File menu and select Open File (C-x f) and type the name of the file and hit enter.
To create a new file, go to the File menu and select Open File (C-x f) and type the name for the new file want the file and hit enter. This can be confusing because creating a new file and opening an existing file use the same interface.
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 prompts 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 get a list of all open buffers type (C-x b). You can switch between buffers in this mode by moving the cursor over the buffer and pressing enter or clicking the mouse.
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 click in the window you want to make active or 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 left 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 most UNIX applications. Caveat: Extremely large blocks of text being copied or pasted with the mouse may lose some data.
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. A file named answers.scm in a directory named Private in my home directory, has the path: ~/Private/answers.scm. Files are case sensitive, BOX and box are two different file names.
You can specify more than one file with a path by using wild cards. A wild card is character that matches many characters. The * wild card matches any number of characters, while the ? wild card matches only one character. The expression ~/answers/*.scm matches all the scheme files in the directory answers, while the expression $HOME/answers/hw?.scm matches the homework assignments zero through nine.
When you are working within the shell, it 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:
To list the files in the current directory, type:
To list all the files in the current directory, including normally hidden files, type:
To list the files in the current directory and other additional information, such as the file's owner, its creation date, and it permissions type:
To list the files in a given directory, say answers type:
To move down to a subdirectory, say sub, type:
To move up a directory, type:
To create a new directory named foo, type:
To create a copy of a file foo called bar, type:
To move file bar into directory foo, type:
To remove a file foo, type:
To remove a directory you must first ensure that the directory does not contain any other files or directories, then type:
When you remove or delete something on a UNIX system it is gone forever. There is no way to recover deleted files, so be careful.
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:
All the printing commands will print to the printer nearest the computer you are logged into unless you tell them otherwise. All the instructional printers in Soda Hall are named after the room they are in. The printer in 330 Soda Hall is called lw330, while the downstairs printer in 274 is called lw274.
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.
When you login to a computer, the default printer is the print to which your print jobs will go if you do not specify another printer. The default printer is usually the printer the is closest to the computer to which you are logged in.
To see the queued print jobs on all the printers to which you can print, type:
To see the queued print jobs on printer printer-name, type:
To print a postscript (ps) file to the default printer, type:
To print a postscript (ps) file to printer printer-name, type:
To print a text file to the default printer, type:
To print a text file to printer printer-name, type:
If you want to print an acrobat (pdf) file, use a viewer to print it or save it to a postscript file and then print it. Do not ever use enscript on anything other than a text file, it will make the printer spew out random stuff for thirty minutes and it will make everyone behind you in the print queue very angry.
One of the strengths of the UNIX operating system is that it works well over a network. You can use a Solaris machine in Australia to login to a HPUX computer in Tokyo and use the programs on the HP machine, without having have them on your computer. The best way to log into 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 login to a remote computer named dilbert, type:
If you have never logged into dilbert before ssh will ask you if you really trust dilbert, you should answer yes . 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 login to the CS computing facilities from home and use graphical applications you will need X Windows software. This is available for free from www.depot.berkeley.edu. X Windows is slow over a modem, but fine over DSL or a cable modem.
One freely available Windows ssh client is TeraTerm. To get around export restrictions, TeraTerm is split into two pieces, the main program, which is just an insecure telnet client, and a patch that makes it into a secure ssh client. You can get TeraTerm and the TeraTerm SSH patch at: http://www.csua.berkeley.edu/~mikeh/crap/ftp. The two files you need to get are ttermp##.zip and ttssh##.zip (##s are the version number, and this changes periodically).
NiftyTelnet SSH is a freely available MacOS ssh client available at: http://andrew2.andrew.cmu.edu/dist/niftytelnet.html. The department provides FSecure for Mac OS, but unless you have an X Server for Mac OS, Nifty Telnet is the better choice.
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:
To list all the process you are running on the computer on which a shell is running on, type:
Occasionally a program crashes or refuses to quit, if this happens you can kill it. To kill a process, type:
If the kill command didn't kill the process, try again. If the process is still alive, type:
Be careful when you use kill -9 , it is very powerful and should be used with extreme caution.
Web and Email
The only decent web browser on UNIX is Netscape Communicator, launch it by typing:
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 is relatively easy to use and most of its menu options are obvious. To see your inbox type I at the main screen. To compose a message type C. To select a message for deletion type D while viewing the message or when the message is hilighted in your inbox. To unselect a message for deletion type U while viewing the message or when the message is highlited in your inbox. To clear your inbox of items marked for deletion type X (for expunge) and then answer y at the prompt.
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, view its man page by typing:
If you need help with a certain subject, but don't know the appropriate command, type:
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 in room 343. 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
Copyright 1999-2001 Paul Twohey. All rights reserved.