Getting Started
There several ways to access Unix machines in the SIMS
environment. (We will be using Solaris Unix, because that is the Unix that
runs on the Sun machines that we use in the lab. FYI, Linux is an increasingly
popular form of Unix and we might have this in the lab in future. The differences
between these are supposed to be unnoticable, so you don't really need
to worry about this.)
For the work in this course the following method
of accessing Unix should work fine. On an NT machine, access the SecureCRT
program at
Start\Programs\Internet\SSH-Telnet\SSH-info.sims
(You shouldn't use irony.sims for this assignment, as
it is used for other purposes. This is the secure version of telnet we're
supposed to use now. It encrypts your password over the network for you.)
You'll get some dialog boxes the first time you run
this. Go ahead and make it your default telnet application in the first
dialog box, and select Accept & Save in the second box. After this
first time you won't have to repeat all these commands.
Once you're past all the dialog boxes, you'll get
a prompt TERM = (xterm). Just hit Return when you see this. Now you're
logged into a unix machine (called info.sims).
This is a very nice version of telnet. You'll notice
the command menu at the top allows you to do cut and paste, change the
keyboard mapping, and many other things.
Learn Unix
Read the information on Basic UNIX File Manipulation
at http://socrates.berkeley.edu/Help/Unix/basicunix.html
Now do the following operations (after each
task I show the appropriate unix command in italics).
-
Create a new directory called stuff
-
mkdir stuff
-
Make stuff your current directory
-
cd stuff
-
Print the current directory
-
pwd
-
Create a new file called greeting containing the word
"hello"
-
echo "hello" > greeting
-
Look at the contents of the file called greeting
-
more greeting
-
Copy this file to another file called greeting2
-
cp greeting greeting2
-
Remove the first file
-
rm greeting
-
Move up out of this directory to your home directory
-
cd ..
-
Check that you're really in your home directory
-
pwd
-
Look at the files in this directory in more detail
-
ls -l
Unix has online manual pages, called man (everything
gets abbreviated, in case you haven't noticed, to reduce typing).
-
Try out the man command at the Unix prompt.
-
See what that more command was we used earlier.
-
man more
-
(The stuff under Synopsis indicates the different arguments
that you can give to different variants of the command.)
-
Find out how to make ls show you files whose names begin
with a . (a period).
-
man ls
More info on
man
pages.
Now read about
running
jobs and processes, redirecting
input and output,
connecting
commands together, and using
wildcard characters.
If you'd like more references, there is a list of
recommended Unix guides at http://wss-www.berkeley.edu/unix/faq/books.html
Learn Emacs
Now learn some basics about the emacs editor. Emacs
has a huge range of functionality but you only need to know the basics
to get started. (Its name stands for Easy Macros.)
Emacs makes extensive use of the Control key, which
can take getting used to. Something written as C-x C-c means first hold
down the control key and press x (while still holding down the control
key) and then do the same thing with control and c. (You can keep the control
key held down for both the x and the c.)
You can run emacs from the Unix prompt by simply
typing Emacs. This puts you in a buffer called *scratch*, which is temporary
scratch space.
You save a buffer's contents into a file by typing
C-x C-s.
You can get out of emacs by typing C-x C-c.
Undo the previous command with C-x u
(This means hold down control and x at the same
time, then release the control key and hit the u.)
The Meta key (usage is written M-x, for example)
is either the Alt key or the ESC key; you'll have to test it out on your
system.
First read an emacs tutorial, for example
http://yoda.cis.temple.edu:8080/UGAIWWW/help/emacs-tutorial.html
Now use tutorial materials prepared by Armando Fox.
Go back to the unix prompt and do the following commands.
-
Go to your home directory.
-
Make a directory called emacs-tutorial
-
Copy the files from the directory /www/docs/courses/is202/f00/emacs-tutorial
into your emacs-tutorial directory.
-
Move into your emacs-tutorial directory.
-
Check that it is really your directory (use pwd).
-
Now read the contents of the file called README (use
the more command) and follow the instructions there for how to run the
emacs tutorial.
Especially Useful Emacs Commands
Below I list what I consider to be especially useful
emacs commands, omitting emacs macros, which get their own section, below.
-
Search in the buffer. After you type the command, start
typing in the letters of the string you are searching for. After you find
the first hit on the string, you can type the command again and get the
next and subsequent hits. When you get to the end of the file, the search
begins again from the top of the file.
-
C-s
-
Replace string. I use this every day. It lets you replace
one string of characters with another in the current buffer. After you
type the command you enter a dialog with the system and it asks you what
pattern you want to replace with what other pattern.
-
M-x replace-string
-
Query replace. I also use this every day. It's like
replace-string except it pauses before each replacement and asks you if
you want to replace that particular instance of the string. This is useful
because sometimes it's hard to specify exactly the pattern you want to
replace. If you want to replace the string you hit Return, otherwise you
hit "n" (for no).
-
M-x query-replace
-
Help: This gets you into the comprehensive online help
facility.
Here is a nice webified description
of the help options.
-
C-h ?
Emacs Macros
There are some aspects of Emacs that make it especially
useful and worthwhile learning. Probably the most powerful is the ability
to write macros on-the-fly to do repetitive editing work for you.
The main idea is that you can ``capture'' a sequence
of emacs commands and have the system repeat this sequence over and over
again for you. Here's how it works.
-
Tell the system you are starting to create macro.
-
Type C-x (
-
Now the system is recording the commands you type next.
So type in the sequence of commands you want the system to record to be
reused later.
-
Once you're done with the commands
-
Type C-x )
-
Now you've defined a keyboard macro. To tell the system
to re-execute the sequence of commands,
-
Type C-x e
-
You can tell the system to re-execute the command any
number of times. Say you want to re-execute it 10 times.
-
Type ESC 10 C-x e
-
You can save macros to be reused later by assigning
them a name with
-
M-x name-last-kbd-macro
Emacs Initialization File
You probably want to create a customized startup file
for emacs. You save this information in a file called .emacs in
your home directory. You can store macros in this file and tell the system
what mode to start up in by default. Here are some lines from my startup
file along with notes as to why they are there
-
This gets rid of that annoying startup message:
(setq inhibit-startup-message t)
-
This means set Auto Fill mode to be true. In Auto Fill
mode, inserting a space at a column beyond `current-fill-column' automatically
breaks the line at a previous space. So it does a nice wrap-around for
you without your having to hit return at the end of the line.
(setq auto-fill-mode t)
-
By default emacs stores a backup copy of every file
you edit with a ~ appended to the filename. I don't like this and so I
turn it off.
(setq make-backup-files nil)
-
These next few are more advanced.
-
You can also assign commands to keyboard sequences.
(Be careful -- --you might override a command that does something else.)
For example, I wanted a fast way to tell the system to go to a particular
line number in the file, so I define the following:
(global-set-key "\C-x\C-g" 'goto-line)
Now when I type C-x C-g the system asks me what
line number to go to and then goes there.
-
You can tell emacs what mode to go into depending on
the file extension of the file you are editing. If I am editing a Java
file (whose name ends with .java) I want the system to use java-mode,
if I'm editing a latex file I want it to use latex mode. To tell this to
the system, I put the following in my .emacs file (the formatting is messed
up in html):
(setq auto-mode-alist
'(("\\.c$" . c-mode) ("\\.lisp$" . lisp-mode)
("\\.java$" . java-mode)
("\\.cl$" . lisp-mode) ("\\.html$" . c-mode)
("\\.tcl$" . tcl-mode) ("\\.tex$" . latex-mode)))
Here is one printable reference
card for emacs (in PDF).
Here is another online
quick reference guide to emacs commands.
Here
is a full version of the GNU Emacs Manual