Applied Physics 461b/861b
COMPUTATIONAL PHYSICS
Introduction to UNIX and vi
Working on mercury
- access is through telnet mercury.yale.edu. If you have a x-terminal emulator on your local computer, you should be able to open an xwindows session on mercury.
- mercury has a help facility which provides information about a variety of topics, including printing, UNIX and vi (type help). The vi information is in the scientific software section of the help. Some of the most commonly used commands are summarized below for your convenience.
Practice in UNIX basics:
- logon
- * is wildcard character. UNIX is case sensitive.
Files are arranged hierarchically (in directories and subdirectories).
- vi filename--begins an editing session for a new file with the name filename, or the existing file called filename.
- more--views the contents of a file without changing it.
It generally appears one page at a time--hit spacebar to
get the next page.
To stop before getting to the end, type ctrl C.
- ls--list the files and subdirectories of the working directory.
- cp filename1 filename2--copy filename1 to filename 2 in same directory.
- cp filename1 directory1--copy filename1 into directory1 with same filename.
- mv filename1 filename2--moves a file (effectively renames the file).
- rm filename1--deletes the file.
- pwd--tells you the full name of your working directory.
- cd--changes working directory to your home directory.
- cd directory1--changes working directory to directory1
(either to a subdirectory or must specify full path name).
- mkdir newdirectory
create a directory called newdirectory which is a subdirectory of
the working directory.
- sh filename--execute a list of commands stored in the file called filename (if you don't want to bother retyping same command over and over).
- command1 \&--run the command called command1 in the background (so you can do other things
while it is running).
- to stop a foreground process, type ctrl C or ctrl Z (the latter may
require that you kill the process in the way described for the
background process before logging out).
- to stop a background process: use ps to get process id \# (eg 220)
then type
kill 220
FORTRAN
- f77 -o filename1 file.f--compiles a fortran program (barebones--type man f77 for more elaborate options) and creates an executable file called filename1.
- filename1--runs the fortran program in the executable file called filename1.
- Note on input-output: unit 5 and unit 6 default to the terminal.
To assign filename5 to unit 5 and/or filename6 to unit 6,
type
programname $<$filename5 $>$filename6.
Other unit numbers can be linked to files using OPEN statements
inside the program, or simply named fort.8 (for unit 8), etc.
PRINTING (you will need to print for the HW assignments)
- Printing from mercury can be directed to a variety of machines in public clusters and college computer rooms (see help).
- Another thing you can do is to use ftp to move the file to your local machine (PC or mac)
and print it from there.
- Some setups also allow you to select a block of text and print it
with a key or menu command called "PRINT SELECTION"
Minimal introduction to vi
- To open a new file with the name filename, type vi filename.
- To insert text after the cursor, type a and then the text.
To insert text before the cursor, type i and then the text.
In both cases, exit from insert mode with the escape key.
- To save the file while you are working on it, type :w.
To save the file and quit the editor, type :wq.
To quit the editor without saving changes, type :q!.
- To delete a line, put the cursor on the line and type dd.
To delete n lines starting with the line the cursor is on, type ndd.
To copy a block of n lines starting with the line the cursor is on, type nyy, then move the cursor to the line after which you want to insert the block and type p.
- To delete a character, type x. To replace a character, type r and then the new character. To replace several characters, type R and the new characters, then use the escape key to exit from this form of insert mode.
- To go to a particular line number n, type :n. To locate a string (case-sensitive!) type /string.