Wednesday, April 01, 2009

A Mug's Guide to Unix

---- P. A. Robinson

This guide is intended to introduce the rank beginner to enough UNIX to get started. It is a list of useful commands that work. For more information on these and other commands, use the man command described below.
Note: CR=carriage return.




Logon
On an ordinary terminal: You will get the following prompt: loginType your login name then CR.
You will get the following prompt: passwordType your password}, then CR.
On a Sparcstation or Dec Alpha: A CR will get you the login prompt. Proceed as above.
On an X-Terminal: A menu will tell you which machines are available to you. Click the appropriate one with the mouse. You will then be able to proceed as if you are logged on to that machine directly.

Other commands

bg
After using CTRL Z to stop a job, you can put it in background by typing "bg".
cat filea fileb > filecJoins "fileb" to the end of "filea" and puts the result in "filec", preserving "filea" and "fileb".

chmod
Changes the read/write/execute (rwx) permissions for the user/group/others (u,g,o). For example chmod og-rwx filea changes the file permissions on "filea" so that the group and others cannot read, write, or execute the contents.

compress fileinCompresses the file "filein", replacing it by one called "filein.Z". The command uncompress filename.Z reverses the process. The commands gzip and gunzip perform the same functions even more efficiently and are available on most machines.

cp -- filein fileoutCopies the file "filein" to "fileout", leaving "filein" intact.
du --Tells you your disk usage in kilobytes.
exit --Logs you off. If there are stopped jobs that you don't want, a second "exit" command will log you off. Otherwise, type jobs to see what the stopped jobs are.
fg --Will bring the highest-numbered stopped or background job into foreground so you can kill it or restart it.
finger username Gives information on the user called "username".
f77 -o file.e file.f Compiles the fortran code in the file "file.f" and puts an executable file in "file.e".
history --Gives a numbered list of your most recent UNIX commands.
jobs -----Will tell you the status of all jobs, foreground, background and stopped. The command fg --will then bring jobs to foreground to run, or kill will terminate them.
kill --Use the jobs command to find out the number jobnumber of your job. The command "kill -9 jobnumber" will then kill that job.
lpq --Tells you the status of the laser printer queue.
lpr --filein Prints filein on the laser printer.
lprm jobnumber --Deletes the job with number "jobnumber" from the laser printer queue. Use the command lpq to get "jobnumber".
ls Lists the normal-type files in your directory.
ls -l Expanded listing of the normal-type files in your directory.
ls -a Lists all files (including login-type) files in your directory.
man comm Displays the online manual entry for the command comm.
man comm col -b lpr Prints the online manual entry for the command comm on the laser printer.
mv filein fileout Moves "filein" to the new file "fileout", removing "filein".
ncargf77 -o file.e file.f As for f77, but also links the NCARGraphics libraries, as needed.
ps ux Tells you how your jobs are running on the machine.
renice The command renice n jobno will change the niceness of the job numbered "jobno" to the value n, between 0 and 19 (do ps ux) to get the job number). Use this command when you are running on someone else's machine, setting a value of at least 12.
rlogin machinename -- Logs you in on the machine "machinename".
rm filein Removes the file "filein".
sparcload -- Tells you the load on each of the sparcstations in the School. Useful for choosing a machine on which to run large jobs.
vi filein Invokes the editor vi on the file "filein".
& An ampersand entered after a command (but on the same line) tells the machine to run the command in background, so you can carry on with other things.
> The > sign is used to direct output of a process to a destination; e.g. proc>fileout sends the output of the process "proc" to the file "fileout".
> &This combination placed after a command redirects all standard and error output to the file specified after it on the same line.
!The exclamation mark followed by the command number will repeat that command. If followed by the first letters of a command, it repeats the most recent command beginning with those letters. Use the command history to get a list of command numbers for your current session. !! repeats the last command.

CTRL Z Stops, but does not kill, the current job. (N.B. hold down the "CTRL" key and "z" at the same time to get this.) You should not use CTRL Z as a substitute for CTRL C, otherwise you will get an accumulation of inactive jobs that use up memory and slow or stop the machine. You should use jobs to find out the job number, then kill to remove it if it is no longer wanted.
CTRL C Kills the current job. (N.B. hold down the "CTRL" key and "c" at the same time to get this.)
The author thanks G. Geers for proofreading this guide and D. H. Dawes for his comments.

No comments:

Post a Comment