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:
- Press CTRL-ALT-DELETE, click the red dislosure triangle button in the lower
right, then select Restart from the pull down menu.
- Watch the screen! It does a few things and then displays the
bootloader screen (LILO), with a menu asking which operating
system to load. Use the arrow keys to highlight Ubuntu Linux, then press ENTER.
(If you wait too long, Windows 7 will automatically be loaded!)
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 my.roanoke 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 bar across the top of the screen is the GNOME Panel.
Just as you access programs in Windows from the Start menu, you can access
programs in GNOME by selecting the appropriate menu options on the
GNOME Panel.
You should also see two color icons on the left side of the panel -
one for the Firefox Web browser and
one for GNOME Help. You can hold your mouse over
an icon to get information about it.
- A taskbar is at the bottom of the screen.
It contains an icon for each window that you have open on the desktop.
These are similar to the icons that you see on the taskbar in Windows.
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.
- Add an icon for Terminal to the panel by clicking on the
"Applications" menu option, then choosing Accessories. Right click on
Terminal and choose "Add this launcher to panel."
- A similar process can be used to add an icon for the text editor
"GNU Emacs 23". (Also under Applications, Accesories)
- If you ever wish to remove an icon from the panel, right
click on the icon then choose "Remove from Panel."
Launch a 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.
You should now have two windows open. You can use the mouse to
move and manipulate these windows and open programs in the same way
you do in other GUI environments that you are familiar with.
As in other systems you can also use
key strokes to do many of the same things and often that is faster. Here are
a couple you may find useful.
- Moving Windows: As usual, windows can be moved by
dragging the title bar but an
alternative is to hold down ALT and then click anywhere in the window
to drag it to a new location. This is particularly handy if the title
bar is not visible.
- Activating a Window:
Clicking inside a window or on its
titlebar both activates the window and brings it to the front.
When you have more than one window open it is often helpful to cycle
through them to get to the one you want to work in.
The usual way to cycle through windows in GNOME
is by pressing Alt-Tab (hold Alt down,
then press Tab), just as in Windows.
Now try ALT-Tab; it should cycle through the windows.
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/Fall2010/CPSC120A
If you are in Dr. Bouchard's class, type in:
http://cs.roanoke.edu/~cpsc/Fall2010/CPSC120B
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.
- 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.)
- 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 /
- 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:
- Change
to the etc directory (remember you need to use the cd command AND
give the pathname of the directory you want to change into).
- Type the command to see what is in the etc subdirectory.
- How do I 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?
- 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:
- In two steps - go up one level to root by typing cd .. (remember
.. is the directory up one level from where you are), followed by
typing cd bin.
- In one step with the relative pathname of bin - type cd ../bin
- In one step using the full pathname from the root - type cd /bin
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?
- 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).
- How do I go back to my 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:
- cd ../home/students/username
takes into account your current location. Effectively this will
take you back up one directory, and then down through home/students
- cd /home/students/username specifies the absolute
path that you want to jump to
- Since you are going to the home directory of a
user, you can just type cd ~username
(of course put your
username here)
Setting Up Your Directory
Now we'll set up your directory with some subdirectories and copy some files into them.
Do the following:
- Use the appropriate Linux command to see what is currently in
your directory (you should see one
file named “Desktop” and one named “Documents”
among others). What type of files are these? (Look at the file type
information from the ls -l command.)
- It turns out there are some other files there. These hidden
files are not always
displayed (because you don’t need them all on a regular
basis). How do you list all of the files in your directory?
(Look at the Linux Command Reference for options on the ls command)
Notice that all the “hidden” files start with a “.”
– these are created by the system.
- You need to create (make)
a new subdirectory, named cs120, to store your
files for this class. Look at the command reference
to figure out the command to do this. Please note!!! Linux is
case-sensitive; the directory cs120 is NOT the same as CS120.
It is very important in this class that you type in commands, pathnames and
filenames in the correct case!
List the files now in your directory to be sure you now have the cs120
subdirectory.
- Change directories to the new subdirectory and confirm
that you are there.
(You can use pwd to confirm, but you may notice
that your current directory is also displayed as part of your prompt.)
- Create a new subdirectory named labs
and change to
this directory.
- Create a new subdirectory called lab0 and again
change to this directory.
- Now we want to copy a file called UnixQuestions
from the cpsc home directory to your present directory.
The shell command you need to type must specifiy three pieces
of information:
- The command itself which is cp (for copy) PLUS
two arguments - one the file you are copying and the
other telling the operating system where to put the copy.
See the examples in the Linux Command Reference.
Note that we need the pathname for the original file (the one
we want to copy) and the directory (or file) we want to put it in.
The pathname of the file we want to copy is ~cpsc/UnixQuestions
(because the file is in the home directory of
"user" cpsc).
We want to put the file in the directory we are currently in.
Remember that you can refer to your current
location as “.” - that is, a single dot.
So, the command is
cp ~cpsc/UnixQuestions .
Confirm the file is in your directory with ls.
Go back to the cs120 directory by going
up the tree (remember the directory up one level is referred to
using two dots so changing up one level is cd ..). You
should have only one subdirectory of cs120
at this point (labs).
Create another subdirectory called assignments
We will use this directory later in the term.
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:
- In your Emacs window, use the pull down menu item Open File...
under the File menu, or use the key stroke C-x
C-f   (the C stands for the Control ctrl
key -- hold it down then press the x key, release the x then press
the f).
- Look at the bottom of the window in the minibuffer and you will see
the words Find File: followed by the path of the directory
you were in when you started Emacs (probably "~/", that is, your home
directory). You need to specify the path for
the file you want to open
to edit. If you have correctly created your subdirectories,
the file should be in ~/cs120/labs/lab0/UnixQuestions. (Remember
that this is the same as /home/students/yourUsername/cs120/labs/lab0/UnixQuestions
because ~ stands for your home directory.) Type this into the minibuffer (don't
type the ~/ again if it's already there) and press ENTER and you'll be in a buffer
containing the file. The file
name corresponding to the buffer will appear near the
bottom of the window on the status line.
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).
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.)