(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
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 ~
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
ls
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 with these exercises, run the following commands to create a
file called lab01 to hand in with a
listing of the directory tree you created, together with the sizes of
their contents:
cd ~/exercises
du -k . > ex01/lab01
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/lab01 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 lab01 file by
running the commands
cd ex01
cat lab01
Can you see that the > ex01/lab01 took what would have gone
to the screen and put it in the file lab01 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 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.
cd ~/exercises/ex01
ls -l level* file* >> lab01
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 lab01? If you aren't
sure, run just the first part of the command: ls -l level*
file*. Then run the command more lab01. Can you see that
the double-arrow redirection >> lab01 caused the output
of the ls command to be appended to the file lab01?
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.
The purpose of this exercise is to introduce you to the emacs editor
and to fix up your file for handing in.
Please see the introductory emacs section in
Lab Manual: Bare Bones.
Start up emacs from your shell using
emacs &
(or use the desktop Launch menu). Note the ampersand
indicates that emacs should run "in the background" and should not
tie up your shell command line.
Use the pull-down menu bar options ("Buffers" "Files" etc.) to open a new file called newfile. Try typing text into the file's "buffer" and saving it. Then, type cat newfile on your shell's command line and see that the file was saved as expected.
You should read through the Bare Bones lesson about basic emacs operation. You should start learning the emacs keyboard shortcuts to free yourself from the mouse while editing. Some shortcuts are given in the pulldown menus. You will learn more from the emacs tutorial (see the "Help" pull down menu). For example, typing Ctrl-x Ctrl-f (abbreviated C-x C-f) opens a file which emacs uses to create a "buffer" that can be edited. If the file already exists, it will be loaded into your buffer. C-x C-s saves your current buffer to the file, and C-x C-c exits emacs.
When you are ready, use the emacs editor to edit the file lab01. Just insert titles Exercise 4 and Exercise 5 and save it for handing in. The titles should go just before the lines that those exercises added to the file.