This set of notes assumes that you have never used Unix before. It does assume, however, that you are comfortable using computers with a graphical user interface, such as the Macintosh operating system or Microsoft Windows. You should sit down at a CS Unix machine and go through this tutorial trying things out as they are explained. Upon completion, you should be able to log in, understand the basics of entering a command line, move around in the file system and view existing files, do basic manipulations of windows, do basic editing with the Emacs text editor, know where to find help and have written your first C program! There are specific exercises listed at the end of the handout, but you'll gain more experience if you try things out as you read.
This identifies the operating system as FreeBSD, the machine as an Intel x86 machine. The machine name is in the first set of parentheses. The second set of parentheses is not really important, but it identfies the terminal connected to the machine. At this point, the computer is waiting for you to enter your login id. Your login id is 2 digits identifying the year you will graduate followed by your initials (usually 3 initials, sometimes 2). If that doses not result in a unique id, it will be followed by _# where # is the value of a counter to make your id unique. For example, Vladimir L. Andonov's login is 02vla. Your login id is set by the system administrator and is never changed. Simply type your login and then carriage return.FreeBSD/i386 (pineywoods.cs.williams.edu) (ttyv0) login:
The login prompt is now replaced with a password prompt. Your password will not display as you type it for security reasons. Hit the carriage return after your password. At this point, you should be logged in. If you typed either your login or your password incorrectly, you will receive an error message "Login incorrect" and will need to re-enter both. If you already have a Unix account from last semester, your password has not changed. If this is your first acount on a CS Unix machine, I have your password.
After successfully logging in, you will see:
This identifies the version of the operating system. (FreeBSD is derived from BSD which was developed at Umiversity of California at Berkeley, explaining the copyright.)Last login: Wed Jan 2 17:29:34 on ttyv0 Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994 The Regents of the University of California. All rights reserved. FreeBSD 4.3-RELEASE (GENERIC) #0: Sat Apr 21 10:54:49 GMT 2001 Welcome to Computer Science at Williams! You are running FreeBSD 4.3! You are logged into pineywoods running FreeBSD 4.3-RELEASE kde, Xwindows, fvwm2 or vanilla? (k|[x]|f|v)
At this point, the computer is asking you to select a window manager by typing a single letter:
Your initial password is provided by the system administrator and you should change it the first time that you login. A good password should be impossible for others to guess or to find by trying every word in the dictionary. A good password has the following characteristics:
To change your password, use the yppasswd command as follows. In the body of the window there is a prompt that looks like: ->. At the prompt, type yppasswd. Here is what you will see:
Here you should enter your current password. Your password will not be displayed on the screen when you type it. Then enter carriage return. Next you will see:-> yppasswd Changing NIS password for your-login-id on bull.cs.williams.edu Old password:
Type in the new password that you want. Again, it will not appear on the screen. Type carriage return. Now you will see:New password:
Type the same new password again. This ensures that you typed correctly since you could not see the characters you typed. If you type the password the same both times, you will see the message:Retype new password:
If the two attempts at typing your new password differ, you will see:NIS password has been changed on bull.cs.williams.edu.
EOF is a mystical phrase meaning End-Of-File. This still doesn't answer the question of what to type, though, does it? EOF is represented by the character Control-d. You type this by holding down the control key (much like you would the shift key) and typing d. (Unforttunately, I can't explain why Control-D means EOF, but it is the case that some Unix commands will expect you to type this magical character to quit.) If you do type Control-d, your password will not be changed, so don't type this!Mismatch; try again, EOF to quit. New password:
If you make mistakes in typing on the command line, use the Delete or Backspace key to erase the previous character.
One thing you will notice with Unix is that "no news is good news". Often if a Unix command is successful, it will produce no output! If it fails, you will receive an error message. Of the list of commands above, only ls and more produce output when they succeed.
ls List the files in the current directory cp file1 file2 Copy the file named file1 to a new file named file2 mv file1 file2 Rename the file named file1 to have the name file2. (mv is actually short for move, but it doesn't necessarily move anything!) rm file1 Remove the file named file1 more file1 Display the contents of a file lpr file1 Print the file named file1
The "more" command deserves some more comment because it is an interactive command. It displays your file one screenful at a time. After each screenful, it displays a prompt either consisting of the name of the file being displayed in reverse video (for the first screenful), (END) in reverse video (for the last screenful), or : (for all other screenfuls). The prompt appears at the bottom of the screen. At this prompt, you have several options, the most useful being:
You can try out "more" by typing "more /home/faculty/freund/shared/cs010/long-file". This will show you the contents of a file in my directory that you have permission to read.
space Display the next screenful b Display the previous screenful q Quit more, returning to a shell prompt.
Directories are containers for files. (For some reason, Macintosh and Windows use the term "folder", but it means the same thing.) When you use ls to list your files, a directory will appear with / at the end of its name. At all times you have a current directory. Your commands are interpreted with respect to your current directory by default. So, for example, ls lists the files in your current directory if you give it no arguments. Here are some useful commands to manipulate directories:
Filenames should consist only of letters, numbers, and '.' A filename is typically divided into a descriptive name and an extension, separated by '.'. Extensions are purely by convention but typically indicate the type of file. For example, "myfile.txt" would be a text file, while "myfile.c" would contain a C program. Extensions are generally optional although some programs, such as the C compiler, expect them to be there.
mkdir dir1 Create a new directory named dir1. rmdir dir1 Remove the directory named dir1. You can only do this if the directory is empty. cd dir1 Make dir1 be the current directory pwd Display the name of the current working directory
Filenames can be given as names that are relative to the current working directory or as absolute names from the special root directory. Thus far, we have assumed relative names that refer simply to files in the current directory. We can also use relative names to identify files in subdirectories. For example, "mydir/myfile" is the file named "myfile" in the directory named "mydir", where "mydir" is located in the current working directory.
Each user also has a home directory. This is the directory that is the user's current directory when the user initially logs in. No matter what the absolute pathname is to your home directory, you can always refer to it with the special relative pathname '~'. For example, no matter what your current directory is, if you type "ls ~", you will see a listing of the files in your home directory.
An absolute pathname always begins with / while a relative pathname never does. To find out the pathname that corresponds to your current directory, type pwd. If you are still in the directory that you logged into, you should see something like /home/cs-students/03abc. This indicates that your home directory is named "03abc" and that it is inside a directory called "/home/cs-students". You can see what other students have accounts on the CS Unix machines by using the ls command, telling it to show you what is in the /home/cs-students directory:
You should see a long list of directories with names that all look like user ids along with a few other random directories.-> ls /home/cs-students
To move a window, point the mouse in the title bar, hold down the left mouse button and drag the window.
To resize a window, point at any of the four corners of the window, hold down the left mouse button, and drag the corner.
To bring a window to the top so that it is completely visible, click the left button in the title bar.
To lower a window so the windows below it are more visible, click the right button in the title bar.
To enlarge a window to a standard page size, left-click on the rightmost icon in the title bar. A second left-click will return the window to its previous size.
To iconify a window, click on the second icon from the right in the title bar. The window should appear as an icon at the bottom of the display. If it does, middle-clicking or double-clicking will restore the window. If, for some reason, no icon is displayed, you can still restore the window by pointing at the desktop (an area outside any window) and selecting the window's title from the menu displayed.
The leftmost symbol in the title bar is a rounded rectangle. If you click on it, it brings up a menu containing. The most useful commands in this menu are.
The area that is outside all windows is called the root. The mouse buttons behave differently in the root. In this case, each button brings up a menu. We have already seen that the right button gives a menu of all windows. The middle button is the same as the menu we saw above. The left button brings up a menu to open some common applications and also to logout. The menu includes:
(Un)Maximize Makes the window as large as the display and restores it to its previous size on a second click. Close Close this window. If the application uses more than one window, the application will continue to run. Destroy Quit the application running in this window. This will close all windows associated with the application.
xterm Creates a new window running a Unix shell xfig Creates a new window running a tool to draw figures with xv Creates a new window allowing you to view gifs, jpegs, etc. and to convert between image formats. Netscape You know... emacs Creates a new window running emacs, a text editor Exit Fvwm Use this to logout
The top row are the titles of pulldown menus that are available. Initially, we will work with a few of these menus and a few keyboard commands. Over the month, your repertoire of commands will grow and will move away from menus and toward keyboard commands. For now, let's create a new file. To do this, point at "Files" and click the left mouse button. Then select "Open file...". At the bottom of the window, you will see "Find file: ~/" with a small black box following it. The box indicates where characters will go when you type. Type in the name of the file that you want to create and hit carriage return.
The last line of the Emacs window is where command prompts and messages appear. The reverse video line immediately preceding it is a status line. It shows you the name of the file you are editing. Before that you should see --:--. This means that the file is up-to-date. If it says, --:**, it means the buffer has been changed since it was last saved. If it says --:%%, it means that you cannot modify the file. After the filename is the "mode" that you are editing in. This should say "(Fundamental)". We will talk about modes later this month. Next is the current line number (L1 indicates the first line). Following that is an indication of how far the current line is in the file in terms of percentage. All indicates that the entire file is showing. Top indicates that you are on the first screenful. Bottom indicates that you are on the last screenful.
The area between the menu titles and the status line is the buffer that displays the contents of the file. Most of your typing goes directly into this buffer. Type some text. Notice the status line changes. You can move the cursor around using the arrow keys. Use the scrollbar to move through the file. Use the "Save Buffer" command from the Files menu to save the buffer to a file. Use "Exit Emacs" from the Files menu to exit emacs. Notice the characters that appear in parentheses at the ends of command names in the menus. These tell you the keyboard characters to type to execute the commands without using the commands. For example, saving the buffer can be executed by typing Control-x Control-s. In the menu control characters appear as C-. Type these by holding the control key down at the same time as typing the second character. Another common way to enter commands is using the Escape key. This is abbreviated M-. In this case the escape key and the following key are typed separately. Here are the keyboard sequences for the most common Emacs commands:
Using keyboard commands is generally faster than moving one's hands back and forth between the mouse and keyboard as one must do to use the menus and scrollbar. While it takes extra effort to learn, the payoff is worth it in the long run in terms of speed of using the editor.
C-f Forward one character C-b Backward one character C-n Next line C-p Previous line C-v Next screenful M-v Previous screenful C-d Delete next character Backspace Delete previous character C-x C-s Save buffer to a file C-x C-f Open a file C-x C-c Exit Emacs
xman is already started when you log in on the console of the FreeBSD systems in TCL 312. xman provides a graphical user interface to online Unix manuals. The manual is divided into several sections. The most useful section for users is section 1 on user commands. C programmers will be interested in sections 2 and 3 which describe library routines provided by Unix that can be called from C programs. In the xman window, click on the "Manual Page" button to bring up a window. If you click on the Sections menu, a list of sections will appear. Selection Section 1, user commands, and you will see a complete table of contents of all Unix commands. If you click on one entry in the window, you will now see the manual page for that command. This is very useful when you want to know exactly how to use a command or exactly what arguments it takes. You will be reading a lot of man pages over the month so you will become more familiar with doing this as the month progresses.
Using xman in this way is only useful if you know exactly what command you are looking for. xman also supplies a keyword-based search. To use it, pulldown the Options menu. Select Search. Type in a keyword and then click on the apropos button. You will now see a list of every entry in the manual with that keyword in its title. Remember that you will find section 1 most interesting so it is safe to ignore those entries that do not have (1) after the command name since those are not in section 1 and thus are not user commands.
xman is most useful for the simplest Unix commands. More complex tools are usually better explained with the info package within Emacs. To start info, enter Emacs and then use "C-h i" to begin info. The first screen shows a list of programs for which help is available. Move the cursor to the program you want more help on using the arrows and then use the carriage return to select the entry. This will now give you help in a hypertext style for the program. You may find underlined links that you can move the cursor to and then hit carriage return to select them. You can also navigate the hypertext selection using the following keys:
Many people prefer the text-based manual system, called man. You can get text-based information about any of the commands or system calls by typing man followed by the name of the command or system call. You can then page through the manual information. To learn more about the manual, you can read the manual about the manual by entering man man at the command prompt.
l Last item visited (like Back in Netscape) u Up to parent n Next sibling p Previous sibling
To compile a C program, use the following command line:
gcc -Wall -o <output-filename> <source-filename>
For example, if you place the above program in a file called face.c, you would compile it using:
gcc -Wall -o face face.c
This will create a file called face in your directory. Note that there will be a * at the end of face. This just indicates that the file is executable and is not actually part of the filename. To execute the file, just type the output-filename at a shell prompt as follows:
-> face