Lab Objectives
|
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.
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
http://cs.roanoke.edu/~cpsc/Fall2011/CPSC120A
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.
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.
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 /
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:
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?
____________________________________________
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?
__________________________________________
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 cpMake a note of what happens (especially the permissions).
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:
Now we'll set up your directory with some sub-directories and copy some files into them. Do the following:
________________________________________________
_______________________________________________
Note that we need the path name for the original file (the one we want to copy) and the directory (or file) we want to put it in. The path name 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.
cp ~cpsc/UnixQuestions .
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.
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:
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.
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.
cp UnixQuestions ~ingram/CPSC120/lab0/YourNameor
cp UnixQuestions ~bouchard/CPSC120/lab0/YourNameNote 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/Yournameor
ls ~bouchard/CPSC120/lab0/YournameAgain, 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.)