Lab 0: Introduction to Linux and Firefox

Lab Objectives

  • Gain exposure to the graphical and command-line interfaces of the Linux operating system.
  • Setup access to online course information through Firefox

Getting started with Linux

The computers in the 2nd floor MCSP lab are dual boot, capable of running Windows 7 or Ubuntu Linux, an open source version of Linux. Generally you will find them running Windows so you will need to reboot into Linux as follows:

After Linux has been loaded you should get a login screen. To log in, click the "Log In" button, enter your username and password (the same that you use to access myroanoke and email). If you ever have password problems, go to Information Technology on 3rd floor Trexler for assistance. You are now logged into the local machine, but you will be storing your files and running programs from a remote computer (named "CS"). This means that you can use any computer in the lab and still be able to access your personal files.

You should see a desktop environment similar to Windows. This is GNOME which is responsible for providing a graphical, desktop interface for Linux. Here are some of the basics for getting around in Gnome.

The GNOME panel can be customized by adding and deleting icons and moving them around. In this course we will regularly use three applications: Terminal (for typing in shell commands), Emacs (a text editor for writing programs), and Firefox (for an online copy of lab instructions). It would be helpful to add icons for these on the panel.

Launch an X-terminal window (an xterm) by clicking the Terminal icon on your panel. You should see a window appear that has nothing in it except a command prompt. A prompt is a special character or sequence of characters letting you know the shell is ready to accept commands - the prompt on the lab machines contains your username, the machine name, the pathname of the current directory and a dollar sign. The dollar sign is one of the standard UNIX prompts. The Linux commands (called shell commands) are typed in an xterm at the prompt -- more on shell commands later.

Now open Firefox using the icon on the panel.

Setting up Firefox

Firefox is an open-source web browser that looks and acts much like Internet Explorer, Safari, or Google Chrome. Open Firefox by clicking on the icon on the panel. First, we want to set the class webpage to be your homepage. Under the Edit menu, select Preferences. The preferences dialog will open, and you should see a textbox for Home Page.

If you are in Dr Ingram's class, type in:

 
http://cs.roanoke.edu/~cpsc/Fall2011/CPSC120B
If you are in Dr. Bouchard's class, type in:
 
http://cs.roanoke.edu/~cpsc/Fall2011/CPSC120A 
Close the dialog and press the Home icon to go to the class web page. Look over the page; note that it contains links to the syllabus, to various useful information, and to the assignments (none yet) and labs. Click on the lab0 link and you'll see the online version of this document. Most labs will contain links that you need to follow, so in general you will use the online version.

Using the Command Line Interface

While pointing and clicking is familiar and fairly intuitive, it is not always the most efficient way to give commands when working with a computer. For this reason, many computer users, especially programmers, prefer to interact with the computer system by typing in commands that explicitly tell the machine what to do. The command-line interface for Linux systems is accessed through an X-terminal(xterm).

Activate the xterm you already have open. The program running in the xterm is called the shell. The shell lets you issue commands explicilty to the Linux operating system and work with files. The following leads you through using some of the basic commands in Linux. Refer to the Linux Command Reference and Linux/Unix Overview handouts given in class as you answer the following questions and type in the appropriate commands to move around the file system. Pay attention to what happens on the screen after each command.

  1. How do you find out "where you are" in the file system? The command is pwd which stands for present working directory. To find out where you are now type pwd

    What is displayed when you type in the command (and press ENTER)?

    ___________________________________________________
    (Note - this should be the full pathname of your home directory - you are always in your home directory when you first log in.)

  2. How do you change to another directory?

    The command is cd (for change directory) BUT you must also type in an argument specifying the directory you want to change to (give either an absolute or relative path to the directory). Note that for any Linux command with an argument you must type a space between the command and the argument.

    Let’s go to the root directory (also known as “/”).
    To do so, you need to type

     
                    cd  /
    

  3. How do you see what files are in a directory?

    The command to see the files in your current directory is ls. To see a list of files in a different directory you need to add a pathname to that directory as an argument.

    Look at the files that are in the root directory (that's where you are!) by typing the ls command.  

    You should see quite a few files including one named etc. It is one of the system directories mentioned in the Linux/Unix Overview handout. Now do the following:

  4. How do you get more information about the files?

    Use the -l option on the ls command; that is, type ls -l (that is an el for long, not a one) to get a long listing of the files.    Type the command to see info about the files in the etc directory. Note that this shows you the permissions on each file (described on the last page of the Linux/Unix Overview), the ownership and group for the file (most of these are root), the size of the file (number of bytes), and the date of last modification of the file.

    Note that some of the filenames show up blue and some are black (you will see two more colors if you scroll up - green and light blue). The file permissions are displayed in the first column (this is the sequence of 10 characters described on page 3 of the Linux/Unix Overview handout). What do you notice about the permissions on the blue files versus the black ones?

  5. Now change to the “bin” directory. Recall that bin is a subdirectory of root – but we are now down one level in etc (see diagram on page 2 of the Linux/Unix Overview). So we can change to root in one of several ways:

    Now type the command to list the files in bin.   Note that a lot of the files contained in this directory are displayed in green.   You may also notice some familiar file names (cp, ls, pwd, for example).  

    Type ls –l and examine the permissions on the green files. What are the permissions for all users?
      What do these (green) files all have in common?   


  6. How do you find permissions for a specific file?

    To do this we need to add the filename as an argument to the ls command. For example to see the permissions on the file cp type:

     
                  ls -l cp
    
    Make a note of what happens (especially the permissions).

  7. How do you go back to your home directory?  

    This is an example of changing directory so you need to use the cd command. As before you could use it with an argument that gives the pathname of your home directory. However, the fastest way to change to your home directory, is to just type cd

    Other options include:

Setting Up Your Directory

Now we'll set up your directory with some subdirectories and copy some files into them. Do the following:

STOP!!! Before going further have the instructor or a lab assistant come over and check to see that you have your directory set up correctly. You will be asked to go to your home directory, show a listing of the files there, then go down into the subdirectories you have created and show what is there.

Using Emacs, the Text Editor:

Launch Emacs by clicking on the Emacs icon (a letter E stylized to look like the horns of a gnu) on the Panel. You will note a menu bar and a bar of icons at the top of the window. These contain pull down menus and icons that you can use to perform many commands. However, every command can also be executed in Emacs using an Emacs function and special keystrokes. Once you become proficient at using Emacs you will probably prefer the keystroke method of giving commands.

Editing an existing file

We'll first use Emacs to edit the UnixQuestions file. To open this file in your lab0 subdirectory do the following:

Now, you are ready to edit. As in a word processor you may move around in the buffer with the arrow keys and with the mouse. Unlike a word processor however you should press the ENTER key when you are at the end of a line. Text editors typically do not provide the same automatic line wrap features that word processors do (though Emacs provides some).

A useful Emacs command: If you ever get stuck halfway into an Emacs command, where the minibuffer is asking for something that you don't understand, type C-g (hold down the ctrl key then hit the g key). This aborts the current command.

Now go to the top of the document and type in your name, then type in the answer to each question immediately following the question.

Save the file by typing C-x C-s (hold down the ctrl key then hit the x key, then release the x key while still holding the ctrl key and hit the s key) OR choose File, then Save (current buffer) from the menu.

Exit Emacs by typing C-x C-c OR choose File, Exit Emacs.

Printing

To print out your answers, use the enscript command in your xterm (shell) window as follows:

enscript -2rG UnixQuestions

This requests that the file UnixQuestions be printed on the lab printer. The additional parameters to the print command tell the printer how you would like the document formatted. Specifically, you are asking for 2 columns, rotated to landscape orientation and add a Gaudy title.

Do not print from within the text editor; always use enscript
Do not print from within the text editor; always use enscript
Do not print from within the text editor; always use enscript

Submit Your Answers

To submit your answers copy your UnixQuestions file to the lab 0 submission directory of your instructor. (~bouchard/CPSC120/lab0 or ~ingram/CPSC120/lab0) Note, you also need to rename your UnixQuestions file so that someone else does not save over your file. It is possible to both copy a file and rename the copy using the cp command. This is done by specifying the location and the new name for the file with the second argument. So, if you are in the directory that contains the UnixQuestions file, you can copy and rename it with the following command:
cp UnixQuestions ~ingram/CPSC120/lab0/YourName
or
cp UnixQuestions ~bouchard/CPSC120/lab0/YourName
Note that you should replace YourName in the above command with your first and last name (without a space in between - for example, johndoe). You can check if the file was properly copied by using the ls command. It is not possible to do an ls on the directory the file was copied to, lab0, becauase you do not have read permission for the directory. You do, however, have read permission for the file that you just copied. To check if the file was copied use the command:
ls ~ingram/CPSC120/lab0/Yourname
or
ls ~bouchard/CPSC120/lab0/Yourname
Again, you should replace YourName with your name. If the above command does not produce an error, then the file was copied correctly.

Exiting an X-terminal: To exit an xterm, type exit at the command prompt.

Exiting GNOME To exit GNOME, click on the power icon (a zero with a one through it) in the upper-right of the screen and choose Restart. In the next window, click the Restart button. The computer will then automatically reboot into Windows 7. (If you choose Log Out from the menu the computer will go back to the Linux login screen.)