PHYCS 3730/6720 Lab Exercise

For those questions requiring an answer, please put your answers in a file called Mylab01.txt. Note that for this lab Exercises 1, 2, and 3 have nothing to hand in. So you will first create this file in Exercise 5, add to it in Exercise 6, and edit it in Exercise 7.

(These exercises courtesy Ben Bromley.)


Exercise 1. Lesson navigation buttons

Find the Physics computer lab manual . Look at the lesson "Logging on and Doing Windows". Play with the navigation buttons in the lesson pages.

Nothing to hand in.

Exercise 2. Desktop window manager: buttons

Learn how to resize, minimize and move windows.
(Lab Manual: Logging on and Doing Windows.)

Nothing to hand in.

Exercise 3. Desktop window manager: root window menu

Start a terminal window using the root window menu.
(Lab Manual: Logging on and Doing Windows.)

Nothing to hand in

Exercise 4. Unix file system: Practice with wild cards and navigation

Read the first part of the Lab Manual lesson "Bare Bones" . From a terminal window, determine your "working directory" (think of this as your location in the Unix file structure) by typing pwd (print working directory) at the prompt. If you have just logged on to your machine or have just opened a terminal application, this directory is your "home directory". (Here it is assumed that your working directory is set to your home directory.)

The result of pwd may be a little long, but after the last slash character /, you should see your username. This long-ish thing, maybe of the form /u/course/myname, is called the "full path name" for your home directory.

You will be doing quite a few exercises in this class, so it is useful to set up directories for organizing them. Let's do this by creating a parent directory called "exercises", which will have subdirectories, one for each lab exercise. So next, create a "subdirectory" called exercises using

mkdir exercises
Check that this was successful by typing ls (the list command). Try some of the variants of the ls command:
ls *
ls -l
ls -la
ls *ses
ls exerci??
ls exerci???

Move to directory exercises by typing the "change directory" command

cd exercises
Then type pwd to verify that you have moved your working directory to exercises.

Type ls. The directory should have no files in it, as this command will indicate.

Create a new subdirectory within directory exercises called ex01.

Change your working directory to this new subdirectory and type pwd. Notice that Unix directory levels are delimited by the slash (/) symbol.

Try moving back to directory exercises using

cd exercises
Why does this fail? Answer: the cd command, when used in the manner just shown, thinks you want to change to a subdirectory of ex01 called exercises. The directory ex01 has no subdirectories; indeed it has nothing in it.

Return to your home directory using cd and the "full path name", that is, the thing that was printed out by the pwd command when your working directory was your home directory (e.g., /u/class/myname).

Note, in unix, all full path names begin with a slash /. In the examples above you used directory names that were not preceded by a /). Instead, you specified a "relative path name": that is a directory whose location is determined relative to the current directory.

Actually, you can get to the top of the whole unix file structure by typing

cd /
Type pwd and an ls to see what file or directories reside here. Don't mess with these! Return to your home by using a sequence of cd commands with relative path names, e.g.,
cd u
cd course
Since getting to your home directory is so fundamental, there are a bunch of ways to do it. The easiest is typing just cd all by itself. Try using the special tilde ("twiddle") ~ character.
cd ~
Note that other users' home directories can be accessed with the ~ symbol. For example, the instructor's account, called p6720, has a home directory of ~p6720, so try
cd ~p6720
Note that the tilde is an abbreviation for the full path to the home directory, so any path beginning with tilde is actually an absolute path.

Finally, you should acquaint yourself with ways to move up the file hierarchy. Two periods, .., will move you up one level. Experiment with this; also try

cd ../..
cd ../../..

When you are done, go on to the next exercise. (There is nothing to hand in here.)

Exercise 5. Unix: Output redirection

Finally, you should be ready to start creating the file Mylab01.txt to hand in. Most of the time you will be creating files with our text editor (emacs). But we haven't introduced emacs yet. So we will pick a Unix command and redirect the output of the command to create the file. Run the following commands to create a file called Mylab01.txt to hand in with a listing of the directory tree you created, together with the sizes of their contents:
cd ~/exercises
du -k . > ex01/Mylab01.txt
Spaces are important in Unix, so pay careful attention to the spaces and the dot here. If you make a mistake, delete the file with the command rm ex01/Mylab01.txt and try again.

What did the above command do? There are several things to notice. First the command du with a flag -k is a Unix "disk usage" utility that tells you what directories and subdirectories you have and what their sizes are in kilobytes. We won't be using it very often in this course. The dot . for "current directory" tells the du command to examine the directory tree descending from the current directory, which should be your directory exercises. Try running just this first part of the command

du -k .
This time the command output is sent to the terminal window. Then examine the contents of your Mylab01.txt file by running the commands
cd ex01
cat Mylab01.txt
Can you see that the > ex01/Mylab01.txt took what would have gone to the screen and put it in the file Mylab01.txt in the subdirectory ex01 instead? That is called output redirection.

Exercise 6. Unix practice: cp, man, mv, grep

This exercise has to do with file manipulation. Use the cp command to copy the file file1 from the ~p6720/exercises/unix_emacs_intro directory to the directory. ex01 that you created above. The syntax for cp is

cp filea pathb
where filea can be any filename (e.g., instead of filea you could have something like /home/data/file.dat) and pathb is a pathname (either a filename or a directory) (e.g., instead of pathb you could give the directory ~/asst01/). When pathb is a directory, the copied file keeps the name of the original file. When pathb is a file, the copied file has whatever name you give it. Tip: Notice that for this exercise the first file in the copy command is not in your local directory, so you need to construct the full file name including the full path. So start with the directory given above, follow with a slash and then the name of the file in that directory. Then the second file in the copy command is not in your home directory. You have a choice here. (1) You could start by first going to the ex01 directory simply using a dot . for current directory. Or you could specify the path to ex01 from wherever your current directory happens to be.

For more details on how to use the cp command (or other shell commands), type

man cp
Push the space-bar to scroll down the "man page". When you are done with man hit q to return to your shell.

Do an ls to make sure the copy worked. Look at the file with the more or less command. (When done, typing q gets you back to your shell.) Also, look at it with the cat command.

Move (mv) (i.e. rename) file1 to the filename filea.

Copy all files of the form file? from directory ~p6720/exercises/unix_emacs_intro to your directory ex01. (As a good habit, you should use ls to see which files are in the source directory before you copy them over....)

Use cat to see what is in these files. Also try out the grep command:

grep jjjj file1
grep Editor file?
grep baboon file*

Before finishing, run the following command to list the files and directories you collected in your home directory and append the listing to the bottom of your answer file Mylab01.txt.

cd ~/exercises/ex01
ls -l level* file* >> Mylab01.txt
The -l is a the lower case letter "ell" and not a 1. Please be sure you type two ">>" to append your result to the file.

What did this command do to the file Mylab01.txt? If you aren't sure, run just the first part of the command: ls -l level* file*. Then run the command more Mylab01.txt. Can you see that the double-arrow redirection >> Mylab01.txt caused the output of the ls command to be appended to the file Mylab01.txt?

Please be sure you know what this command does and what it did to the file, because to do the next exercise you will need to know which lines you just added here. Finally, remove these files with the rm command:

rm file1
rm -f file2
rm file?
Note the (possibly risky) use of the -f directive in the second line.

Exercise 7. Final edit

The purpose of this exercise is to introduce you to the emacs editor and to fix up your file for handing in. The problem here is that your file has results of Exercise 5 and Exercise 6 all run together. For the grader we need to insert the title "Exercise 5" before the lines that came from Exercise 5, and the title "Exercise 6" before the lines for that exercise.

If you need an emacs refresher, please see the introductory section in Lab Manual: Bare Bones.

Then, when you are ready, use the emacs editor to edit the file Mylab01.txt. To do that start up emacs from your shell using

emacs Mylab01.txt &
Note the ampersand indicates that emacs should run "in the background" and should not tie up your shell command line.

Exercise 8

Here you are just asked to hand in your exercise file. Do this by following the submission instructions on the exercise home page .