J. Jenkinson
May 1992
This document is neither rigorous nor complete - it is intended as a quick easy to read guide for anyone new to the Unix operating system to find out how to do what they are most likely to want to do.
In the following pages, system replies and prompts, and commands and
their arguments are shown in normal typewriter font. File names and
arguments or parameters which must be replaced with the appropriate
input are enclosed within <...>. File names referred to in the text
are italicised. This is not always the case for file names within tables
of example commands. The same command syntax as used
in the UNIX manual pages will be followed:
| [ ] | brackets mean that enclosed item is optional |
| ... | anything followed by ellipses may be repeated more than once |
The Unix shell is the command interpreter or user interface to the operating system. There are different ``varieties'' of shells, for example the Bourne Shell(sh), the C shell (csh), the Korn shell (ksh), the job shell (jsh, an enhanced C shell called tcsh.
Please note that the discussion in this guide assumes that you are using the tcsh (or the C) shell.
When you first login you will ``be'' in your home directory. All your permanent files and subdirectories lie under your home directory. See Section 8.1 for a description of the directory structure of the file system. As well as having this default ``landing place'' within the file system when you first login, you also have a default shell, the tcsh shell.
The files .login and .cshrc in your home directory are supplied for you when your account is first established. These files are standard UNIX files used to set up your environment. Every time you log in the .cshrc script, and then the .login script, are run automatically for you. Every time you start up a new C shell, the .cshrc script is run again, but not the .login script. Thus the .login file should contain commands and environment variable definitions that only need be executed at the beginning of each login session, e.g. commands for initializing your terminal settings and definitions of environment variables.
The .cshrc script should include definitions of any aliases, and definitions of variables that are used by the shell, but that are not environment variables (such as the history, prompt, path and cdpath variables). Aliases are useful if you commonly need to type in the same long command, as you can alias the command to a suitable short name chosen by yourself. Thereafter, instead of typing in the long command, you can type in its alias.
Enter more .cshrc to see the contents of your default .cshrc. A ``#'' at the start of a line precedes a comment. These comments should enable you to see how to change your .cshrc to suit yourself if necessary. Note however that if you make an error when changing any of your ``dot'' files which are automatically sourced whenever you log in, you may find that you are unable to log in the next time. A work-around for this is to use ftp to get the offending file, edit it again on another system, then ftp it back to the problem system. It is best to check your changed ``dot'' file before you log out. To do this, first make it executable, e.g.
chmod +x .cshrc
and then execute it as a normal shell script. (Note that if you source it at this stage and it does contain an error, you will be automatically logged out.)
If you find that you have corrupted any of your ``dot'' files beyond redemption, it is always possible to get us to give you the default files which all accounts are set up with in the first place.
To view your default environment variable settings, enter the command env. A list of shell variables and their current values will be printed on your screen. Some examples of environment variables which may be set by you are given in the table below.
| Environment Variable | Purpose |
| HOME | Contains the full pathname of your home directory |
| SHELL | Determines which shell program will be used when you do a shell escape |
| from a program such as vi or mail | |
| TERM | Contains the terminal type, e.g. vt100 |
| LOGNAME | Contains your login name |
| PROJECT | The project which is being charged for this interactive session |
| The file where the mail program looks for new mail messages | |
| MBOX | The file the mail program moves your mail to after you have looked at it |
| LPDEST | The default printer which is used if commands such as lp are used |
| without a destination printer | |
To view your C shell variables, enter the command set. Some examples of C shell variables which may be set by you are given in the table below.
| C Shell Variable | Purpose |
| cdpath | The directories to be searched when you enter a cd subdir command |
| filec | If set, enables file name completion |
| history | Determines how many previous commands will be kept in the |
| command history list | |
| ignoreeof | If set, prevents accidental logging off when typing CTRL-D |
| noclobber | If set, prevents overwriting an existing file when output from a |
| command is redirected | |
| notify | If set, a message will be sent to you when a background job |
| finishes running | |
| path | The directories to be searched for the commands which you issue |
| prompt | Sets the string to be used for the primary command prompt |
If you wish to use an alternative shell, such as the Korn shell, you will need to add the following lines at the end of your .login file:
setenv SHELL /usr/bin/ksh
exec /usr/bin/ksh
To execute your .profile file at this point, enter
.profile
To use the Bourne shell, replace ksh with sh in the lines above.
To log out of the Korn shell or Bourne shell, type exit rather than logout.
If you require more information on a specific topic, the man command
can be used to display the relevant pages of the reference manuals. Enter
man <topic>, where topic is the name of the command, library, or local
utility. The manual pages will be displayed a screen at a time. Press the
<RETURN> key to display the next screen.
Note that the man pages are all written in a similar format. The following are some examples of the typical headings under which the information is given:
| NAME | gives the name of the command, and a one-sentence description of the purpose of the command. |
| SYNOPSIS | gives the correct syntax for the use of the command with its
various options and arguments. In the synopsis section, items enclosed in square brackets ( [ ] ) are optional. A list of items separated by vertical bars ( | ) indicates that one and only one of the list is to be used. An underlined item is to be replaced with your filename, or a number, depending on the context. Ellipses following an item indicate that it may be repeated any number of times. |
| DESCRIPTION | gives a more detailed explanation of the purpose of the command, and helps to shed some light on the possible arguments for the command. |
| OPTIONS | describes each possible option for the command. |
| EXAMPLES | perhaps the most useful part of the description. |
| ENVIRONMENT | describes the list of environment variables which can be set by you, and which will influence the operation of the command. |
| FILES | tells you which files are either read by the command to produce your output, or are created by the command. This does not include the files whose names you specify as arguments to the command. |
| SEE ALSO | gives you a list of other related commands whose manual pages you may find useful to browse. |
| NOTES | is for anything which does not conveniently fit into the other categories. |
| BUGS | gives the known limitations of the command. |
If the actual name of the command is not known, you can search the titles and brief descriptions in the man pages for a string by entering
man -k string
This will return command names and brief descriptions in which string was found.
The following is a list of the most commonly used UNIX commands, and it is intended for quick reference purposes only. Details and further options can be obtained by using the man command. The list is not in alphabetical order, instead a vague grouping of commands has been attempted.
Miscellaneous Essential Commands
| Command | Description | Usage Example | Notes on Example |
| passwd | change your password | passwd | You are prompted for your old password and then your new password. |
| man | view the online documentation | man cd | The manual pages for the cd command are displayed at your terminal. |
| echo | write to standard output | echo hello | Writes hello to the screen. |
| file | lists the file type | file myfile | Displays whether myfile is data, a script file, text, executable, etc. |
| send or read electronic mail messages | mail without any arguments will place you in the mail program and will display your list of received mail messages. | ||
| mail logname@address | Send mail to person with name logname and Internet machine address address | ||
Commands for Viewing Files
| Command | Description | Usage Example | Notes on Example |
| cat more pg | list a file on standard output (default standard output is the terminal) | cat .cshrc | The contents of the .cshrc file are displayed. cat displays the whole file at once, whereas more and pg display a screen at a time. |
| head | list the beginning of a file on standard output | head longfile | The first 10 lines of longfile are displayed. |
| head -50 longfile | The first 50 lines of longfile are displayed. | ||
| tail | list the end of a file on standard output | tail longfile | The last 10 lines of longfile are displayed. |
| tail -70 longfile | The last 70 lines of longfile are displayed. | ||
Commands For Copying and Moving Files
| Command | Description | Usage Example | Notes on Example |
| cp | copy a file | cp oldfile newfile | A copy of oldfile is made, and saved as newfile. |
| dd | convert and copy a file | dd if=infile of=ofile conv=lcase | The file infile is converted to lower case and the result is saved in the file ofile. |
| dd if=infile of=ofile | infile with block size of 800 | ||
| ibs=800 obs=512 | bytes is converted to ofile with block size of 512 bytes. | ||
| rcp | copy a file between two UNIX hosts which are both on the Internet | rcp localhost:file1 otherhost:file2 | file1 on the machine localhost is copied to file2 on the machine otherhost. The localhost: can be omitted. See Section 8.3.1 |
| ftp | transfer files using the file transfer protocol | ftp hostname | This establishes an ftp connection to the specified host. See Section 8.3.2 for a description of using ftp. |
| mv | move a file | mv oldfile newfile | oldfile is moved (renamed) to a file called newfile. |
| rm | remove / delete a file | rm temp | Remove (delete) the file called temp. |
Commands for Managing Files and Directories
| Command | Description | Usage Example | Notes on Example |
| ls | list the contents of a directory | ls dir | If the directory name is omitted, current directory is assumed. |
| ls -l dir | -l = long format | ||
| ls -a dir | -a = include hidden files | ||
| chmod | change the access permissions of a file | chmod ugo+rwx file | Allow owner, group and others read, write and execute permission for file. |
| umask | set or display file creation mask | umask 022 | Gives owner full permissions and others read and execute permission for any new file created. |
| chown | change file ownership | chown abc123 yourfile | Changes the ownership of yourfile to abc123. |
| chgrp | change group ownership of file | chgrp 123 yourfile | Changes yourfile so that group 123 can access the file using the group permissions. |
| pwd | print working directory | pwd | Gives the full pathname of the directory in which you are currently working. |
| cd | change directory | cd subdir | Change to a subdirectory of your current directory or a directory specified in the CDPATH variable. |
| cd .. | Change to the directory immediately above. | ||
| cd ../dir2 | Go to the directory above then into its subdirectory, dir2. | ||
| cd /home/group/user | Change to the directory specified by the full pathname. | ||
| cd | Change to your own home directory. | ||
| mkdir | make / create a new directory | mkdir subdir | Creates a directory called subdir as a subdirectory of your current directory. |
| rmdir | remove / delete a directory | rmdir subdir | Removes subdir, only if it is empty (contains no files). |
Commands for Printing, Editing, and Searching in Files
(Note that the printing commands assume that you have a printer accessible
from your unix system. )
| Command | Description | Usage Example | Notes on Example |
| lp | print a file | lp file -d mylp | Print file on the printer called mylp. |
| lpstat | display printer status | lpstat -d mylp | Displays the status of the printer mylp. |
| cancel | cancel a print job | cancel mylp-1234 | Cancels a print job with request-id mylp-1234. |
| pr | format file for printing | pr file |
Adds a heading to each page of printed output. |
| vi | invoke the vi editor | vi newfile | Edit the file newfile. If newfile does not exist, an empty file is opened for editing. |
| wc | display a count of lines, words, and characters in a file | wc file1 | |
| diff | compare two files and show the differences | diff file1 file2 | Compares file1 with file2. |
| grep | search for a regular expression in a file | grep this file1 | Prints out every line of the file file1 which contains the string this. Can also use wildcards in the search pattern. |
| tr | translates characters | tr 'a' 'A' < file > nfile |
Convert all occurrences of a in file to A and save the result in nfile. |
| sed | stream editor (non-interactive editor) | sed '/fred/d' file >nfile | Delete all lines containing the string fred in file and save the result in nfile. |
Commands for Archiving and Compressing Files
| Command | Description | Usage Example | Notes on Example |
| ar | maintain groups of files combined into a single archive file | ar rcv libname memb | Create the archive file called libname and store in it the file memb. |
| ar x libname memb | Extract file memb from the archive library. | ||
| ar d libname memb | Delete file memb from the archive library. | ||
| ar t libname | List the table of contents of the archive library. | ||
| tar | create tape archive of files | tar cfv tarfile dir | Create a file tarfile, or write to magnetic tape tarfile, all the files in the directory dir. |
| tar xvf tarfile | Extract the files from tarfile. | ||
| tar tf tarfile | List the table of contents of tarfile. | ||
| compress | compress a file | compress bigfile | bigfile is compressed and the compressed version is called bigfile.Z The original bigfile is removed. |
| uncompress | uncompress a file | uncompress bigfile.Z | bigfile.Z is uncompressed and the original bigfile is recovered. |
Commands for Compiling, Debugging, and Displaying Resource Usage
| Command | Description | Usage Example | Notes on Example |
| cc | compile a C program | cc file.c | Compile the C source code in file.c and produce an executable in a.out. |
| cc -o prog file.c lib.a | Compile the source code in file.c, link with the required object modules in lib.a, and save the executable in the file prog. | ||
| f90 | compile a FORTRAN program | f90 file.f90 | Compile the FORTRAN source in file.f90 and produce an executable in a.out. |
| f90 -o prog file.f90 lib.a | Compile the source code in file.f, link with the required object modules in lib.a, and save the executable in the file prog. | ||
| make | maintain and update related programs and files | make prog.o | Looks for a file calledmakefile or Makefile in the current directory, and according to the rules/information in that file, will create or recreate prog.o if it is ``out of date'' with respect to the files used to create it. |
| sdb | debug source code | sdb prog.exe | Debug prog.exe. |
| ps | display the status of the current processes on the system | ps | Display processes associated with the current interactive session only. |
| ps -ef | Display all processes in full format. | ||
| quota | display users disk quota and usage | quota -v | Display users quota on all mounted file systems where quotas exist. |
| df | show free disk space on file systems | df | |
| du | show the number of 512byte disk blocks used per directory or file | du | Used without any arguments, du returns the sizes of files and directories below the current directory. |
Commands for Monitoring Users and Processes
| Command | Description | Usage Example | Notes on Example |
| who | shows who is logged on to the system | who | Used without any arguments, who returns the login name, terminal name, and login time for each current user. |
| finger | display information about users | finger logname | Returns the full name and other information about the user logname. |
| kill | terminate a process which is owned by you | kill -9 1234 | Terminate the process with process id 1234. The -9 signal cannot be ``caught'' and therefore is a sure kill. |
| jobs | display information about stopped or background jobs | jobs | |
| stop | stop a background job | stop %1 | Stops job 1 which was running in the background. |
<CTRL>z |
stop current foreground process | ||
| fg | resume a stopped job in foreground | fg %1 | |
| bg | resume a stopped job in background | bg %1 | |
| nice | run a command at low priority | nice 4 ps | When this command is issued in csh the ps command is run with the default nice value incremented by 4. The higher the nice value, the lower the priority of the job. |
In addition to the above list, some commands
may be available from public domain software sources. These are described in
the following table.
| Command | Description | Usage Example | Notes on Example |
| emacs | invoke the Emacs editor | emacs file | Open the emacs editor and read in file to be edited. To quit from the editor, use <CTRL>x <CTRL>c . See Section 6.2. |
| uemacs | invoke the MicroEmacs editor | uemacs file | Open the uemacs editor, which is very similar to the emacs editor above, but has less functionality, and some different key bindings. See Section 6.2. |
| less | list a file on standard output (i.e.terminal) | less file | less is like more or pg , with some additional useful features. |
In general, an executing program requires input data and produces output data and error messages. There are three standard files for this purpose: the standard input file (stdin), the standard output file (stdout) and the standard error file (stderr). Unless otherwise specified, the standard input is taken from the keyboard, standard output is written to the terminal screen, and standard error is also written to the terminal screen.
If the input data for an executable program is contained in an
ordinary file on disk, the input redirection symbol ( < ) can be
used to specify this file as the standard input when the program is
run. For example, suppose the executable program is called
compute_average, and the data for which an average is required is
stored in the file daily_expenses, then the command
compute_average < daily_expenses
will cause the program to be run using the file daily_expenses as standard input. Any output generated by the program will appear on the terminal screen.
> and >> ) can be used to cause the
standard output to be written to a specified disk file, either
overwriting the file if it already exists, or appending to the end of
the file. If the file does not already exist it is created. For
example, the output of the who command can be written to the file
current_users by specifying
who > current_users
or the output of the who command can be appended to the file users_log by specifying
who >> users_log
The symbols for error redirection are 2> and 2>> when using the
System V shell (sh), and are >& and >>& when using the C
shell (csh), depending on whether the specified file is to be
overwritten or appended to. In the following example the error
messages resulting from the compress command are written to the
file cmperror, assuming the command is run under csh
compress hugefile >& cmperror
The command to append the error messages to cmperror when the file is decompressed using the uncompress command would be
uncompress hugefile.Z >>& cmperror
Note that if there was any standard output produced by the command it would also be directed to cmperror as it is not possible to redirect standard error separately from standard output under csh. (It is possible to redirect these files separately under sh.)
It is possible to read the standard input from a disk file and also write the standard output to another disk file. For example, to store the computed average daily expenditure in a file called expav the command would be
compute_average < daily_expenses > expav
The standard output from one command can be passed as standard input to
another command through the use of the pipe symbol (
). In the
following example the result of the grep command on infile, searching
for occurrences of this, is piped to the sort command, and the
result is saved in the file outfile.
grep this infile | sort > outfile
A number of characters have a special meaning when read by the shell.
Examples are the file redirection characters < and >, the pipe
character
, and & which is used to run a job in the background.
These characters are often call shell metacharacters. Other examples
are:
<SPACE> |
are used as separators between command-line arguments |
and <TAB> |
|
| ; | is used to separate commands entered on the same line. For example, cd; pwd; ls -l can be entered as a single command rather than on three separate lines. |
| $ | is used to precede a variable name. For example, to change to the home directory, cd $HOME could be used. |
| ` | (back quotes) are used in command substitution. For example, echo `date` would use the output from the date command as the argument to echo. |
| ? | matches any single character in file name substitution. For example, ???.f would match abc.f but not a.f or abcd.f |
| * | matches any string, including the null string, in file name substitution. For example, *.f matches any file ending in .f |
| [...] | matches any of the enclosed characters in file name substitution. For example, [Aa]*.f would match any file beginning with A or a and ending with .f. Ranges of characters can also be specified, as in [A\...Z]. |
\ |
is used to remove the special meaning of the following character. For example,
grep \* a.f could be used to search for the character
* in the file a.f. If the \ was omitted,
the shell would expand the * to match all file names before
executing grep,
and the search would fail. |
| ' | (single quotes) are used around a string to prevent the shell from
interpreting any of the
enclosed characters. For example, grep '$4' *.f would
search for the string $4, whereas
grep $4 *.f would cause the shell to replace $4 with
the fourth argument from the
command line before executing grep. |
" |
(double quotes) are used around a string to prevent the
shell from interpreting any of the
enclosed characters except for $, `, ' and \. Variable
substitution
and command substitution still occur inside strings enclosed in
double quotes. For example,
echo "$LOGNAME logged in at `date`" >> users_log could
be used to obtain a record
of when users logged in. |
This section is intended to give only the barest essentials of vi, enough to show a novice how to open a file, make simple changes and then save or quit. Even though vi is not the most user friendly or powerful of editors it is extremely useful to be familiar with it, as it is the standard editor on all UNIX systems. Consult one of the many UNIX references for more details.
Enter the command
vi file1
If file1 exists, a copy of it is opened for editing. If file1 does not exist, vi displays a blank screen and text added can then be saved to a file(s) at any later time.
vi operates in two modes: command mode and input mode.
Command mode allows you to move around the file, search for strings and delete or alter text. You can also enter line-editing commands or escape to the shell by typing a colon (:) from command mode. When you start vi you are in command mode.
Input mode allows you to enter text. To change to input mode from
command mode, first position the cursor then press, for example, the i
(insert) key. After typing in text press the <ESC> key to go back to
command mode. It is recommended that you create a file in your home
directory called .exrc containing the line
set showmode
When you are in input mode you will then get a message saying INPUT MODE in the bottom righthand corner of the screen.
Commands for moving around files
| Key Combinations | Result |
<CTRL>d |
scroll forward half a screen |
<CTRL>f |
scroll forward a full screen |
<CTRL>b |
scroll backward a full screen |
<CTRL>u |
scroll backward half a screen |
h or <BACKSPACE> |
move cursor left ( |
| j | move cursor down ( |
| k | move cursor up ( |
l or <SPACEBAR> |
move cursor right ( |
| 0 | go to the beginning of the current line |
^ |
go to first nonblank character on the current line |
| $ | go to the end of the current line |
| fx | move the cursor to the right to the character x |
| Fx | move the cursor to the left to the character x |
| tx | move the cursor to the right to the character just before x |
| Tx | move the cursor to the left to the character just after x |
| G | go to the end of the file |
| nG | go to line n |
-- |
go to previous line |
+ or <RETURN> |
go to next line |
| H | position cursor to first line on screen |
| M | position cursor to middle line on screen |
| L | position cursor to last line on screen |
Commands for deleting, replacing, undoing, joining lines
and cutting and pasting
| Key Combinations | Result |
| /string | search for string. Cursor moves to string if found. To make the search case insensitive, type the command :set ic before the search command (:set noic turns off ``ignore case'' mode) |
| string | search backward for string |
| n | repeat the last search |
| N | repeat the last search in the opposite direction |
| x | delete the character under the cursor |
| X | delete the character to the left of the cursor |
| dw | delete current word |
| dd | delete current line |
| D | delete from cursor to end of line |
| rx | replace character under cursor with x |
| R | replace characters typed over until <ESC> key is pressed |
| cc | replace all the characters in the line |
| C | replace the remaining characters in the line |
| u | undo last change |
| U | undo all changes to current line |
| J | join the line below at end of current line |
| . | repeat last command which created, deleted or changed text |
~ |
change case of character under cursor |
| yy | copy the current line to buffer |
| 10yy | copy the next 10 lines to buffer |
| p | paste buffer in after the current line |
| P | paste buffer in before the current line |
vi is line oriented. If you start somewhere in a line and press X repeatedly, the cursor moves to the left screen boundary and stops. There is no wrap back as with some other editors such as emacs.
Line-editing commands for searching, substituting,
deleting, positioning, and saving, quitting, or reading files
| Key Combinations | Action |
| :g/xxx/p | print all lines containing xxx |
| :s/xxx/yyy/ | replace first occurrence in current line of xxx with yyy |
| :s/xxx/yyy/g | replace all occurrences in the current line of xxx with yyy |
| :1,$ s/xxx/yyy/g | replace every occurrence in the file of xxx with yyy |
| :1,15 s/xxx/yyy/ | replace first occurrence in lines 1-15 of xxx with yyy |
| :.,$ d | delete from current line to end of file |
| :# | print the current line number |
| :25 | position the cursor at line 25 |
| :r file1 | read the contents of file1 |
| :w | write the current buffer back to the file vi was opened with |
| :w file2 | write the current buffer to file2 |
| :q! | quit without saving any changes made to the file |
| :wq | save the current buffer to file and quit |
| ZZ | save the current file and quit (equivalent to :wq) |
| :!command | execute the shell command, then return to edit |
Commands to enter input mode
| Key | Result |
| a | enter text starting AFTER the cursor |
| A | enter text starting at the end of the current line |
| i | enter text starting AT the cursor |
| I | insert text at the beginning of the current line |
| O | open a new line ABOVE the current line |
| o | open a new line BELOW the current line |
After pressing one of these keys, type in text. The <BACKSPACE> (or
<DELETE>) key deletes characters while in input mode. The <ESC>
key switches input mode off, and returns you to command mode.
The MicroEmacs and Emacs editors are both commonly available on unix systems, but their availability will depend on your system administrator. As suggested by their names, they are similar editors with MicroEmacs having a reduced functionality compared with Emacs. It is not true to say that MicroEmacs is a subset of Emacs however, as not all the key bindings are identical. They are public domain software, and as they do not come standard with UNIX operating systems, you cannot rely upon them being available on UNIX systems.
To edit a file using the MicroEmacs editor, enter the command
uemacs filename
The man page for uemacs gives no real information on how to use the editor, but it does have the essential information on how to save your changes, get help from within uemacs, and how to exit.
Emacs is a powerful text editor provided by the Free Software Foundation, a non-profit organisation dedicated to providing high quality public domain software. To open either a new or existing file for editing with the Emacs editor, enter the command
emacs filename
The command to exit the editor is <CTRL>x<CTRL>c
The electronic mail service is a useful way to communicate with other users on the network. Through it, it is possible to send mail to others, receive mail, and forward mail which you have received to others.
Described below is the standard UNIX mailer which comes with System V Release 4. You should use a local system as your primary mail system and to automatically forward any mail sent to you on other machines to that local system (see Section 7.1.2).
To send a mail message (to anusf for example), enter the command
mail help@nf.apac.edu.au
The text of the message is then entered, and can be as many lines as
required. To terminate the message, press <CTRL>d. The message as
typed in will be sent to the specified mail address. Alternatively,
if the mail message to be sent to user fred on machine home
is contained in the file memo, the command
mail fred@home.anu.edu.au < memo
can be used.
Entering the command mail without any arguments places you in the mail
program, which displays your list of received mail messages. (If you
have no mail waiting for you the message ``No mail.'' is printed
on the screen and you are returned to your shell.) Pressing the
<RETURN> key will display the first unread message in the list.
After this you may wish to enter h to redisplay the list of
messages, or a ? to see the list of available commands. Enter q
to exit the mail program.
If you wish to read your mail on another system (e.g. your own workstation), you can achieve this by creating a .forward file in your home directory on other machines. The .forward file simply contains your address on the other system. For example, suppose a user wishes to receive their mail on the machine oldfaithful, where they have a username of joe. Their .forward file should contain the single line:
joe@oldfaithful.uni.edu.au
The UNIX file system is often referred to as an ``upside down tree'' structure. At the top of the file system is the root directory, denoted with a single slash (/). Contained in this directory are the first level of branches in the tree structure, such as the subdirectories /usr, /home, /var, /stand, /dev, /etc, /tmp and a number of ordinary files. These directories contain other subdirectories and ordinary files.
A new user who belongs to group 123 and is assigned a user name of abc123 is given a personal place in the file system to store their files. This is referred to as their home directory, and in the above example will have a full pathname of /home/123/abc123. The full pathname or name of their .cshrc file will thus be /home/123/abc123/.cshrc. The first slash denotes the root directory, whereas the slashes between the other directory names and the final file name act as separators. Thus the home directory is a subdirectory of /home/123, which is in turn a subdirectory of /home. It is recommended that users order their files within their home directory by using a logical system of subdirectories. See the mkdir, rmdir, cd, cp, mv, pwd and ls commands in Section 4.
Instead of referring to a file by its full pathname as above, it is possible to specify its path relative to the current directory. For example, when abc123 first logs in the user will be in their home directory /home/123/abc123 and the relative path of their .cshrc file is simply .cshrc. If they then use the command
cd /home/123
to change their current working directory, then the relative pathname of their .cshrc file would be abc123/.cshrc. Note that it is important not to put a slash at the beginning of a relative pathname, as this would cause it to be interpreted as a full pathname (beginning at the root directory).
| Symbol | Description | Usage Example | Notes |
|---|---|---|---|
~ |
home directory | cp file1 ~ |
The file file1 in the current directory is copied to a file of the same name in your home directory. |
| . | current directory | tar cf ~/tarfile . |
All files in the current directory are archived to file tarfile in the home directory. |
| .. | parent directory | cd .. | Change to the directory immediately above the current directory. This is referred to as the parent directory. |
Every file has associated with it a set of file access permissions which can only be changed by the file's owner or the system administrator. These permissions determine the security of your files. When you first create a file, a set of default access permissions are assigned to it automatically. These defaults are determined by the umask command which is executed in your .cshrc file. Directories also have a set of file permissions which greatly affect the security of the files within the directory. The permission modes for ordinary files and directory files have somewhat different ramifications.
The command
ls -l
will list the files in the current directory and include the permission modes of all the files. For example, the command might result in the following if there are the two files apples and oranges in the current directory
-rwxr-xr-x 1 ownidn 512 Jan 21 11:33 oranges
-rw-r---- 1 ownidn 47 Feb 03 16:15 apples
The first dash (-) means that these are ordinary files. (If they were directories there would be a d instead of the first dash.) The next nine characters are the permission bits, the first three being for the user (i.e. owner) of the file, the next three for members of the owner's group, and the last three for others. The letters indicate which of read (r) write (w) or execute (x) permission the user, group or others have to the file. In the example for the file oranges, the owner/user has read, write and execute permission, group members have read and execute permission only, and others have read and execute permission only. For the file apples, the owner/user may read and write to the file, group members may read the file, and others cannot read, write or execute the file. For ordinary files, to be able to read a file means that you can copy it, list it at a terminal, or generally view the contents of the file. Write permission means that you can alter the file's contents, and execute permission means it can be run as a program or shell script.
Directory file permissions are similar to ordinary file permissions in that there are nine permission bits, three for the owner/user of the directory, three for group members and three for others. However, for directories, read access determines whether one can use the ls command to list the contents of the directory, write access determines if files can be deleted from or added to the directory, and execute permission determines if the directory can be used to access the files it contains. Denying execute access permission effectively denies access to the contents of the directory. An appropriate set of directory file permissions to allow members of your group to read or copy the files in your directory are
drwxr-x---
If you wish group members to be able to add or delete files from your directory, you need to give them write permission as well:
drwxrwx---
The nine permission bits can be viewed as a three-digit octal number. For example, the file oranges above has an access mode of 755, and apples has a mode of 640. In your .cshrc file the umask command is used to set the file creation mask to 077. This mask is XORed with 666 for files and 777 for directories to generate the permissions for new files. This mask results in the owner having read and write permission for files and read, write and execute permission for directories, with the group and others having no permissions. To give your group read and execute permission for any new file that you create, change the umask value to 027.
The chmod command can be used to change the access permissions of existing files. The command uses the codes u for the user/owner, g for the group, o for others, + to add a permission, - to remove a permission, r for read access, w for write access, and x for execute permission. The format of the command is then
u + r
chmod g - w filename
o x
For example, if it was required to add read permission for others to the file apples, the command would be
chmod o+r apples
To remove execute permission for everyone from the file oranges, the command could be
chmod ugo-x oranges
or
chmod a-x oranges
since the code a stands for all of user, group and others. The command for changing file permissions is the same regardless of whether you are dealing with an ordinary file or a directory.
You are automatically the owner of any files which you create. As described above, it is possible to give access to the file either to other members of your group, or to everyone who has an account on the machine.
User accounts are set up a primary group. It is the primary group which is taken by default as the group for a file when determining access permissions.
A user may also be connected to secondary groups. If you wish to change the group which can access a file you must do so explicitly for that file using the chgrp command. For example, if user abc123 has 123 as their primary group, and they wish to change the group of the file bananas to be z01, which is one of their secondary groups. They enter the command
chgrp z01 bananas
This has the effect of allowing other members of group z01 to access the file bananas according to the group permissions which the file has, regardless of whether or not they are in group 123. It also means that users in group 123, who are not also members of z01, will not be able to access the file under group permissions. Only the owner of the file may change its group. To see which groups you belong to, use the groups command.
It is also possible to change the ownership of a file. The catch is that you have to own a file to change its ownership, so once you change the ownership, you lose the ability to change it back again. For example, if you wish to give user klm500 ownership of the file bananas, the command would be
chown klm500 bananas
As added security for particularly sensitive files you can use file encryption. The utility des will encrypt a file, using a key which you supply. This key may be specified by you on the command line when you invoke des, otherwise you will be prompted for it. To encrypt the file secret with the encryption key keepit, and save the output in the file very.secret, the command would be
des -e -k keepit secret very.secret
It is possible to copy files from one UNIX host to another UNIX host connected to the Internet with a single command, provided you have a .rhosts file on the remote machine, or you have secure shell installed on both machines. An explanation of secure shell is beyond the scope of this document.
The .rhosts file in your home directory on the remote machine simply contains a line with your local machine name and your local login name, such as
mach1.uni.edu.au smith
Such a .rhosts file will also allow you to run remote processes such as rcp and rsh on the remotes machine from your local machine.
For example, to copy a file from the machine you are logged into to mach2, enter the command
rcp filename mach2:filename
Note that for machines not connected to the local Ethernet, the complete machine address must be used.
To move files between any two systems on the network, one of which you are currently logged in to, enter the command
ftp mach2.uni.edu.au
You will be asked for your login name on the mach2, and then for your
mach2 password. Once the ftp session is established the prompt will
be ftp> and any of the following list of commands can be used. (Enter
man ftp for more details.) In the following, the mach2 is referred to
as the remote machine, and the machine to which you were originally
logged in is called the local machine.
General / Moving Around Commands
| Command | Description | Usage Example | Notes on Example |
|---|---|---|---|
| bye | terminate the ftp session | bye | |
| quit | synonym for bye | ||
| help | prints information about ftp commands | help pwd | The pwd command is described. |
| help | A list of ftp commands is printed. | ||
| ? | synonym for help | ||
| pwd | print the name of the remote machine's current working directory | pwd | |
| cd | change directory on the remote machine | cd ./sub1/sub2 | |
| lcd | change directory on the local machine | lcd .. | Change to the parent directory on the local machine. |
| mkdir | make a directory on the remote machine | mkdir newrd | A directory called newrd is created under the current working directory on the remote machine. |
| rmdir | remove a directory on the remote machine | rmdir oldrd | The directory oldrd is removed from the remote machine. |
| delete | delete remote file | delete file1 | |
| dir | print a listing of the contents of the remote directory | dir . flnms | Contents of the current remote directory are written to the file flnms on the local machine. If no file name was specified the list would be sent to the terminal. |
| ! | shell escape | Starts up a new shell on the local machine. Useful for creating a new local directory or displaying current files on the local machine. | |
File Moving Related Commands
| Command | Description | Usage Example | Notes on Example |
|---|---|---|---|
| binary | toggle binary mode on/off | binary | Turns binary mode on. Typing binary again would return you to ASCII transfer mode. |
| get | copy a file from the remote machine and store it on the local machine | get remf locf | The file remf from the remote machine is copied to the file locf on the local machine. If a local file name is not specified, the file is given the same name as on the remote machine. |
| recv | synonym for get | ||
| mget | copy a number of files | mget r* | Get all files in the current directory from the remote machine on the remote machine which have names starting with r. These are copied to same named files in the current local directory. |
| put | copy a file from the local machine to the remote machine | put locf remf | The file locf from the local machine is copied to the file remf on the remote machine. |
| send | synonym for put | ||
| mput | copy a number of files from the local machine to the remote machine | mput l* | Put all files in the current directory on the local machine which have names starting with l. These are copied to same named files in the current remote directory. |
| prompt | toggle interactive prompting during multiple file transfers or multiple file deletes | prompt | By default prompting is turned on. The first time this command is entered prompting is turned off and mget or mput will transfer all files, and any mdelete will delete all files. |
| verbose | toggle verbose mode | verbose | verbose mode is on if ftp commands are coming from a terminal. When verbose mode is on all ftp responses are displayed to the user. |
<CTRL>c |
abort a file transfer | <CTRL>c |
Sending transfers are immediately aborted. Receiving transfers may or may not be aborted, depending on whether the remote server supports the ABORT command which is sent to it. |
Maintaining large programs is vastly simplified through the use of the make utility. You create a file called makefile, and in it you set out the ways in which executable and/or object files are dependent on other files such as source code. When the make command is invoked, files which are older than the last modification times of the files on which they depend are rebuilt using either rules specified in the makefile or the system-wide rules for the file type. Note that make will prematurely exit if there is an error in your .cshrc. This is a result of the fact that the commands generated by make are each executed in their own shell, by default using the -ce option which causes an exit upon any errors. A very simple makefile is shown below:
prog.exe: main.f90 sub1.f90
f90 -o prog.exe main.f90 sub1.f90
In this example, prog.exe is the ``target'', and main.f90 and sub1.f90 are the
components on which prog.exe depends. The target is always separated
from its components by a colon ( : ). The rule for creating prog.exe from
its components is given on the second line. This line must start
with a <TAB>. Using the command
make prog.exe
or simply
make
will result in the rule being executed if the current prog.exe file is older than either of main.f90 or sub1.f90.
A slightly more complex but more useful example is shown below:
# Makefile for program prog.exe
FC = f90
FFLAGS = -O
OBJECTS = main.o sub1.o sub2.o sub3.o
# Declare the file Suffixes for default rules
.SUFFIXES .f90
# Default rule to create object files from FORTRAN source
.f90.o: ; f90 -c $(FFLAGS) $<
# Rule for making prog.exe
prog.exe: $(OBJECTS)
$(FC) -o prog.exe $(FFLAGS) $(OBJECTS)
# Delete the object files
delete:
rm -f $(OBJECTS)
Lines beginning with # in this file are comments. Note that
the variables FC, FFLAGS and OBJECTS have been used
in this makefile to make changes to the compiler name, compiler
options or list of object files much simpler: changes are necessary in
only one place rather than right through the file. The executable
file prog.exe depends on the four object files main.o,
sub1.o, sub2.o and sub3.o. If the command make or make prog.exe is entered and any of these
object files is out of date relative to the FORTRAN source file, the
source file will be recompiled using the .f90.o inference rule
in the file. Note that in this rule the symbol $< stands for
the out-of-date FORTRAN file on which the target .o file
depends. Once all of the object files are up-to-date, the executable
prog.exe will be rebuilt using the rule for making prog.exe from the object files.
Entering the command make delete will result in all of the object files being deleted.
If you have a number of programs which have routines in common, you may find it convenient to create a library of the common routines and use this ``archive library'' when linking the programs (as described in the next section). To create a library, the ar command is used. Compile each routine to generate the object files. Then create the archive by using, for example,
ar ruv mylib.a *.o
The object files could then be deleted.
To see which files you have in the archive, the t option can be used:
ar t mylib.a
To delete an object file from the archive, the d option is used:
ar d mylib.a sub99.o
If it is ever necessary to extract a file from the archive, the x option is used:
ar xv mylib.a object-file-name
Libraries are specified at the linking stage after the object or source file names on the f90 command line. For the standard libraries stored in the directories identified by the environment variable LD_LIBRARY_PATH it is sufficient to specify the names in the form -llibrary. This is actually a shorthand way of writing the full name /usr/lib/liblibrary.a. For your own private libraries, it is necessary to specify the full name of the file, as in
f90 -o prog.exe *.o ../mylib/libmyroutines.a
or to tell the compiler where else to look for libraries with the -L option:
f90 -o prog.exe *.o -L../mylib -lmyroutines
Under UNIX, each library specified is used in turn: the first library is searched to satisfy as many external references as possible and then is discarded, with this procedure being repeated for all the other libraries specified. If the third library, say, uses routines which were in the first library, then the first library must be specified again after the third library on the command line.
Programs are executed simply by typing the name of the executable file. If you do not include ``.'' in your path, it may be necessary to enter ./prog.exe instead of just prog.exe
To determine the memory required by an executable program, the size command is used:
size myprog.exe
This will display the size (in bytes) of the text, data and bss sections of the executable file, and the total memory required. Note that the values returned represent the static size, and do not take into account dynamic memory allocated by the Fortran system or by the user's program.
Files can be connected to FORTRAN unit numbers in two ways: through the FORTRAN OPEN statement, as in
open(unit=9,file='input.dat',status='unknown')
or through the use of environment variables, as in
setenv fu09 input.dat
a.out
FORTRAN units 0, 5 and 6 are reserved by default for stderr, stdin and stdout, respectively. (Note that using setenv fu05 input.dat will not work.) Thus, if your program reads from unit 5 and writes to unit 6, it could be run using input and output redirection:
a.out < input.dat > output.log
In interactive work, stderr and stdout are by default printed on the screen, and stdin is the terminal. For batch jobs, redirection should always be used for stdin and stderr. This avoids the embarassment of a job with a huge amount of output filling up the general batch spool area.
This document was generated using the LaTeX2HTML translator Version 99.2beta6 (1.42)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html basic_unix.tex
The translation was initiated by Judy H Jenkinson on 2000-06-19