Sei sulla pagina 1di 32

Unix for Beginners

____________________________________________________________________________

UNIX for Beginners

Gerard J. Kleywegt
Department of Molecular Biology
University of Uppsala
Uppsala - Sweden

With help from Alwyn Jones, Erling Wikman and Arnold Andersson

Version 1.0 @ 930111


Version 2.0 @ 940116

Latest update @ 9/10/2002 2:20 PM

1
Unix for Beginners
____________________________________________________________________________
I - Table of contents
Chapter/Section Item Page
_________________________________________________________________
I Table of contents 2
II Introduction 4
II-1 Literature 4
II-2 What is UNIX ? 4
II-3 About this guide 5
III UNIX versus VMS 6
III-1 Commands 6
III-2 Miscellaneous 7
IV Basic concepts 8
IV-1 Logging in 8
IV-2 Commands 8
IV-3 Getting help 8
IV-4 Control characters 8
IV-5 Editors 9
IV-6 I/O streams 9
IV-7 File system 9
IV-8 Pathnames 10
IV-9 Listing directory contents 10
IV-10 Meta-characters 10
IV-11 Simple file manipulation 11
IV-12 Linking files 11
IV-13 Changing file permissions 12
IV-14 Manipulating text files 12
IV-15 I/O redirection 13
IV-16 History facility 13
IV-17 Aliases 14
IV-18 Job control 14
V Example files 16
V-1 .login 16
V-2 .cshrc 16
V-3 Other files 17
VI Example scripts 18
VI-1 compressor 18
VI-2 split 18
VI-3 repeat 19
VI-4 police 19
VI-5 forall 19
VI-6 sln 20
VI-7 dirtar 21
VI-8 tardir 21

2
Unix for Beginners
____________________________________________________________________________
VII Miscellaneous 22
VII-1 ftp 22
VII-2 rlogin/telnet 22
VII-3 make 22
VII-4 tar 22
VII-5 more commands 22
VII-6 Files versus processes 23
VII-7 sed 24
VII-8 sed 24
VII-9 X-windows programs 24
VII-10 cut 24
VII-11 system-dependent Fortran functions and subroutines 24
VII-12 command-line arguments in Fortran 25
VII-13 dynamic memory allocation in Fortran 25
VII-14 saving disk space 25
VII-15 units 25
VII-16 w and who 25
VII-17 factor 26
VII-18 some more commands 26
VIII Index of Unix commands 27
IX Inverted index of Unix commands 30

3
Unix for Beginners
____________________________________________________________________________
II - Introduction
II-1 • Literature:
- S.G. Kochan & P.H. Wood, “UNIX Shell Programming”, Hayden Book Company,
Berkeley, 1985 (usually found in the Patterson room);
- G. Anderson & P. Anderson, “The UNIX C Shell Field Guide”, Prentice-Hall, Englewood
Cliffs, 1986 (in Erling’s room);
- P.E. Bourne, “UNIX for VMS Users”, Digital Press, 1990 (in Alwyn’s room);
- “CONVEX UNIX for the Beginning User - Training Course”, CONVEX Computer
Corporation, 1988 (available on request from Gerard);
- “CONVEX UNIX for the Advanced User - Training Course”, CONVEX Computer
Corporation, 1988 (available on request from Gerard).

II-2 • What is UNIX ?


UNIX is a so-called operating system which nowadays runs on most computer systems. An
operating system is merely a computer program through which the user interacts with the
computer and its components and peripheral devices (processor, processes, files, disks,
terminals, printers, plotters, etc.). Since every computer has one, operating systems are a
necessary evil that you have to deal with if you do protein crystallography; on the other hand,
knowing your operating system(s) well can make life a lot easier for you.
UNIX was developed on a PDP-7 by Dennis Ritchie and Ken Thompson at Bell
Laboratories in the late 1960s; it was first called UNIX in 1970. After 1975, UNIX developed
along two separate branches leading to Berkeley (BSD) UNIX and System N UNIX (with N
currently being V). Nowadays, System V UNIX is available on most computers but contrary
to popular belief, there is no such thing as a “standard” UNIX version. Although the basic
commands are available in most UNIX implementations, hardware vendors like to add non-
standard options and ditto commands to tailor their UNIX to their machines. Standardisation
is, however, being undertaken by the Open Software Foundation (OSF) and, separately, by
Unix International; the first proceed, OSF/1, is running on the new DEC Alpha computers.
Since the mid-1980s approximately, UNIX has evolved into the operating system of
choice for most machines (probably because it is cheap for a hardware vendor to adopt it),
which means that users in a multi-vendor computer environment no longer have to learn a new
operating system whenever they get a new computer (now they only have to familiarise
themselves with the system-specific extensions).
UNIX does have some strong points: it is fairly portable, flexible (i.e., easy to change,
adapt and extend) and contains several powerful utilities. Also, it supports multiple users and
multi-tasking. Nevertheless, UNIX is still very much an operating system for computer jocks
(programmers); in skilled hands, it is very powerful, but to the novice end-user it is sometimes
a nightmare (system-specific extensions, inconsistent syntax). Fortunately, on the modern
graphics workstations more and more tools become available which make life easier (in this
case, more “Macintosh-like”).

4
Unix for Beginners
____________________________________________________________________________
II-3 • About this guide.
This guide attempts both to help novice UNIX users to get started and to help more
experienced users to get more out of their operating system. It has been written by a
reasonably spoiled SGI/IRIX/C-shell user. This means that not all commands and scripts are
necessarily identical or even available if you use other machines ! Novice users who have
used VAX-VMS will be interested in chapter III; more experienced users will probably want to
skip sections III and IV.

A UNIX saleslady, Lenore,


Enjoys work, but she likes the beach more.
She found a good way
To combine work and play:
She sells C shells by the seashore.

A very intelligent turtle


Found programming UNIX a hurdle
The system, you see,
Ran as slow as did he,
And that's not saying much for the turtle.

Just about every computer on the market today runs Unix, except the Mac (and nobody
cares about it).
Bill Joy

Making files is easy under the UNIX operating system. Therefore, users tend to create
numerous files using large amounts of file space. It has been said that the only standard
thing about all UNIX systems is the message-of-the-day telling users to clean up their files.
System V.2 administrator's guide

5
Unix for Beginners
____________________________________________________________________________
III - UNIX versus VMS
III-1 • Commands:
The following is a list of common VAX/VMS commands and their UNIX counterparts. Use
the manual pages for more information regarding the precise syntax, options etc.

____________________________________________________________________________
VMS command UNIX command description
____________________________________________________________________________
show default pwd show current directory
show system ps show current processes
show users who OR finger show current users
show symbol * alias show symbols/aliases
show dev d df show file system
sh queue * at -l show batch queues
show process ps show my processes
____________________________________________________________________________
set def sys$login cd go to home directory
set def [-] cd .. go to parent directory
____________________________________________________________________________
create/dir [.mydir] mkdir mydir create new directory
del my.dir; rmdir mydir delete directory
copy cp copy
delete rm delete file(s)
delete/confirm rm -i delete after confirmation
dir/size=all/date/prot ls -FartCos extended directory listing
dir [...] ls -R list directory tree
dir/size/total du disk usage
rename f_1 f_2 mv f_1 f_2 rename/move a file/dir.
purge --------------- delete older versions
set protection chmod change file protection
---------------------- chown change ownership
____________________________________________________________________________
append a b cat a >> b append file a to file b
diff a b diff a b list differences
search a "str" grep str a find "str" in file(s)
edit vi OR jot OR emacs OR .. edit
type cat list file contents
type/page more OR less list file(s) in portions
____________________________________________________________________________

6
Unix for Beginners
____________________________________________________________________________
____________________________________________________________________________
VMS command UNIX command description
____________________________________________________________________________
fortran file.for f77 -c file.f compile file
link file.obj f77 -o X file.o link
run file file execute program
@file source file execute command script
spawn cmd cmd & spawn a command
submit at OR batch submit a job
a:=cmd alias a cmd define symbol/alias
write sys$output echo write to output device
____________________________________________________________________________
recall/all history show recent commands
recall cmd !cmd execute previous cmd
---------------------- set history=100 remember last 100 commands
help cmd man cmd give help about cmd
phone talk exchange messages
mail mail OR Mail electronic mail
show terminal stty show terminal settings
set terminal stty set terminal characteristics
backup tar backup file(s)
____________________________________________________________________________

III-2 • Miscellaneous:
One of the most important differences between VMS and UNIX is that UNIX does not allow
for different versions of the same file (e.g., on the VAX you may have login.com;1,
login.com;2 etc.). This means that you never have to purge your directories, but also that you
overwrite a file if you send output to it more than once !
Under VMS you usually have a file LOGIN.COM in your home directory which is
executed when you log on to the VAX; under UNIX, these are replaced by .login (executed
when you log in) and .cshrc (executed whenever you start a C-shell process).
File names under UNIX are also different; for instance, a file which is called
DISK5:[USER.XPLOR]XPLOR.INP;35 on the VAX might be called
/disk5/user/xplor/xplor.inp on a UNIX system.
Another major difference is the case-sensitivity of UNIX, in other words: three files
called text.dat, TexT.Dat and TEXT.DAT refer to the same file under VMS but to different
files under UNIX !

7
Unix for Beginners
____________________________________________________________________________
IV - Basic concepts
IV-1 • Logging in:
In order to be able to use a computer, you have to log in. For this you need a user name, a
password and a home directory (all three are provided by the system manager the first time).
Your user name should not contain special characters (such as “/” or “-”) and be
unique. Your password should be long and hard to guess (i.e., don’t use your own name, your
cat’s name, your phone number, etc.). Change your password regularly (use the command
passwd)! Passwords are to be taken extremely seriously ! If anyone obtains a valid
username/password combination, he or she can log on to the system and do a lot of damage
(deleting your files, for example, or installing virus programs) !!!
The system file /etc/passwd contains a list of all authorised users with their (encrypted)
passwords, user id, group id, home directory and default shell-type. If you cat (type the
contents of) this file, you will notice that there are several “special” users, for example, “root”
(system manager), “demo” and “ftp”.

IV-2 • Commands:
Commands tell the system what to do. Under UNIX they usually consist of lower-case letters.
The general syntax is: command [option(s)] [argument(s)]. The arguments are usually files
(sometimes other devices, such as a display window or a printer) upon which the command
will act. The options modify the way a command works; often they are single letters preceded
by a dash (“-”; minus sign); usually several options can be combined and prefixed by a single
dash. Please note that some commands mix options and arguments, some use a “+” instead of
a “-” or even nothing at all. Also note that sometimes you have to provide “obvious”
arguments; for instance, the find command, which looks for specific files in a directory tree,
needs the -print option if you want to see the results on your screen ...
You may type several commands in a row, provided you separate them with semi-
colons (“;”). If you need to continue a command on the next line, use the backslash character
(“\”) at the end of the first line, etc.

IV-3 • Getting help:


The help command under UNIX is called man (for “manual”); it has the syntax man
command_name. Anther useful command: apropos anything (lists all commands which
contain the string “anything” in their manual header).

IV-4 • Control characters:


If you make mistakes while you type a command you may use:
- CTRL-h or BACKSPACE to erase the last character
- CTRL-w to erase the last word
- CTRL-u to erase the whole line
You may change these definitions in your .login file (e.g., to define CTRL-f as the erase-
character keystroke, you would enter stty erase ^F).
Other useful control characters are:
- CTRL-s to suspend output to the terminal

8
Unix for Beginners
____________________________________________________________________________
- CTRL-q to resume output
- CTRL-o to discard output to the terminal
- CTRL-z to suspend the current process (type fg, for “foreground” to resume it)
- CTRL-c to kill the current process
- CTRL-d to log out

IV-5 • Editors:
There are four types of editors under UNIX:
(1) line editors (obsolete): ed, ex
(2) full-screen editors (soon obsolete ?): vi, emacs
(3) window-based editors (Macintosh-like): jot, zip, xedit
(4) stream editors (will edit files for you using a command script): awk, sed
Note that jot and zip only run on SGIs; xedit is available on most machines running X-
windows; emacs is not available on all machines; sed and awk are very powerful tools (they
make a lot of “jiffy” programs obsolete) !

IV-6 • I/O streams:


There are three I/O streams associated with UNIX (see table). Under normal circumstances,
standard input is expected from the keyboard and both standard output and standard error are
associated with the terminal screen. As under VMS, input and (error) output can easily be
redirected; in addition, under UNIX it is possible to “pipe” the output from one command or
program straight into another one (this will be discussed later).

I/O stream VMS-equivalent C unit Fortran unit default


stdin sys$input 0 5 keyboard
stdout sys$output 1 6 terminal
stderr sys$error 2 6 terminal

IV-7 • File system:


UNIX organises information into files. Files are more than just collections of characters sitting
on disks; in general, a file is a sequence of bytes of raw data. Files may therefore be
executable programs, text files, data files, but also directory files, physical devices and
communication channels (there even exists a “non-file”: /dev/null - whenever you want output
to go down the drain, redirect it to this “file”).
Files are organised hierarchically in a so-called directory tree; at the top is the “root
directory” / (a single slash). On a system disk, this directory typically contains subdirectories
such as bin (UNIX commands), etc (system files), tmp, lib (libraries) and usr. The usr
directory in turn contains the home directories of the users of the machines (and their
subdirectories).
The home directory usually has the same name as the username; it is the user’s initial
working directory when he or she logs in.

IV-8 • Pathnames:

9
Unix for Beginners
____________________________________________________________________________
The complete name of a directory (or file) is called its pathname. To see the complete
pathname of your current directory, use pwd (print working directory); this will display for
example: /nfs/taj/bubba if your username is “bubba” and you work in Alwyn’s group. A
pathname which begins with a slash (i.e., one which is defined starting in the root directory) is
called an absolute pathname. You may also use relative pathnames; they are given relative to
your current directory. For example, a file “xplor.inp” in Bubba’s subdirectory “xplor” may be
referred to as xplor/xplor.inp when Bubba is in his home directory. Another user in his home
directory on the same disk might use: ../bubba/xplor/xplor.inp (the “..” refers to the parent
directory) and users on other disks might use either /nfs/taj/bubba/xplor/xplor.inp or
~bubba/xplor/xplor.inp; the “~bubba” means: Bubba’s home directory. Bubba himself could
also use ~/xplor/xplor.inp (a single “~” refers to one’s own home directory).
Filenames may contain up to 256 characters; they are case-sensitive, so “test” and
“TEST” are two different files ! Try to avoid special characters (such as: / \ | ‘ “ ? $ # ; ~ - ! @
% & etc.), except for periods and underscores.

IV-9 • Listing directory contents:


The ls (list) command lists the contents of a directory; the options you provide determine how
much information is displayed (my favourite on SGIs is: ls -FartCos). A typical entry in a
directory listing may look as follows:
-rwxr-xr-- 1 bubba 17632 Apr 1 23:59 xplode*
The first character indicates the file type; it may be: “-” ordinary file, “d” directory, “b”
block device, “c” character device, “l” symbolic link or “s” socket. The next nine characters
show the permissions (in three groups of three) of the user, other users in the same group and
anyone else (in that order): “r” means read permission, “w” write permission and “x”
(sometimes “s”) execute permission, whereas a “-” means that the corresponding permission
has not been granted. The number (1) is the number of names that are linked to the file
(default is 1, if the file is linked to other files this number will be higher). This is followed by
the username of the owner of the file (bubba) and the size of the file in bytes (17632). The
date and time when the file was last modified are also listed as is the actual name of the file
(xplode). The “*” after the file line is produced by the -F option of the ls command and
indicates that this is an executable file (program or script); the -F option will also put a “/” after
directory files and an “@” after linked files.

IV-10 • Meta-characters:
You may use several meta-characters (wildcards) in filenames:
(1) “*” - matches any number of characters; e.g., ls */*.f will list all Fortran source files in the
current directory and all of its sub-directories.
(2) “?” - matches any single character; e.g., ls file?.f will list file0.f, file1.f, file2.f etc., but not
file10.f, filexyz.f and so on.
(3) “[]” - within the brackets you may put a list of ASCII characters which are considered to
match, or a range of characters separated by a dash; e.g., ls file[135].f will list file1.f, file3.f
and file5.f, but not file2.f etc.; ls [A-Z1-4]*.f will list all Fortran files whose name begin either
with an uppercase letter or with 1, 2, 3 or 4.
These meta-characters may be used with nearly all UNIX commands, not just with ls !

10
Unix for Beginners
____________________________________________________________________________

IV-11 • Simple file manipulation:


You may copy a file with the command: cp oldfile newfile; this will make an exact duplicate
of oldfile; if newfile existed it will be overwritten (the -i option prevents this), otherwise it will
be created. If you want to copy a file to another directory, the second argument should be the
name of the target directory (i.e., not of the new file !): cp xplor.out ../notes will copy the file
xplor.out to the sister directory “notes”. If you want to copy a file from another directory to
your current directory, use either the absolute pathname of your current directory or simply a
dot (“.”, this always means “current directory”): cp ../notes/xplor.out . If you want to copy a
directory structure, use cp -r dir1 dir2.
A file can be removed with the command: rm myfile. If you want be prompted and
asked if you really, really want to remove a file, use the -i option: rm -i file?.f etc.
If you want to move or rename a file, use the command: mv oldfilename
newfilename; this is equivalent to: cp oldfilename newfilename ; rm oldfilename. Use the -i
option to prevent files from being overwritten.
To create a new directory, use: mkdir newdir.
To change directories, use the cd command; examples: cd xplor/old, cd
~billybob/mail, cd ../../joey etc.
A directory which contains files can be removed completely in two ways: rm mydir/*
; rmdir mydir or rm -r mydir. There is one difference, however: the second method
recursively deletes all sub-directories and their files as well !

IV-12 • Linking files:


A hard link allows you to assign multiple names to a single file (usually both files have to be
on the same disk). It establishes another pathname to an existing file. For example, if you
want to be able to edit a file “lab_notes” in all of your directories, you could create it in your
home directory and later make links from all your subdirectories (you may give the linked files
different names if you like). Now, whenever you edit any of the linked files the changes are
made to all the files “lab_notes” since in reality they all correspond to one single file
somewhere on the disk. The syntax is: ln existing_file link_file (note: if you swap the
arguments you will effectively delete the existing_file !!!).
A better way of linking is through so-called soft links; these can be made across disks
and even to disks attached to computers which are physically quite far apart (so you could link
a file in Stockholm to one in Uppsala). The link file really only contains a text string (the
pathname of the file to which it is linked); this string is substituted whenever the name of the
linked file appears in a pathname. A familiar example: ln -s /nfs/taj/alwyn/o/data odat (note
the “-s” which makes this a soft link and please note the order of the arguments: existing file
first !). Another useful example (if you use the scratch disk a lot): ln -s /nfs/scratch/bubba
scr (now it will seem as if /nfs/scratch/bubba is a sub-directory called scr of your current
directory).

IV-13 • Changing file permissions:

11
Unix for Beginners
____________________________________________________________________________
File permissions (read, write, execute permission) can be altered with the chmod command.
This can be used in two different ways. The easiest one has the syntax: chmod who operator
permission filename(s), where:
- who = u (user), g (group), o (others) or a (all three classes)
- operator = + (add), - (remove) or = (assign permission(s))
- permission = r (read) and/or w (write) and/or x (execute)
Examples: chmod g=rx file1, chmod a+x file2, chmod o-wx file3 etc.
The second syntax involves octal protection indicators: chmod permission_bits
filename(s). The “permission_bits” is a set of three digits between 0 and 7, one for u, g and o.
Read permission has been assigned the value 4, write permission 2, execute permission 1 and
no permission 0; the appropriate permission_bits are found by adding the values of the granted
permissions, for example: chmod 755 xplor.exe will give the owner rwx-permission
(4+2+1=7) and all other users rx-permission (4+1=5).
Note that directories are only accessible if you have read and execute permission; the
same is true for script files and program executables. Also note that you may prevent a file
from being overwritten or deleted by giving yourself no write permission. If you want to
change the ownership of a file, use the chown command.

IV-14 • Manipulating text files:


The following commands are often used for manipulating text files:
- cat filename : type the contents of the file on the screen
- more filename : ditto, but paginated (type a SPACE to see the next page or a “q” to quit;
some versions of UNIX offer the command less as well with which you can go back and forth
in a file)
- head filename : print the first 10 lines of a file (use: head -5 filename to see just the first
five lines, etc.)
- tail filename : print the last 10 line of a file; you may use the option -5 or -123 similar to
head; if you use the option -f, the process goes into an endless loop printing everything that is
added to the file to your screen (use this to monitor your XPLOR jobs, for example; terminate
with CTRL-c)
- grep string filename : list all occurrences of “string” in file “filename”; use the -i option to
ignore uppercase-lowercase differences
- wc filename : print the number of lines, words and characters in a file
- cmp file1 file2 : tells you whether or not two files are identical
- diff file1 file2 : finds differences between two files (on SGIs use /usr/sbin/gdiff; this is a
window-mouse-based implementation of diff); use the -s or -r option to compare two
directories
- sort filename : sorts a file alphabetically or numerically; if you provide several filenames,
the files will be merged and then sorted
- lpr -Pprinter filename : print a file on the printer (in our lab: “printer” would be “qms” or
“2up” etc.); use the commands lpq to list current print jobs and lprm to remove them; use in
conjunction with pr to get a nice listing including a header, the filename and page numbers,
e.g.: pr -h “Source” -l80 prog.f | lpr -P2up

12
Unix for Beginners
____________________________________________________________________________
IV-15 • I/O redirection:
Often it is handy to redirect the output of a command or program to a file (or a printer or ...).
The syntax to do this is: command > outfile. This will overwrite “outfile” if it existed
already, unless you put the statement noclobber in your .cshrc file (then you may only
overwrite files by using “>!” instead of “>”). If you want to append the output to an existing
file, use “>>”. Example: to append file2 to file 1, use: cat file2 >> file1. If you also want to
redirect the standard error output to the same file, use “>&” or “>>&”.
To redirect standard input from a file, use: command < inputfile, for instance: xplor <
xplor.inp. Alternatively, you may use “<< string” to indicate that everything that follows on
standard input until the line which contains only “string” is to be used as input. For example:
4d_ono crap.o << end-of-input
yes (use display)
@lsq.omacro
stop
end-of-input
Of course, you may use combinations of input and output redirection: xplor <
trafun.com >>& all_trans.out and so on.
Another way of I/O redirection is the use of “pipes”: a pipe causes the standard output
of one command to be transferred into the standard input of another command. The syntax is:
command1 | command2; for example, to find out how many users are logged in, type who |
wc -l; to get a sorted list of logged in users, type who | sort, or who | sort | more. A more
useful example: to count the number of amino acids in a PDB file, use: grep “ CA “ file.pdb
| wc -l; to list the CA-atoms of all alanyl residues, use: grep ALA file.pdb | grep “ CA “. If
you also want to pipe the standard error output, use “|&” instead of “|”.

IV-16 • History facility:


The csh-command history lists previously issued commands (use “-8” to get just the previous
eight commands); the number of commands that is saved can be set as follows: set
history=100 (you may want to put this into your .cshrc file).
If you mistyped a command, you may use: ^wrong^correct to correct the typo and
execute the command; for example, if you typed: who|sort|moer, type ^er^re next and the
correct command who|sort|more is executed.
To re-execute a previous command, use “!”: !! repeats the previous command, !142
repeats command number 142 (in the list produced by history), !l repeats the most recent
command beginning with the letter “l”, !-4 goes back four commands and !?s? repeats the
most recent command that contained the letter “s”. You may also extend previous commands,
for example if the previous command was ls -l, you may type !! -a /usr | more which will
result in the execution of ls -l -a /usr | more !
You may also “recycle” parts of previous command lines (for instance, long file
names). The C-shell divides each command in separate “words” delimited by spaces or tabs.
For example, if command number 5 in the history list was ls -al file1 file2 file3, then the
command plus its options are called :0, the first file name is :1 or ^, the second file name :2
and the last file name :3 or $, while all files collectively may be referred to by *. The
following table gives some of the possible history references for this command:

13
Unix for Beginners
____________________________________________________________________________
You type: What is executed:
!5 ls -al file1 file2 file3
more !5:2-3 more file2 file3
cat !5:$ cat file3
more !5^ more file1
lpr !5:2 lpr file2
lpr !5* lpr file1 file2 file3
You may also modify previous commands, for example: !!:s^old^new; if the previous
command was ls -l *.old, the new command will be ls -l *.new. To verify that the edited
command is correct, type :p immediately after the event identifier: !!:p:s^old^new; if it is
correct, type !! to execute it.

IV-17 • Aliases:
The csh-command alias lists all defined aliases. The command also allows you to rename or
abbreviate commands, for example: alias rm ‘rm -i’ will mean that every time you type rm
you actually execute rm -i. Should you at some stage want to use the original rm command
without the -i option, then you have the following options: unalias rm removes the alias,
/bin/rm executes the rm program itself without any option, \rm does the same.
An alias may contain more than one command, for example: alias status ‘date ; who |
sort’.
If you want to create aliases for commands which require an argument (usually, a
filename), use \!* (there is actually some perverted logic behind this ...) at the position of the
argument: alias ala ‘grep ALA \!* | grep CA | wc -l’; now if you type ala file.pdb the result
will be the number of alanyl residues in that file.

IV-18 • Job control:


A command may be executed in either the foreground or the background. Foreground jobs
may read from and write to the terminal and the shell will wait until a command is finished
before prompting the user for a new command. Background jobs may never read from the
terminal (they will be stopped if they try to) but they may write to it (this can be switched off
by stty tostop); the shell prompts for a new command without waiting for the command to
complete.
In order to execute a command in the background put an ampersand (&) after the
command: xplor < x.in >& x.out &. The job will receive a background job number ([1], [2]
etc.) and a process ID. When it is completed, a message like “[2] Done xplor < x.in >& x.out”
will be displayed on your terminal. A job which was started in the foreground can be stopped
with CTRL-z and then be continued in either the background (command bg) or the foreground
(fg).
The command jobs gives you a list of background jobs initiated at your terminal. If there are
more than one, the one labelled “+” will be started if you type fg; if you want to start another
one in the foreground, type %3 (to start job number 3). To stop a job running in the
background, use stop %5; to terminate it completely, use kill %2.

14
Unix for Beginners
____________________________________________________________________________
To get information about your (and other people’s) processes, use the ps command (for
example, if you want to know if anybody else is already running XPLOR on an SGI before
submitting your own XPLOR job, type: ps -ef | grep -i xplor).
The kill command can also be used to terminate or interrupt processes by referring to
their PID (process id; these are listed by the ps command), for example: kill -9 1734, kill -
STOP 182, kill -CONT 182, etc.
If you start a job in the background and you plan to log out before it is finished, submit
it with the nohup command (no hang-up): nohup xplor.com &; if you don’t do this, all your
processes, including your XPLOR job, will be killed when you log out !
Use nice and renice to run background jobs with lower priority (so your big
calculations are not in the way of interactive users).

15
Unix for Beginners
____________________________________________________________________________
V - Example files
V-1 • .login:
I recommend that you keep it to an absolute minimum. I prefer to keep all my settings in the
.cshrc file.
umask 022
eval `tset -s -Q`
stty line 1 erase '^H' kill '^U' intr '^C' echoe

V-2 • .cshrc:
The following are fragments of my .cshrc file; note that this particular one is tailored to SGI’s
IRIX.

#
set path = (. .. ~ ~/bin /usr/bsd /bin /usr/bin /usr/bin/X11 /usr/sbin
/usr/demos /usr/demos/bin /usr/etc /usr/local/bin /usr/bin/dn /usr/ucb
/nfs/taj/alwyn/o/bin /usr/people/alwyn/a/bin /nfs/vega/people/alwyn/a/bin
/nfs/public/IRIX/bin /usr/new /user/bin /user2/bin)
limit coredumpsize 0
source /nfs/public/IRIX/ccp4/include/ccp4.setup >& /dev/null
set autologout=240
set ignoreeof
set history=100
set savehist=250
set filec
set fignore = (.o .a .old .f.old .f.older .f.oldest)
set notify
set time=5
set prompt = " > "
alias newsh 'wsh -s40x80 -f Screen.15 -t"new shell"'
alias ftp 'ftp -i'
alias diff 'diff -lsbwit'
alias comp 'compress -v'
alias unco 'uncompress -v'
alias note 'cat ~/stuff/notes | grep \!*'
alias down 'cd \!*'
alias up 'cd ../'
alias left 'cd ../\!* '
alias home 'cd'
alias dir ls
alias dsd 'ls -laF \!* | sort'
alias dsds 'ls \!* | grep "`date | cut -c5-10`"'
alias ls '\ls -FartCos'
alias l '\ls -Cal'
alias lc '\ls -C'
alias lss '\ls -FartCos \!* | sort'
alias fint 'find * -print | grep \!*'
alias sus 'who -a'
alias sss 'ps -ef | sort'
alias time '/bin/time'
alias h 'history'
alias h5 'history | tail -5'
alias hg 'history | grep \!*'
alias hg5 'history | grep \!* | tail -5'
alias grep 'grep -i'

16
Unix for Beginners
____________________________________________________________________________
alias count 'grep -c'
alias help man
alias ta 'tail -100'
alias he 'head -100'
alias lo logout
alias du 'du -rk'
alias grand '\du -sk *'
alias df 'df -k'
alias s source
alias rm 'rm -i'
alias dorm '\rm'
alias del 'rm'
# disp alien will set the environment variable DISPLAY to alien.bmc.uu.se
alias disp 'set x=\!* ;setenv DISPLAY $x.bmc.uu.se:0;setenv|grep -i display'
# a quick way to set your terminal to VT100
alias vt100 'setenv TERM vt100 ; setenv | grep -i term'
# Fortran compilation for SGI, ESV, ALPHA/OSF1
alias f77sgi '/bin/time f77 -Olimit 3000 -v -check_bounds -u -w0 -c'
alias f77esv '/bin/time f77 -Olimit 3000 -v -check_bounds -u -c'
alias f77al '/bin/time f77 -Olimit 3000 -C -O -u -v -c'
# head AND tail a file
alias ht 'set x=\!* ; echo head $x ; head $x ;echo tail $x ; tail $x'
alias xterm 'xterm -sb'
alias show 'ps -ef | grep $user | grep -i \!*'

V-3 • Other files:


Some other files in your home directory might be:
.logout - csh-script which is executed when you log out
.signature - your name and address, for example; will be appended to every mail you send
.plan and .project - used by the finger command
In addition, there may be window-manager specific files such as .chestrc, .4Dwm,
.Xdefaults, and/or .sgisession. Examples of all these types of files can be found in (and copied
from) /nfs/public/shell.

17
Unix for Beginners
____________________________________________________________________________
VI - Example scripts
The following script files can be copied from /nfs/public/shell. For more information on shell-
specific constructs (if, while, foreach, -e, -f, $#argv etc.), consult the manual pages for the csh
command.

VI-1 • compressor:
This script can be used to automatically find and compress large map files (or it can easily be
changed to find and act on other files). Consult the manual pages of the find command for an
explanation of all possible options.

# compressor ... gerard kleywegt @ 920318


# find /.. => search there (/ => entire file system)
# -name .. => specify file names (-o is "OR-function")
# -size ..c => specifies minimum file size in bytes
# -type f => only look for files (i.e., not links or directories)
# -atime +2 => only use files which haven't been accessed in two days
# -exec .. => command to be executed for each "hit" (compress -v or ls)
set echo
find /nfs/taj \( -name '*.map' -o -name '*.o' \) -size +20000c -type f -
atime +2 -exec compress -v {} \;
unset echo

VI-2 • split:
This script will, in a given directory, copy all Fortran files (.f) to a subdirectory called fsplit
(must exist), do an fsplit and remove the original sources (beware of filename duplications !).
Note the uses of the set command.

# split - gj kleywegt @ 920311


if (-e fsplit) then
set sources=*.f
set numfiles=$#sources
echo Split $numfiles sources
if ($numfiles == 0) then
echo ERROR - no .f files in this directory ...
exit -1
endif
foreach file ($sources)
echo ... splitting $file ...
cp $file fsplit
fsplit fsplit/$file
\rm fsplit/$file
end
exit 0
endif
echo ERROR - no subdirectory called "fsplit" here ...
exit -2

18
Unix for Beginners
____________________________________________________________________________
VI-3 • repeat:
This script will execute a given command repeatedly at regular time intervals (using the sleep
command).

# repeat - gj kleywegt @ 911025


if ($#argv < 2) then
echo usage: repeat sleep_seconds command arg1 arg2 arg3 ... arg7
exit
endif
set echo
while ($#argv > 1)
$2 $3 $4 $5 $6 $7 $8 $9
echo "... I am going to sleep a little ..."
sleep $1
end
exit

VI-4 • police:
This script will check every ten minutes whether there are processes which have consumed
more than 60 minutes of CPU-time and still do not have the highest nice-value; if there are any
(and if they’re not owned by root), they will be reniced. This version of the script can only be
executed by root.

# police - gj kleywegt - renice long-running non-root processes regularly


# activate with: nohup /nfs/taj/police >& /dev/null &
while (2 > 1)
set allproc=`ps -ef | cut -c9-15 | sort`
foreach proc ($allproc)
if ($proc == "PID") then
else
set root=`ps -lf -p $proc | grep root | wc -l`
if ($root == 0) then
set nice=`ps -lf -p $proc | grep $proc | cut -c33-34`
set cput=`ps -lf -p $proc | grep $proc | cut -c74-76`
if ($cput > 60) then
if ($nice < 39) then
/etc/renice +19 $proc
endif
endif
endif
endif
end
sleep 600
end

VI-5 • forall:
Some UNIX commands (such as tail and lpr) do not allow for wildcards in the filename
specifications. In order to circumvent this problem, the following script takes a file description
containing multiple arguments or wildcards and a command and will execute the command for
each of the files. Examples: forall '*.f' tail -20 and forall '*.ps' lpr -Pqms.

# forall file_id command - gj kleywegt @ 920803/920917


if ($#argv < 2) then

19
Unix for Beginners
____________________________________________________________________________
echo
echo "usage: forall file_id command [arg1 ... arg6]"
echo
exit 1
endif
set sour=$1
set comm="$2 $3 $4 $5 $6 $7 $8"
echo "===> FORALL (" $sour ") DO " $comm
foreach file ($sour)
echo $comm $file
$comm $file
end
echo "Done ..."
exit 0

VI-6 • sln:
This script is a safe soft-linker. In order to prevent you from accidentally erasing files by
swapping the arguments to ln -s, it checks if the first file actually exists. If you put this script
in your private /bin directory, you should put the following in your .cshrc file: alias ln 'echo
USE ~/bin/sln INSTEAD OF ln'.

# sln - a SAFE soft linker - Gerard Kleijwegt @ 920812


if ($#argv < 2) then
echo
echo "usage: sln existing_file link_file"
echo
exit 1
endif
set exist=$1
set linkf=$2
echo "sln - existing file : " $exist
echo " - link file : " $linkf
if (-f $exist) then
\ls -FartCos $exist
if (-f $linkf) then
\ls -FartCos $linkf
echo "WARNING - link file exists - overwrite (Y/N) ???"
set answer=$<
if ($answer == "y") then
\ln -s $exist $linkf
\ls -FartCos $linkf
endif
else
\ln -s $exist $linkf
\ls -FartCos $linkf
endif
else
echo "ERROR - file does not exist"
if (-f $linkf) then
\ls -FartCos $linkf
echo " - but the link file DOES ..."
echo " - maybe you swapped the arguments ???"
echo " - if so, try : sln " $linkf $exist
endif
endif

20
Unix for Beginners
____________________________________________________________________________
VI-7 • dirtar:
If you want to archive or ftp a whole directory (tree), this is most efficiently done by first using
tar to archive all files into one archive file, compressing the resulting archive file and deleting
the original directory (tree). This script does the work for you.

# dirtar - gj kleijwegt @ 920803/921029


if ($#argv < 1) then
echo
echo "usage: dirtar dir_name"
echo
exit 1
endif
set dirnam=$1
echo ... tarring $1 ...
tar cvqqqf - $1 > $1.dirtar
\ls -FartCos $1.dirtar
echo ... compressing $1.dirtar ...
compress -v $1.dirtar
\rm -r $1
\ls -FartCos $1.dirtar.Z
exit 0

VI-8 • tardir:
This script takes an output file from the previous script and restores the original directory
(tree).

# tardir - gj kleijwegt @ 920803/921029


if ($#argv < 1) then
echo
echo "usage: tardir dir_name"
echo
exit 1
endif
set dirnam=$1
echo ... uncompressing $1 ...
\ls -FartCos $1.dirtar.Z
uncompress -v $1.dirtar.Z
echo ... untarring $1 ...
\ls -FartCos $1.dirtar
tar xovpf $1.dirtar
\rm $1.dirtar
\ls -FartCos $1
exit 0

21
Unix for Beginners
____________________________________________________________________________
VII - Miscellaneous
VII-1 • ftp:
File-transfer protocol; can be used to copy files from one computer (e.g. a VAX) to another.
Use something like: ftp -i xray.bmc.uu.se if you want to copy files from XRAY to an SGI or
ESV. If you copy from one UNIX machine to another, you may also use rcp (remote copy) or
uucp (UNIX-to-UNIX copy).

VII-2 • rlogin/telnet:
If you want to log on to another computer (e.g. a VAX or another UNIX machine), use either
rlogin (remote login; will not execute the .login file if you go to a UNIX machine) or telnet,
followed by the name of the host computer.

VII-3 • make:
If you have many or large programs to maintain, make is an excellent utility for you. The idea
is that you define a dependency-tree (the executable depends on the object files and libraries;
each object file depends on a Fortran file plus one or more include files, etc.) in a “makefile”.
If you have edited one subroutine file, all you have to do is type make executable_name, and
only that subroutine will be compiled and all object files and libraries will be linked together.

VII-4 • tar:
If you want to copy files to tape, you may use the tar command (tape archiver). To copy files
to tape, use something like tar cv ~bubba >& ~bubba/tarlist; to restore files, use tar xovp
(filename).

VII-5 • more commands:


file filenames : list the types of the filenames
date : print current time and date
banner text_up_to_10_chars : prints large text on stdout
factor integer : print prime factors of an integer
fold -75 file > newfile : fold long lines
last -5 gerard : print last 5 sessions of user "gerard"
strip file : strip an executable of unused routines
touch file : “touches” a file; changes date-last-changed
alloc : show allocated memory
limit (-h) : show limits (memory etc.)
egrep/fgrep : different versions of grep
fsplit file : split Fortran file into one file per routine
f77 options files : compile and link a Fortran file
cc options files : compile and link a C file
ar : archive and library maintenance
clear : clear terminal screen
finger username : list information about a user
od file : octal, decimal, hex, ASCII file dump

22
Unix for Beginners
____________________________________________________________________________
cal : print calendar
cron : execute commands at a specified date/time
mail/Mail : send and read mail
sort : sort or merge files
stty : set or list terminal characteristics
talk : talk to another user (like phone on the VAX)
time : time a command
which/whereis : locate a program or script
paste : list two or more file side-by-side
setenv : set environmental variables
printenv : list environmental variables
df : show disk usage
dd : file conversion

VII-6 • Files versus processes:


Files contain static information such as operating system commands (script files), Fortran or C
instructions (program files), arbitrary text or data. Processes do the actual work; in general
they execute programs (for example, a UNIX command or a program of your own or a CCP4
program). Each process has an “environment” which it inherits from its parent process.
Whenever a sub-process is started, the parent process waits until it is finished, unless the sub-
process is run in a batch queue or spawned.
In addition, UNIX provides command line interpreters (comparable to VAX/DCL)
which are called shells. You will probably use the standard C-shell (csh), but there are others
(e.g., the Bourne shell and the Korn shell). Each type of shell offers an additional set of
commands.
An example may help to clarify these concepts: suppose that you are in directory
/home/user/xplor and you want run XPLOR with an input file called xplor.inp. You then have
the following options:
(1) type “xplor < xplor.inp”: a sub-process will be created which inherits the characteristics of
the parent (i.e., your terminal session), XPLOR will be run (in the directory /home/user/xplor)
and when it is finished, control will be returned to your terminal.
(2) type “xplor < xplor.inp &”: this does the same, except that the process will now be
spawned; in other words, the XPLOR process will be run as a separate process and you will be
able to continue to work in your terminal session while XPLOR is running.
(3) create a file xplor.com which contains the line “xplor < xplor.inp”, change its protection to
make it executable (chmod) and execute it by typing “xplor.com”; the effect will be the same
as in (1)
(4) now type “xplor.com &”; the effect will be the same as in (2)
(5) modify the file xplor.com to read “xplor < xplor.inp &”; in this case, it doesn’t matter
whether or not you execute or spawn the file, in both cases control will be returned to the
terminal almost immediately
(6) modify xplor.com so that it contains the lines:
# script for running xplor
xplor < xplor.inp &

23
Unix for Beginners
____________________________________________________________________________
If you execute this “script” you will find that it doesn’t work. This is because the “#” on the
first line means that you want the child process to run in a separate C-shell, with its own
environment (directories etc.). This means that the process will start in your home directory
(/home/user), execute the .cshrc file (this can be avoided by starting the script file with
“#!/bin/csh -f” instead of with “#”) and then try to run XPLOR. This will fail since the file
xplor.inp does not exist in your home directory. In order to get the script to work, you have to
insert a line “cd xplor” between the two lines.
(7) source the modified script file; now the same will happen as in (6), except that any
statements executed in the sub-shell will also affect your own shell. Hence, if you have cd and
set statements in the script, they will put you in a different directory and (re)define certain
symbols ! This is the reason why, if you have altered your .cshrc file, you should always
source the new .cshrc file, rather than execute it.

VII-7 • generating files with instructions for all files of a certain kind: for example, get all files
named m24_cav*.o, put the string 'draw ' in front of each of them and put them in a file: \ls -c
m24_cav*.o | sed -e s/"m"/"draw m"/g > odraw.mac. The resulting file can be executed by
O immediately.

VII-8 • sed stream editor; for example: sed -e s/random/rannew/g conezd.com > new.com or
(using a script file) sed -f sed.script test.f > new.f.

VII-9 • X-windows programs (on SGIs at least): xedit - text editor; xfig -
"MacDraw/MacPaint" (use f2ps to get PostScript); xwd - window dump (redisplay with
xwud); xman - man pages; xmag - magnify a part of the screen; xfd - font display; xload -
show cpu load; xcalc - calculator; xclock - guess what; xterm - terminal window; xcalendar -
calendar & time management

VII-10 • use cut to grab certain columns or fields of a stream, for example: tty | cut -c1-9
gives: "/dev/ttyq"

VII-11 • system-dependent Fortran functions and subroutines:


- call flush (iunit) => flushes buffer of output unit IUNIT
- call fdate (str24) => returns date and time
- et = etime (real(2)) => real(1)=elapsed user time,
real(2)=elapsed system time,
etime(..)=sum of these two
- dt = dtime (real(2)) => ditto, but increments since last call
to dtime
- call getenv (nam,val) => returns value of env var NAM in VAL
(both str*)
- call getlog (str*) => returns user's login name
- call idate (imon,iday,iyear)
- call itime (real(3)) => array contains hrs,min,sec
- i = mclock() => returns time accounting info

24
Unix for Beginners
____________________________________________________________________________
- call perror (str*) => print str* and last detected error's
message to stderr
- call gerror (str*) => get last detected error's message
- i = ierrno() => return number of last error
- call qsort (...) => see man page
- call sleep (nsecs) => suspend process for nsecs seconds
- i = alarm(nsecs,extproc) => call external procedure after
nsecs seconds
- call system(str*) => execute str* as a sh-command
- time, ctime, stime, ltime, gmtime => see man pages
- str* = ttynam(iunit) => returns name of tty (or blanks)
- logi = isatty(iunit) => true if iunit is a tty

VII-12 • command-line arguments in Fortran:


- narg = iargc ()
- call getarg (iarg, str*)

VII-13 • dynamic memory allocation in Fortran:


pointer (iptr, arr)
dimension arr(1)
integer malloc,nbytes
...
nbytes = 4*nvars
iptr = malloc(nbytes)
...
call free(iptr)

VII-14 • saving disk space: use compress (and uncompress) to reduce the amount of disk
space occupied by large, infrequently used files. The new file will have “.Z” appended to its
name. Use zcat to look at the contents of compressed text files without uncompressing them.

VII-15 • use the units command to convert between different units, e.g. kg to/from lbs.

VII-16 • the commands w and who tell you who is logged in on your machine

VII-17 • to find the factorisation of an integer number, use the factor command. This is very
useful when you are trying to find grids for CCP4 programs ! CCP4 does not allow you to
have grids which contain a factor > 19; so 134 is invalid since 134 = 2 * 67 and 67 > 19; 132
(2*2*3*11) and 136 (2*2*2*17) would both be okay

VII-18 • some more commands:


bc - arbitrary-precision arithmetic language
nl - adds line numbers; handy in combination with cat/zcat/more, e.g.: nl myfile | more

25
Unix for Beginners
____________________________________________________________________________
tr - translate or delete characters; useful for changing a file from UPPER- to lowercase, for
example: cat infile | tr '[A-Z]' '[a-z]' > outfile
spell - check a file for spelling errors
xedit - quick-and-dirty editor (gets its own window), for example (from O):
O > $ xedit map_macro &
limit - put the following line in your .cshrc file in order to avoid multi-megabyte core dumps:
limit coredumpsize 0
uuencode/uudecode - if you want to send BINARY files by E-mail, uuencode them:
uuencode binary_file coded_file > coded_file
banner - echo a text of up to 10 characters to the screen in BIG letters

26
Unix for Beginners
____________________________________________________________________________
VIII - Index of Unix commands
alias abbreviate common commands IV-17,V-2
alloc list allocated memory VII-5
apropos help on available commands IV-3
ar archive files VII-5
awk editor, stream-based IV-5

banner list text in big letters VII-5,VII-18


bc calculator with arbitrary precision VII-18
bg put job in background IV-18

cal list calendar VII-5


cat list file contents IV-14,IV-15,V-2
cc compile/link C program VII-5
cd change directory IV-11,V-2,VII-6
chmod change file protection IV-13
chown change file ownership IV-13
clear clear terminal screen VII-5
cmp compare files IV-14
compress compress files V-2,VI-1,VI-6,VI-7,VII-14
cp copy files IV-11,VI-2
cron execute commands regularly VII-5
cut extract columns from files V-2,VII-10

date list date and time IV-17,V-2


dd convert files VII-5
df list file-system usage V-2,VII-5
diff list differences between files IV-14,V-2
du list disk usage V-2

echo list to terminal V-2,VI-2,VI-3,VI-5,VI-6,VI-7,VI-8


ed editor, line-based IV-5
egrep version of grep VII-5
emacs editor, full-screen IV-5
ex editor, line-based IV-5
exit exit from a command script VI-2,VI-3,VI-4,VI-5,VI-7,VI-8

f77 compile/link Fortran program V-2,VII-5


factor list prime factors of a number VII-5,VII-17
fg put job in foreground IV-18
fgrep version of grep VII-5
file list type of files VII-5
find find files IV-2,V-2,VI-1
finger list user information V-3,VII-5
fold list file and fold long lines VII-5
fsplit split Fortran source file VI-2,VII-5
ftp copy files from/to other machines V-2,VII-1

grep find/count string in files IV-14,IV-15,IV-17,IV-18,V-2

head list file header IV-14,V-2


history list recent commands IV-16,V-2

jobs list jobs IV-18


jot editor, window-based IV-5

kill interrupt/terminate job IV-18

27
Unix for Beginners
____________________________________________________________________________

last list last sessions of a user VII-5


less list file contents, paginated IV-14
limit list/set hardware limits V-2,VII-18
ln link files IV-12,VI-5
logout stop a session V-2
lpq list print jobs IV-14
lpr print files IV-14,VI-5
lprm remove print job IV-14
ls list files IV-9,IV-10,IV-16,V-2,VI-5,VI-6,VI-7,VI-8,VII-7

Mail mail facility VII-5


mail mail facility VII-5
make manage dependent files VII-3
man help with a command IV-3,V-2
mkdir create directory IV-11
more list file contents, paginated IV-14,IV-15,IV-16
mv move/rename files IV-11

nice execute command with lower priority IV-18


nl add line numbers VII-18
nohup execute command in background IV-18

od list dump of any file VII-5

passwd change password IV-1


paste list two files side by side VII-5
pr list file nicely IV-14,IV-17
printenv list values of environment variables VII-5
ps list processes IV-18,V-2
pwd list present work directory IV-8

rcp copy files from/to other machines VII-1


renice change priority of a command IV-18,VI-4
rlogin log in on other machine VII-2
rm remove files IV-11,IV-17,V-2,VI-2,VI-6,VI-7,VI-8
rmdir remove directories IV-11

sed editor, stream-based IV-5,VII-7,VII-8


set define value for a variable V-2,VI-2,VI-3,VI-4,VI-5,VI-6,
VI-7,VI-8,VII-6
setenv set environment variable V-2,VII-5
sleep wait N seconds VI-3
sort sort files IV-14,IV-15,IV-16,IV-17,V-2,VII-5
source execute script V-2,VII-6
spell check spelling VII-18
stop interrupt job IV-18
strip strip executable VII-5
stty set/list terminal characteristics IV-4,IV-18,V-1,VII-5

tail list file footer IV-14,V-2,VI-5


talk talk to other user VII-5
tar archive files VI-6,VI-7,VI-8,VII-4
telnet log in on other machine VII-2
time time a command V-2,VII-5
touch change access date of files VII-5
tr translate/delete characters VII-18
tty list terminal VII-10

28
Unix for Beginners
____________________________________________________________________________
unalias remove an alias IV-17
uncompress decompress files V-2,VI-8,VII-14
units convert unit systems VII-15
unset remove a variable VI-1
uucp copy files from/to other machines VII-1
uudecode convert ASCII file back to binary VII-18
uuencode convert binary files to ASCII VII-18

vi editor, full-screen IV-5

w list current users VII-16


wc count lines, words, bytes in files IV-14,IV-15,IV-17
whereis list filename of program/script VII-5
which list filename of program/script VII-5
who list current users IV-15,IV-16,V-2,VII-16

xcalc calculator VII-9


xcalendar calendar and time manager VII-9
xclock clock VII-9
xedit editor, window-based IV-5,VII-9,VII-18
xfd show available fonts VII-9
xfig draw pictures VII-9
xload show CPU load VII-9
xman help VII-9
xterm terminal window V-2,VII-9

zcat list contents of compressed text file VII-14


zip editor, window-based IV-5

29
Unix for Beginners
____________________________________________________________________________
IX - Inverted index of Unix commands
abbreviate common commands alias IV-17,V-2
add line numbers nl VII-18
archive files ar VII-5
archive files tar VI-6,VI-7,VI-8,VII-4

calculator xcalc VII-9


calculator with arbitrary precision bc VII-18
calendar and time manager xcalendar VII-9
change access date of files touch VII-5
change directory cd IV-11,V-2,VII-6
change file ownership chown IV-13
change file protection chmod IV-13
change password passwd IV-1
change priority of a command renice IV-18,VI-4
check spelling spell VII-18
clear terminal screen clear VII-5
clock xclock VII-9
compare files cmp IV-14
compile/link C program cc VII-5
compile/link Fortran program f77 V-2,VII-5
compress files compress V-2,VI-1,VI-6,VI-7,VII-14
convert ASCII file back to binary uudecode VII-18
convert binary files to ASCII uuencode VII-18
convert files dd VII-5
convert unit systems units VII-15
copy files cp IV-11,VI-2
copy files from/to other machines ftp V-2,VII-1
copy files from/to other machines rcp VII-1
copy files from/to other machines uucp VII-1
count lines, words, bytes in files wc IV-14,IV-15,IV-17
create directory mkdir IV-11

decompress files uncompress V-2,VI-8,VII-14


define value for a variable set V-2,VI-2,VI-3,VI-4,VI-5,VI-6,
VI-7,VI-8,VII-6
draw pictures xfig VII-9

editor, full-screen emacs IV-5


editor, full-screen vi IV-5
editor, line-based ed IV-5
editor, line-based ex IV-5
editor, stream-based awk IV-5
editor, stream-based sed IV-5,VII-7,VII-8
editor, window-based jot IV-5
editor, window-based xedit IV-5,VII-9,VII-18
editor, window-based zip IV-5
execute command in background nohup IV-18
execute command with lower priority nice IV-18
execute commands regularly cron VII-5
execute script source V-2,VII-6
exit from a command script exit VI-2,VI-3,VI-4,VI-5,VI-7,VI-8
extract columns from files cut V-2,VII-10

find files find IV-2,V-2,VI-1


find/count string in files grep IV-14,IV-15,IV-17,IV-18,V-2

30
Unix for Beginners
____________________________________________________________________________
help xman VII-9
help on available commands apropos IV-3
help with a command man IV-3,V-2

interrupt job stop IV-18


interrupt/terminate job kill IV-18

link files ln IV-12,VI-5


list allocated memory alloc VII-5
list calendar cal VII-5
list contents of compressed text file zcat VII-14
list current users w VII-16
list current users who IV-15,IV-16,V-2,VII-16
list date and time date IV-17,V-2
list differences between files diff IV-14,V-2
list disk usage du V-2
list dump of any file od VII-5
list file and fold long lines fold VII-5
list file contents cat IV-14,IV-15,V-2
list file contents, paginated less IV-14
list file contents, paginated more IV-14,IV-15,IV-16
list file footer tail IV-14,V-2,VI-5
list file header head IV-14,V-2
list file nicely pr IV-14,IV-17
list file-system usage df V-2,VII-5
list filename of program/script whereis VII-5
list filename of program/script which VII-5
list files ls IV-9,IV-10,IV-16,V-2,VI-5,
VI-6,VI-7,VI-8,VII-7
list jobs jobs IV-18
list last sessions of a user last VII-5
list present work directory pwd IV-8
list prime factors of a number factor VII-5,VII-17
list print jobs lpq IV-14
list processes ps IV-18,V-2
list recent commands history IV-16,V-2
list terminal tty VII-10
list text in big letters banner VII-5,VII-18
list to terminal echo V-2,VI-2,VI-3,VI-5,VI-6,
VI-7,VI-8
list two files side by side paste VII-5
list type of files file VII-5
list user information finger V-3,VII-5
list values of environment variables printenv VII-5
list/set hardware limits limit V-2,VII-18
log in on other machine rlogin VII-2
log in on other machine telnet VII-2

mail facility Mail VII-5


mail facility mail VII-5
manage dependent files make VII-3
move/rename files mv IV-11

print files lpr IV-14,VI-5


put job in background bg IV-18
put job in foreground fg IV-18

remove a variable unset VI-1


remove an alias unalias IV-17

31
Unix for Beginners
____________________________________________________________________________
remove directories rmdir IV-11
remove files rm IV-11,IV-17,V-2,VI-2,VI-6,
VI-7,VI-8
remove print job lprm IV-14

set environment variable setenv V-2,VII-5


set/list terminal characteristics stty IV-4,IV-18,V-1,VII-5
show CPU load xload VII-9
show available fonts xfd VII-9
sort files sort IV-14,IV-15,IV-16,IV-17,
V-2,VII-5
split Fortran source file fsplit VI-2,VII-5
stop a session logout V-2
strip executable strip VII-5

talk to other user talk VII-5


terminal window xterm V-2,VII-9
time a command time V-2,VII-5
translate/delete characters tr VII-18

version of grep egrep VII-5


version of grep fgrep VII-5

wait N seconds sleep VI-3

32

Potrebbero piacerti anche