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 on-line 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 path name 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 web page to be your homepage. Under the Edit menu, select Preferences. The preferences dialog will open, and you should see a text box 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 on-line version of this document. Most labs will contain links that you need to follow, so in general you will use the on-line 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. Some commands that are commonly given to the Linux operating system are for interacting with the file system. All of the files in the Linux file system are contained in directories and all directories (except for the root) are contained in other directories. 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 explicitly 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 path name of your home directory. Every user has a home directory that is the same as you're log-in name. You are always in your home directory when you first log in. A full path name is a list of directories from the root that specifies where a file is located. A relative path name is a list of directories from the present working directory that specifies where a file is located.

  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 path name 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, 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.

    The file permissions of each file are the sequence of 10 characters that are displayed in the first column. File permissions are used to control access to a file. Permissions can be used to prevent someone else from reading your private files, or allow someone else to edit files you are collaborating on.

    The permissions -rw-r--r-- are for a regular file where the owner has read and write permissions (the r and w) but not execute permission (the -) and both the group and all others have only read permission.

    The permissions drwx--x--x are for a directory where the owner has read, write and execute permissions but the group and others have only execute permission.

    Note that some of the file names show up blue and some are white (you will see two more colors if you scroll up - green and light blue). What do you notice about the permissions on the blue files versus the white ones?

    ____________________________________________

  5. Now change to the “bin” directory. Recall that bin is a sub-directory of root – but we are now down one level in etc (see diagram in 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 file name 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 path name 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 sub-directories 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 sub-directories 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 sub-directory 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, because 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.)