Lab #1: Basic UNIX
Fall 1999
(To be completed in your lab period, week of September 13)
The Getting Started With UNIX manual is found online at
You are encouraged to continue your introduction to the laboratory computing environment by reading the above manual after you complete this assignment.
The first thing you must do when you begin your work on the computer is to ``log in'' to let the system know that it is you who is using the system. Access to the system is controlled to maintain its security; only those with accounts on the Engineering Computing Facility (ECF) system can access it. To login, you must have two pieces of information: a login name and a password. All undergraduate electrical and computer engineering students are automatically given an account when they register. The login procedure was discussed in class, and you should already have a login name and password. If you don't have it yet, you'll obtain it in the next section.
Your login name (or ``login'') is a 6-8 character string that is your identity on the computer network. Your password is a variable length character string known only to you. Your password serves as a key to your account much like you would use a key to gain entry to your locked house. In fact, not even the system knows what your password is, it only keeps an encrypted version. Later in the lab you will be shown how to change your password.
Just as you login to the computer when you begin to use it, you must logout of the computer when you are finished using it. If you must logout before you reach the end of the assignment, read the final section of the assignment which instructs you on how to logout. After you logout, DO NOT TURN THE UNIX COMPUTERS OFF!
Note: the computer systems in GB251 are on a different network. If your lab is in these rooms, you must first tell the computer that you wish to log on to ECF. Use the login name ecf and the password ecf to initialize the machine. When you are finished, you can click on the ``Exit'' button in the upper right-hand corner to restore the machine to the original state.
The password for the ecf account in GB251 will be changed regularly. Your TAs will announce the new password each week. You should only use the GB251 room during your lab period -- at all other times, you must use the ECF rooms SF1012 and SF1106.
This is how you get your account name if you have never logged in before. If this doesn't work for you, go to the ECF office. It doesn't have a room number on the door, but it is located on the first floor of Galbraith in the South hallway, near the First Year office.
Below is what you will see on the screen. The text you enter is displayed in bold, and you should replace it with your actual student number, name, and birthdate. In this contrived example, my initial password would be 43210108. You'll learn how to change it later on in this lab.
Please enter your student number: 0978654321
Please enter your last name: Lemieux
Please enter your date of birth as YYMMDD: 990108
Your ECF login name is: lemieux
After logging in, the "X Window computing environment" is automatically started. You will see as you progress in this course that the X Window environment and the UNIX operating system is a powerful one to work in because of the ability to have the computer do different things at the same time, a concept known as multitasking. You can even run programs on different computers and have their windows appear on your screen. The X Window environment also allows you to conveniently organize the windows on the screen. For now, we will learn the basics about manipulating windows. Some additional information can be found in Section 4.3 of the manual.
The manipulation of windows on the screen is accomplished mainly through the use of the mouse. If you are not familiar with how to use a mouse, you may want to ask your neighbour or the teaching assistant (T.A.) for a quick demonstration and some help with the terminology that follows.
The following intructions apply to the ECF terminal rooms, SF1012 and SF1106. If you are in GB251, window manipulation and logging out is slightly different. Be sure to ask a TA for help if you are having trouble.
When X Windows starts up, there will be a single window on the screen that appears like the one in Figure 1. There may also be a smaller window titled ``Message of the Day''. After you read this, close it by clicking the ``Close'' button. From what is written in the title bar, the thin rectangular box at the top of the window, we can see that this is the Login Session window. A window can be moved around on the screen by clicking on the title bar and dragging it to another location. Give this a try. Note to GB251 users: you will need to use the middle mouse button to move a window.
You can also change the size of a window using the mouse. Move the cursor to a corner of the window. You should see the cursor change to an L-shape that aligns with the corner of the window. Click the mouse and drag the cursor away from the window, then release the mouse button. This action increases the size of the window. The window could similarly be decreased in size by dragging the edge of the window inward. At the top right of the window are two little boxes that are also used to control the size of the window. Clicking the box on the right maximizes the window so that it occupies the entire screen. Clicking this box again returns the window to its original size. The other little box is used to reduce the window to an icon. Click on this box to iconify the window. The icon can now be moved to another location on the screen by clicking and dragging it. Reducing windows to icons is an important way to organize the screen when you are working with many windows. You can restore an iconified window to its original size and location by double clicking on the icon. Note to GB251 users: resizing a window works slightly differently, ask your TA for help.
Now look inside the Login Session window. The computer may be asking you if you want to read some messages. It is expecting you to respond with y, n, or q. Enter q to quit. You should see some introductory messages about the system followed by the UNIX prompt:
The prompt will be some variation of this depending on the name of your computer. You can issue commands directly to the UNIX operating system at this prompt. In this assignment, the commands that you are to enter are shown in boldface. The first command you will enter will tell UNIX to create a new window. Move the pointer with the mouse so that it is on top of the Login Session window and enter the following command:
The xterm command stands for X Terminal and it creates a window which, like the Login Session window, has a UNIX prompt at which you can enter commands. You can now use either the Login Session window or the new xterm window to issue UNIX commands. You can create additional windows with the ``xterm &'' command if you like and have several windows on the screen. Despite having many windows on the screen, only one window is active at a time. The active window has a highlighted border, and all text typed at the keyboard is directed to the active window. You can make another window active simply by pointing inside it.
Sometimes, windows will be partially or completely hidden behind other windows. To bring a window to the top, point at its title bar and click the left mouse button. To push a window to the bottom, point to the title bar and click the right mouse button. Practice these techniques by overlapping your windows and raising them and lowering them in turn.
A window is closed by double clicking on the small box at the top left corner of the window. Try this on an Xterm window. Do not try this on the Login Session window, because if you do, you will be logged out of the computer. For this reason and others, it is good practice to iconify the Login Session window and to work in other windows, so that the Login Session window is kept intact.
When you create new windows with the xterm command, the ampersand (&) is an optional component of the command. By default, commands are executed in the foreground. Adding an ampersand to the end of a command instructs UNIX to execute it in the background. What does all this mean? Commands that are executed in the foreground must complete execution before the command line that started it can do anything else. So if you call up a new window using the xterm command and do not include an ampersand, you will not be able to use the window from which you called up the new one until the new xterm window is closed. When a command is executed in the background, the command line from which it was called can continue to accept commands while the background command is executing.
When calling up new windows from the command line, you should always add an ampersand at the end of the command so that you can use both the new and the original windows. Try calling up new windows using the xterm command with an ampersand and without an ampersand and observe what happens in the original window.
You will be writing your Java programs on the main compute server, skule.ecf. To start a new window on skule using X windows, move the mouse pointer over to the main background and press the mouse button down. A pop-up menu should appear. Keep the button pressed, and move the pointer down to the ``skule.ecf'' option if you are in SF1012/1106, or to the ``xterm 24'' option if you are in GB251.
At this point an important task that you must do is to change your password. Remember that the password to your account is the only security measure keeping your account private so you should choose your password carefully and keep it an absolute secret. You change the password by using the passwd command. Your password should be at least 6 characters long, with 7 or 8 being preferable. Try to use a mixture of numbers and letters in both upper and lower case, making it less likely that someone will be able to guess your password. In particular, do not use any single words that could be found in a dictionary or names. Since computers are good at tedious tasks, people have written programs that can try to guess your password using a dictionary and other guessing schemes.
When changing your password, a new window on skule.ecf may start up. The new password dialog should look something like this:
spark1.ecf% passwdAs you type both the old and new passwords, the characters will not be visible on the screen. This is deliberate, to prevent others from seeing your password by looking over your shoulder. Because you cannot see your password, you are asked to type it twice, on the theory that you are unlikely to make the same typing mistake twice.
Changing password for <your login name>
Old password: <type in your current (old) password here>
New password: <type in your new password here>
Re-enter new password: <type in your new password again>
Data and programs that you use are stored on a disk into what are called files. There are many types of files. Some files are software programs that can be executed, other files contain text that can be read, while other files contain images that can be displayed on the screen. Two things that all files have in common are that they can be stored in computer storage, and that they all have a name. We will soon take a look at some files in the computer system. As we add more files to computer storage the number of files grows to the point where it is hard to keep track of them all. For this purpose, files are organized into directories. You can think of directories as being like file folders. File folders are used to organize papers and articles and things and are named according to their contents. You may well be familiar with the concept of folders from Windows or Macintosh systems. In UNIX, folders are called directories.
If you mapped out the directory and file organization onto a graphical representation, you would get a tree-like structure as shown in Figure 2. At the top is the root directory. It is represented by a slash character, which is its name. The root directory may contain files, and it will also contain other directories. The files and directories within the root directory are shown as nodes below and attached to the root directory. These directories may have files and other directories contained within them and these are shown as nodes below and attached to the parent directory. This pattern can be repeated many times.
It is the files that are actually important when it comes to running programs, whereas the directories are only there to organize the files. When you want to work with files, you generally have immediate access to the files in one directory only. This directory is called the working directory. To find out what the present working directory is, type in the following command:
UNIX will respond with a string that looks like /u/0T3/yourLogin. This string describes a path through the directory tree from the root directory to the present working directory. Reading it from left to right, the path starts at the root directory, which contains the directory named u, which contains the directory 0T3, which contains the directory with the same name as your login. What this string is saying is that there is a directory with the same name as your login name and it is located in the path described above and it is the present working directory.
You can change the present working directory using the cd command. The cd command takes an argument, which is an extra term that is input after the command. In this case the argument is the path of the directory that you want to change to. There has to be a space between the command and the argument. Try the following:
Then enter the pwd command. You will see that the present working directory is as you have requested - the root directory. Now try the following:
Entering the pwd command will show that you are now in the directory requested. Finally, enter:
and this will take you back to your home directory as you can verify using the pwd command once again.
Up until now, we have been specifying the path from the root directory to the desired directory as the argument to the cd command. This is called the absolute path. It is not necessary to always give the absolute path as the argument and usually, one does not do so. Rather, one can use what is known as a relative path. Try this, go to the root directory by entering cd /. Now go to the u directory by entering the following command:
If you do a pwd command, you will see that you are now in /u even though you didn't have the slash beginning the argument of the cd command. Because the argument did not begin with a slash, UNIX understood you to mean go to the u directory from the present working directory, which is /. Now try to go to the 0T3 directory by entering:
Again, if you enter the pwd command you will see how you have moved into the new directory.
There are two important short-forms that are used to specify directories. Two consecutive periods (..) refers to the parent directory of the current directory, so if you use the command cd .. the parent directory will become the working directory. The other important short-form is the ~ character, which refers to your home directory. No matter where you are in the directory tree, entering cd ~ will make your home directory the working directory. With the cd command, you can get even simpler than that and enter just cd to make your home directory the working directory. Practice using these short-forms. First, enter a command to go directly to your home directory (cd ~ or cd), then back up the directory tree, one directory at a time, using cd ... Then return to your home directory once again.
Now you should have a good understanding of navigating around directories. But of course, the interesting part is not directories, but what they contain. To determine what a directory contains, one uses the ls command, which stands for ``list'' and instructs UNIX to list the contents of the directory, which will include any files and subdirectories. Now let's see what we can find using the ls command. Go to the root directory and enter:
You will see some strings arranged in columns. The ls command is displaying the names of files and subdirectories contained in the root directory. Try using ls in the /u directory, and in other directories if you wish. Now go to your home directory and enter ls. There is probably no output. This is because as a new user, you have not created any new files or directories. However, even though ls does not show you any files in your home directory, there are some there that are hidden. To show all the files, including those that are hidden, enter:
Some filenames will be displayed. The names of hidden files are easily distinguishable as they all begin with a period. When your account was created, your home directory and a few hidden files were automatically created for you. These files are hidden because you would not normally work with them as you would with your program files. Hidden files usually contain special information for the computer system on various things like how to set up your screen display, or how to respond to your commands. You may want to explore some of these files and determine what they do some other time.
One last variation on the ls command that you will probably find helpful is:
The final l stands for long form and entering this command will show all files and directories with more descriptive information for each item. A concise summary of directory and file organization can be found in Section 5.3 of the Getting Started With UNIX manual.
In the previous section, it was shown how to explore the directory tree and how to look at existing directory contents. Now you will learn the basic commands for changing directory and file organization. For the most part, this will be constrained to directories and files within your own home directory.
Changing the directory tree structure is accomplished through the use of two basic commands: one that creates new directories, and one that destroys them. The mkdir command makes a new directory. To illustrate its use, go to your home directory, then enter
spark1.ecf% cd ~The argument supplied with this command is the name of the new directory, ``aps105''. You can verify that a new directory was made by using the ls command. Notice that by default, the new directory is placed within the present working directory.
spark1.ecf% mkdir aps105
Removing directories that are no longer required is just as easy. To do so, you go to the directory in which the unwanted directory is contained, then use the command:
However, a directory cannot be removed unless it contains no other files and no other directories.
Basic file manipulation is achieved through the commands that copy, move and delete files. The cp (copy) command is used to make a duplicate of an existing file. It takes two arguments: the first argument is the name of the file to be copied, the second argument is the new name of the new duplicate file. In your home directory, enter the following command:
This command has made a copy of the hidden file ``.login'' and called it ``new.file'' which is not a hidden file because its name does not begin with a period. Verify that the copy was made using the ls command.
The mv (move) command changes the name of a file, and can also move a file into a different directory (the latter will be discussed in a few paragraphs). Try the following:
Again, the ls command will show you the change that was made.
Finally, files can be deleted by using the rm (remove) command. Delete the new file that you created with the following:
Up until now, the file and directory manipulation commands have been demonstrated to operate only within the present working directory. These commands are in fact more versatile than this because it is possible to work with files and directories other than those in the present working directory. To work with a file or directory outside of the present working directory, you must supply its path rather than just its name for the command argument. Absolute or relative paths can be used.
For example, cp can be used to make a duplicate of a file that is not within the present working directory. Use the following command to copy the Java program Hello.java which is located in the directory /share/copy/aps105 to your home directory:
The first argument of the command is the absolute path of the Hello.java program file. The second argument is a period. This is a commonly used short form that represents the present working directory. UNIX interpreted this command to mean place a copy of the file Hello.java (located in /share/copy/aps105) in the current directory and give it the same name (Hello.java). Now try using the mv command to place this file in the aps105 directory you created earlier:
The mkdir, rmdir, and rm commands also can take paths as arguments. Experiment with these commands some more until you get the hang of it. Use Section 5.3 of the UNIX manual as a reference.
Now try to compile the Hello.java program. From a skule.ecf window, go to the aps105 directory and start the Java compiler by typing:
You run this program by starting the Java interpreter as follows:
You should see the output of the program, saying Hello world!
The most basic and most important files that you will be working with are text files. A text file consists of readable text that can be created using the keys on a standard keyboard. Text files are used for various purposes so you will want to have a good knowledge of how to work with them. In this course, you will be making text files that will serve as Java programs.
You can create or make changes to a text file using what is called a text editor. There are several text editing programs available for use on the computer network. The simplest editor to use is called xedit, and it is described below. The editor you should learn to use for your assignments is called nedit, and you should try using it as well. Call up xedit on your computer using the command:
The xedit window that pops up is a different kind of window from the xterm windows we have been using. This window is specifically designed for editing text files. There are four sections to this window. The bottom section is a large empty box and it is here where the text file is composed. xedit starts up with this section cleared so you can create a file from scratch.
Let's create a simple text file. Move the mouse so that the cursor is pointing in this section. Then write some simple text in this box such as your name or ``testing testing 1 2 3...'''
At the top of the window is the filename section. There are three boxes at the left with the words ``Quit'', ``Save'' and ``Load''. Beside this is an empty box. This is the space where the name of the file is specified. Because this is a new file, it has yet to be named. Point the cursor inside this space and type ``test.txt'', then click on the Save button. You have just created a new text file. Now click on the Quit button to close the xedit window.
To see that a new text file was created, go to the xterm window and enter an ls command. The file test.txt should appear in the directory listing.
Open up an xedit window again using the command written above. Besides creating new files, xedit can be used to change existing files. In the filename space, type ``test.txt'', then click on the Load button. The file you created is loaded into the text file section. You can now edit the file. Point with the mouse just after the first ``testing'' word and click. Now press the Backspace button on the keyboard several times until the word is erased. Now, type in the word ``Editing''. By clicking on the Save button, you can save the changes you have made. Finally, click the Quit button to exit the editor.
Other editors you may want to try out are nedit or jove, which are also for beginners, and vi or emacs which are for more advanced users.
Editors are useful for creating and editing text files, but if you just want to read the contents of a text file, you can use one of several UNIX commands at an xterm window. This saves you from having to start up a text editor to view the file. The most convenient command for typing out a text file is the more command. Entering more along with the text file name as an argument types out the file in the xterm window, one screenful at a time, if the file is longer than one screen. You can advance through the file by pressing the space bar. Try using the more command as follows:
For information on other commands that handle the contents of files, see Section 5.4 of the manual.
Electronic mail is now the primary method of communication in our industry (Electrical and Computer Engineering) and pretty much the entire modern world. You may well find that much of your working day consists of dealing with ``e-mail.'' Experiment with e-mail by sending a letter to a friend or to someone sitting close by in the lab. Your e-mail address is
Find out what his/her login is. Now, you can send them e-mail either by by following the instructions below (to use a very simpler mailer), or by starting the pine program, and using the arrow and enter keys to read the "help" section.
spark1.ecf% mail <yourFriend'sEmailAddress>
If their account is also on the ECF system, you can drop the @ecf.utoronto.ca part.
If at any time while you are composing the letter you decide to cancel it, enter CTRL-C twice; that is, hold down the CONTROL or CTRL key (as you would the shift key) while typing in a C.
If someone has sent mail to you, UNIX will notify you with the message ``You have new mail'' when you login. To read new mail, enter the command:
The UNIX mail facility will display to you a list of the letters waiting to be read. For each letter in the list, the sender's login and the letter's subject will be displayed. To read the letters all you need to use is the Enter key and the space bar. Press Enter to display the first letter in the list. If it can't completely fit on the screen, you will see only one screenful and a "more" prompt; the space bar will show you the next screenful. When that letter is completed, you can press Enter again to read the next one. This is the most basic way to use e-mail, but more control over the program is possible. For more information, read Section 5.13 in the manual.
You will soon realize that e-mail is the most reliable method of getting in touch with others on campus, and by way of the Internet, with users of computer networks all over the world. In order to send e-mail to a user on another computer network all you need to know in addition to the user's login is the Internet address where he/she can be reached. When you send mail, you append the address to the login as follows:
Mail is used of course for more than just sending friendly letters. It is the easiest way to get in touch with professors, technicians, T.A.s and others if you have questions or requests to make. Make sure that you get the e-mail addresses of the professors and teaching assistants of your courses. If you have suggestions about APS105, mail a message to Guy Lemieux, lemieux@ecf.utoronto.ca.
The mail command is actually a very primitive mailing tool. Our system offers several, better alternatives that may take a little bit of learning. Try the pine mailer or elm. You can learn about these mailers using the man pine or man elm commands, and also asking the programs themselves for help, using their internal help commands.
You have no doubt read something about the world wide web, and maybe have used it already. To use it on our system, start up the netscape program by typing in a window:
After a delay, you should see a window asking you if you will accept various terms and conditions. Read it and then click the OK box if you wish to proceed. You should note that there are two versions of netscape on the system: the spark systems use the older version (3.0), and skule uses the newer one (4.51). The older version works fine for most things, but when you are writing Java applets you should use the newer version.
A rather colourful and complex window will appear. In the box next to the word "Location:" click the mouse, and erase what is there using the backspace key. Then type:
Press the return key. This will lead you to a tutorial on how to use netscape to explore the world-wide-web. The basic idea is to click on underlined text items, and this will take you somewhere else. Click on the "what is a hyperlink" text at the bottom.
You should check out the home page for this course, located at:
You'll be able to find this assignment by following links on that page.
Click on the "What's New?" and "What's Cool?" buttons in the Netscape window to see a selection of interesting things to look at.
Click on "Net Search" to search the web. Type your favourite topic into the search engine text box, and see if you can find what you like.
Check out the Engineering Computing Facility site:
which has all sorts of information about ECF facilities. You can go to this site by typing the above address into the text window at the top of netscape window, and then typing return.
You can begin creating your own web space on ECF right away. At the UNIX prompt, type:
skule.ecf% cd ~A series of instructions will appear on the screen telling you that the space was created. You can visit your home page using netcape by replacing lemieux with your login id:
skule.ecf% wwwinit
The default web page is rather generic and bland. You can customize it by editting the HTML files in your web space. Go into your web space and edit your master web page by typing:
skule.ecf% cd ~/public_html
skule.ecf% xedit index.html
For further information, visit the following link: http://www.ecf.utoronto.ca/~aps105/www.html
There are two ways to participate in the course newsgroup, using pine or netscape. If you do work from home often, you should learn to access the newsgroup using pine (from within your telnet program under Windows). While you are at school, you can use netscape.
Start pine by typing pine. A menu will come up, choose L for FOLDER LIST. Now you are presented with two options, to see your saved mail folders or to see the newsgroups. Using the down arrow, move to the second option under News-collection. You should see the menu at the bottom of the screen change, and the word ``Subscribe'' should be next to the letter A. Press the A key to Subscribe to a new group. Enter ut.ecf.aps105 as the newsgroup name and press ENTER. You have just subscribed to the course newsgroup!
Press ENTER again to see the newsgroup in the expanded list. If you have more than one newsgroup, they should all be listed. Select ut.ecf.aps105 and you have just entered the world of Usenet! There should be a welcome message posted to the newsgroup, plus may be some other recent announcements.
Reading news from netscape is easier. Just visit the course home page and then click on the newgroup link. Be sure to read the newsgroup warning given on the first day handout: accessing news from outside ECF may not work properly. In particular, you may be able to read some messages, but messages you post from outside ECF may never come back in to ECF.
To post news from netscape, first visit the newsgroup, then click on the New Msg icon at the top. The first time, you will likely get an error about an incorrectly formed mail address. To fix this, go to the Edit menu, and select Preferences. A dialog will appear, in which you should select the Identity option under Mail & Groups on the left hand side. Then go to the E-mail Address box on the right hand side and add the missing @ecf.utoronto.ca part to your e-mail address. You should then be able to post using the New Msg icon.
This tutorial has covered a lot of ground but it is only the tip of the iceberg. You are encouraged to continue learning about the UNIX operating system and the computer network. First of all, learn in greater depth about the topics that were covered in this assignment from the sections of the ``Getting Started With UNIX'' manual that were referenced in the tutorial. Practice and experiment with the various commands and techniques. You will eventually want to learn most of the information presented in the manual. Sections 1 through 4, sections 5.1-5.5; 5.8-5.15; and Section 9 are of immediate interest to all users. You may also want to explore some of the program packages on the system in Section 5.7; the facilities used on the Internet such as News, ftp, telnet and the World Wide Web in sections 5.16-5.18; or the vi editor in Section 6.
If you want in-depth information on any particular UNIX command or program used on the system, use the man (manual) command, with the command or program name as the argument. For example, enter
to get information on the ls command. As the information is displayed, you will see -More- written at the bottom of the screen. At this point, you can press the space bar to display the next screen, or press q to quit.
When you have finished your session on the computer, you must logout by entering the following command in the Login Session window:
If you forget to do this, someone will be able to get unauthorized access to your programs and other files after you leave the terminal. They could get you in BIG trouble.
If you are in GB251, you must click on the large Exit button in the upper-right corner of the screen.