Lab #0: Basic UNIX
Fall 2000
This assignment is in the form of a tutorial and will gradually take you through the basics of interacting with the computer. You may find that this assignment will take longer than two hours to complete. If this is the case, please complete it at another time, but as soon as possible. This lab is not marked.
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 the class handout, 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.
Never give your password or to someone else, or let someone use your account. Doing so is against University policy, and the other user can leave open a ``back doors'' into your account to access it later, even if you 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 (Linux) 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 ecflinux and the password provided by the TAs 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. If you have weird looking windows, exit. Before logging in again, check that ``Basic Unix (TWM) X11'' is selected under ``Options.'' 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: Smith
Please enter your date of birth as YYMMDD: 990108
Your ECF login name is: smithjo
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.
Note to GB251 users: the setup in that lab is slightl different. You should do this lab in the SF rooms until you are familiar with the machines, then try the GB251 room.
When X Windows starts up, there may be windows on the screen, or you may have to create them yourself. The handout from class explained how to log out and save the desktop, which actually saves the windows and their positions for your next login session.
Most of your work will be done using terminal windows. Start a new one by clicking the large taskbar button that looks like a computer screen with a GNOME footprint. A window will pop up, and 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, and new terminal windows are launched by right-clicking on the background.
You can also change the size of a window using the mouse. Move the cursor to the lower-right corner of the window. You should see the cursor change to an L-shape that aligns with the corner of the window. To make it bigger, click the mouse and drag the cursor away from the window, then release the mouse button. GB251: click and hold the mouse button on the square box in the title bar, then drag the window edges wider and release the mouse button. At the top right of the window are three little boxes to control the window. The ``X'' closes the window, the middle one maximize the window size, and the left one makes it disappear. To make the window reappear, click on its name in the task bar. GB251: the icon in the top-right of the window will shrink it down to an icon, and clicking the icon makes it reexpand.
In the terminal window, 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 GNOME terminal window, has a UNIX prompt at which you can enter commands. You can now use either the GNOME terminal 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 by clicking the title bar, the same way Microsoft Windows works. More advanced UNIX users change their settings so having the mouse pointer over a window is sufficient to make it active. To change your setup to this method, you will have to change the focus behaviour of your desktop and window manager, enlightenment.
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. 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.
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, the main server, may start up. The new password dialog should look something like this:
p1.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.
opening window on skule for password change
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 as files on a disk. There are many types of files: some 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 on the ECF 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 1. 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/0T4/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 0T4, 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 0T4 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
p1.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.
p1.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:
Note: currently, the /share/copy directory structure does not exist on the Linux computers, but it does exist on skule.ecf. You can go to the skule.ecf computer by typing ssh skule.ecf on the command line. The first argument of the cd command is the source file, here it contains the absolute path of the Hello.java program file. The second argument is a single period, 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 terminal 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!
Once you have your Java program working, you can submit it electronically to be marked. To submit your lab programs, run the command as follows:
This command will submit the file ``Hello.java'' for lab 0. You can continue to work on your own version of Hello.java without affecting your submission. To submit code for other labs, replace the 0 with the lab number.
You can also submit more than one file, either by running the submitaps105f command multiple times, or by placing all the files on the command line:
If you choose to resubmit a file again after making changes, the older version is replaced with the newer one. However, you can never erase files once they are submitted. If you wish to give the marker specific instructions (please, keep these to a minimum!), submit a file called README with your note typed inside it.
To view the list of files you have submitted for lab 0:
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 pico, 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, but most UNIX systems have a better version of more, called less. Entering more (or less) 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. 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.
p1.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.
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 (the outdated predecessor to pine). 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.
Sometimes you will not be able to use the large ``N'' button on the task bar to start netscape. For example, GB251 users will not have the task bar on their screen. In these cases, you can start up the netscape program by typing in a window:
After a delay, you may 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 different versions of netscape on the system: the Linux PCs have the latest, skule uses a slightly older one (4.5), and the spark systems have very old versions (3.0). The older version works fine for most things, but when you are writing Java applets be sure to use the latest version.
When the main netscape window comes up, try typing a new site in the ``Location:'' box, such as:
or try a search engines:Press the return key. This will lead you to either an old tutorial on how to use netscape to explore the world-wide-web, or to the Google search engine.
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 on skule, 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 login 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% nedit index.html
Forch further information, visit the following link:
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/ssh 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.
Don't forget to log off when you're done!
If you forget, someone will be able to get unauthorized access to your programs and other files after you leave the terminal. They may even leave ``back doors'' open to regain access to your account after your password is changed. They could get you in BIG trouble, so always ask a sysadmin for help when you think your account is no longer secure.
If you are in GB251, you must click on the large Exit button in the upper-right corner of the screen.