(These exercises courtesy Ben Bromley.)
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.
Learn how to resize, minimize and move windows.
(Lab Manual: Logging on and Doing Windows.)
Nothing to hand in.
Start a terminal window using the root window menu.
(Lab Manual: Logging on and Doing Windows.)
Nothing to hand in
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
Check that this was successful by typing ls (the list command).
Try some of the variants of the ls command:
Move to directory exercises by typing the "change directory" command
Then type pwd to verify that you have moved your working directory
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
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
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.,
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.
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
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
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
When you are done, go on to the next exercise. (There is nothing to hand in here.)
cd ~/exercises du -k . > ex01/Mylab01.txtSpaces 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
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
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.
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
For more details on how to use the cp command
(or other shell commands), type
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
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 -f file2
Note the (possibly risky) use of the -f directive in the
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.