| |
In this lab we will practice using emacs and some basic Unix commands, just to start getting the
hang of things.
- Log in to your Orion account.
- Copy the file
story01.txt from the CS 5 directory to the directory you are in using the command:
cp /home/cs/cs5/story01.txt .
Don't miss the little dot that is the second argument to the command. It stands for "the directory I am in now".
- Load the file into Emacs using the command:
emacs story01.txt
and make the following changes to the file:
- Delete the last paragraph, by using ctrl-k on each line. (Ctrl-K is the
"kill line" command in emacs. Keep holding down the control key and hit the "k"
key repeatedly until the paragraph is gone.)
- Put the paragraph you just deleted after the first paragraph. Do this by going to the
beginning of the second paragraph and typing ctrl-y (for "yank"), which pastes the last killed
block.
- Now let's use the search command, ctrl-s. When you type this, you
get a prompt to enter what you wish to search for. As you start typing, emacs will immediately take you to the next bit of text that matches as much as you've typed up to that point. This is called an "incremental forward search". Let's search
for all instances of the name Jack. Go to the beginning of the story and start the search command. Once you've found the first instance of the word "Jack", repeat the search, by just continuing
hitting ctrl-s. Emacs will repeatedly find the next instance of the text you are searching for.
The "incremental backwards search" works the same way, but is invoked with ctrl-r.
- Save your file (remaining in emacs) by typing ctrl-x then ctrl-s.
- Change all instances of the name Jack to your name. To do this use
the find and replace command. Type esc-x and then the text
replace-string. You will be prompted to enter the text you wish to replace
and then the text you wish to replace it with. Emacs will then do all the replacements at once.
If you prefer to be asked whether to replace
each occurence, then, instead, type esc-x followed by query-replace (or just
esc-%).
Note, for all of these commands, make sure that you are at the
beginning of the file. Otherwise they will only effect the part of the file below the point the cursor is at.
- Use ctrl-x and then ctrl-c to quit emacs. You will be asked if you wish
to save this file. Save it by typing "y ", and then emacs will exit.
- Look at the contents of the file you just edited by typing:
cat story01.txt
at the unix prompt.
- If the whole file didn't fit on your screen, view the file screen-by-screen by replacing
cat
with more in the last command.
- Print the story to the printer in the lab using the
print command:
print story01.txt
- Change the name of the story you just edited. Do this by using the move
command
mv story01.txt newfile
where newfile is whatever name you want to give the file.
- See who else is on the system: try these commands:
who and w and users.
- Try the
date and uptime commands.
- Find out when your instructor was last on the system. Type:
finger name
where name is your lab instructor's last name.
- Get some information about a unix command by typing:
man command
where command is the command you want help with.
Try getting information about some of the unix commands you just used.
|