[PDC - Center for Parallel Computers, KTH]
Overview of AIX (IBM's UNIX) for UNIX Novices

Table of Contents


Introduction

This is an introductory tutorial for new Theory Center or AIX users. The following topics are discussed to facilitate use of the system:

Many general topics are discussed in their own tutorials.

If you are interested in working through the examples, or trying the commands, you may wish to print out this tutorial for easy reference. If you can open more than one window on your screen, then leave this tutorial in one window and type the commands in another.


Overview of the Environment and the AIX Operating System

The Theory Center's main production system is an IBM RS/6000 SP running the AIX operating system. AIX is IBM's distribution of AT&T's System V UNIX but includes many BSD (Berkeley Standard Distribution) enhancements. Please note System V and BSD contain a large set of commands in common that in several cases support different options and have different default behaviors; for example: ls, stty, mail, and grep.


Getting Started

Please note, in the following discussion, "%" represents the system prompt, and what follows is what you should type in.

Passwords

When you log onto the system for the first time you will need to change your password. The utility "kpasswd" permits changing from one password to another. (You may be familiar with the standard UNIX command "passwd"; "kpasswd" is the version used by our kerberos security system.) To access, type:

%kpasswd It will then prompt you for your old password, for the new password, and then ask you to reconfirm the password just entered. A password can have any alpha or numeric characters.

Logging Out

To log out of a session, type either

%logout
or
%exit

Commands

Commands are names of executable files or of built-in shell functions. AIX is case sensitive and uses lower case more often than upper case, so be aware of this potential problem. The syntax for a command is:

%command arg1 arg2 arg3

where arguments can include options, option values, command keywords, and filenames. Options generally begin with a dash and immediately follow the command name. Multiple options can be combined, such as:

%ls -al

which is the same as:

%ls -a -l

To control the display of information to your terminal screen, there are a few commands available. If you anticipate more than one screenful of information displayed, and you want to have time to look at it before it zips by, type:

| more

appended to your commands entered, on the same line. "|" connotes a "pipe", and the above will force output to your terminal one screen at a time. Hit the space bar for the next screen.

If you want to display a short file, you can display the file with the cat command.

%cat filename

The above command will scroll through the contents of the file. Use Control-s to stop the display and Control-q to resume display.

If you need to view something at the end of a large file, you can use the tail command.

%tail filename -n

This will display the last n lines of a file, or the last 10 lines if the -n option is omitted.

Startup Files

The .login file gives the operating system specific information about you as a user. Frequently it tells the system terminal characteristics, command search paths, and one-time shell options. A sample .login is below.

    setenv TERM vt100                         (sets terminal type)
    stty erase '^X' kill '^U' intr '^C'       (sets:  erase key
                                                      kill line key
                                                      interrupt key)
    set path = (/usr/ucb /bin /usr/bin /etc /usr/local . ~)
You can also create other "special" function files:
          .cshrc        - executes every time you enter the
                            C shell
          .logout       - executes every time you log out

          .profile      - executes every time you enter the
                            Bourne or Korn shells
In order to view these "invisible" files (so called because these files, prefaced by a ".", are not listed with a plain "ls") in your directory, use the "-a" option as follows:

%ls -a

String Substitution on the Command Line

The alias command performs a string substitution on the command line according to your specifications. This command is convenient for renaming a command or group of commands with a name that is more familiar. You can create an alias with the following format:

%alias entered-command executed-command

e.g.

%alias ll ls -l
(when "ll" is typed, "ls -l" is executed)

To disable an alias created, type:

%unalias ll

It is often useful to place alias commands in the .cshrc file.

Replicating Commands

The history mechanism maintains a list of recently used command lines, also known as events, and provides a shorthand method for re-executing any of the events in the list. It is also handy for checking to see what you had done before if you have the need to retrace your steps. To start history if it had not been started for this session, type:

%set history = 22

You may want to place this command in your .cshrc file.

After some activity has transpired, type:

%history

and the most recent events are displayed, up to 22. To re-execute an event in the list, type:

%!the associated event number

and the command will be executed. To re-execute the latest event, type:

%!!

To execute the last command with a string match, type the following:

%!string
or
!h

You can try the following:

    %set history = 22              (start history)

    %ls *.dat                      (list all data files)

    %history                       (display all events)

    %pwd                           (display current working directory)

    %!!                            (execute last event: pwd)

    %!2                            (execute event #2)

    %!ls                           (execute last event with string "ls")

    %vu moo.dat                    (typo)

    %!!:s/vu/vi/                   (substitute "vi" for "vu" last event)

    %la -ls my*                    (typo)

    %^a^s                          (substitute "s" for "a")

    %!vi                           (execute last event with string "vi")

    %set prompt = '\!%'            (show current prompt number)
    13%                            (what will be displayed to the screen
                                    if you did the above sequence)

Files and Directories

Files

The AIX file system provides a structure where files are arranged in directories, and directories in turn are arranged under other directories in a tree-like organization. Related files can be grouped in directories, of which these "subdirectories" are under the user's primary or root directory.

Files can be accessed by more than one name through the "link" mechanism. Links can be used to make the same file appear in several users' directories, enabling them to share the file easily. More information on this can be found by typing:

%man ln

The file naming convention in AIX is that all file names can contain up to 14 characters in length, including characters like "." All uppercase and lowercase letters are valid characters, including numbers, the underscore, period and comma. Filename extensions are required for the compilers: a C Language program requires a "c" extension and a FORTRAN program requires an "f" extension. Special characters should be avoided in filenames. These are:

     & ; | * ? \ ' " ` { } ( ) < > $  'space' 'tab'
These characters have special significance when the shell scans out of a line before executing the command. The "values" of these characters can be overridden by "quoting" the character, i.e.:
     \*    gives plain *
    '***'  gives plain ***
And remember, in AIX the operating system is case sensitive.

Some file commands are:

     cp - Used to copy the contents of one file to another file.
          Syntax:   %cp original file name new file name
          Example:  %cp file1 file2

     mv - Used to rename a file by moving the contents of the file to
          another file.
          Syntax:   %mv original file name new file name
          Example:  %mv file1 file3

     mv - Used to move a file from one directory to another directory.
          This is a useful command for reorganizing the files in your
          directories.
          Syntax:   %mv file name(s) directory name
          Example:  %mv file3 file4 Cprogs
          The two files, file3 and file4, moved from the current working
          directory to the directory Cprogs.

     rm - Used to delete or remove a file permanently.
          Syntax:   %rm original file name
          Example:  %rm file1
As a precaution, you may use the inquire option (-i) to prompt you before the delete.

%rm -i file1

     cat - Used to display the contents of a file at the shell prompt.
          Syntax:   %cat file name
          Example:  %cat file3

     pg - Used to display the contents of a file with more than one
          screenfull worth of text, one screen at a time.
          Syntax:   %pg file name
          Example:  %pg file3
          To resume display after each screen is displayed, hit the
          RETURN key.

     more - Like pg, used to display a file one page at a time.
          Syntax:   %more file name
          Example:  %more file3
          To resume display after each screen is displayed, hit the
          SPACE BAR.

Directories

While you are logged into the system, you will always be associated with one directory or another. The "working" directory is the directory that you are currently associated with. To access any file in the working directory, you simply use the name of the file. To access a file in another directory, you must use a pathname. To find out the directory you are currently in, type:

%pwd

which stands for "print working directory", and the system will display the pathname of the working directory.

Because AIX has a tree-like structure, a file has both a name and a pathname. The absolute pathname is the file's name prefaced with the directory(ies) describing the "path" from the root directory to the file. An example is: /afs/pdc.kth.se/home/u/username/results/run3. The file "run3" is located in a subdirectory "results" that is subordinate to the user's home directory. If you were in the directory "results", then you could access the file by referring to it as "run3".

A file can also be accessed by a relative pathname. Relative pathnames describe the path from the working directory to the file. The special directory ".." refers to the parent of a directory. For example, if the working directory is /afs/pdc.kth.se/home/s/smith/ then ../../j/jones/run3 refers to the file "run3" in the directory afs/pdc.kth.se/home/j/jones/ .

Your "home" directory is the directory you are in at the time you log in. It will hold your startup files and any subdirectories you create. Whenever you create a directory, "mkdir" automatically places two entries into the directory: "." and ".." "." is the directory itself and is synonymous with the path name of the working directory. ".." is the parent directory and is synonymous with the pathname of the parent of the working directory. These directory entries are only visible if you include an option with the list directory command:

%ls - a

Some directory commands are:

     mkdir - Used to create a directory.
          Syntax:   %mkdir ./directory name
          Example:  %mkdir ./fortprogs

     cd - Used to change current working directory to another directory.
          Syntax:   %cd /directory name
          Example:  %cd /projects/fortprogs
                    %cd ..                 (Moves up one directory level)
                    %cd .                  (Change to current directory)

     rmdir - Used to remove a directory.  The directory must be empty.
          Syntax:   %rmdir ./directory name
          Example:  %rmdir ./fortprogs

     pwd - To display to the screen the current working directory.
          Syntax:   %pwd
          Example:  %pwd

File Protection

Directory protection in AIX is controlled by the AFS file system from Transarc. There is extensive online information available about
AFS.

Once the directory permissions have been set using AFS commands, access to individual files can be granted by setting the access mode to either "private" or "shared". The users who can access a file are grouped into three categories: owner, group and other. And a file can be accessed in three different ways: read, write or execute. If you type:

%ls -l

each file in the current working directory is listed and is preceded with its particular access information. The access information is described in the string of nine characters: the first three positions represent access permission for the owner of the file, the second three position represent access permission for the group, and the last three are for others. Of the three positions, the first position indicates whether read permission is granted (r or -), the second position indicates write permission (w or -) and the third position indicates execute permission (x or -). The "-" denotes "not allowed".

To change access to a file or directory, the owner must use "chmod" (change mode) to affect the desired change.

     Syntax:   %chmod group desired  change  mode  file name

     Example:  %chmod g+rw file2  (grant read/write for group users)
     Example:  %chmod u+x prog1   (grant execute access for owner)
     Example:  %chmod a-w file3   (eliminate write access for all users)
     Example:  %chmod o-x prog2   (eliminate execute access for others)
Remember, if you want to allow someone to copy or read one of your files, you also have to change the access permissions of the file's parent directory to give the person read and execute permission.

Note: A directory cannot be "executed." Instead, the third position indicates permission to search through and list the contents of the directory.

The following are important directories, standard to every account:

     / - The root directory.

     /u - The directory which contains all of the users' home directories.

     /bin and /usr/bin - The directory where standard unix utility programs
          reside.  /bin contains standard utilities and /usr/bin contains
          less common utilities.

     /usr/local - The directory where programs installed by the local
          administrator reside.   Theory Center documents and the Tutor
	  system are located here.

     /dev - The directory where the peripheral device drivers reside.

     /etc - The directory where miscellaneous and administrative files
          reside.

     /tmp - The temporary space that can be used by programs and users.
          Please note that it is not recommended for short term storage.

Utilities

There are many utilities available in AIX, ranging from environment variable changes to processes. A list of popular utilities and a brief description is listed in the appendix section of this tutorial.

Utility programs allow you to work with the system and manipulate the files you create. The following lists the more popular ones.

grep - Used to search through a file to see if it contains a specified
     string of characters.  It displays each line that contains the
     string.
     Syntax:  %grep 'string' file name
     Example: %grep 'subroutine' prog1.f

sort - Used to display the contents of a file in order by lines.  It
     does not change the contents of the file.
     Syntax:  %sort file name
     Example: %sort phonelist

uniq - Used to display a file, skipping adjacent duplicate lines.
     Syntax:  %uniq file name
     Example: %sort phonelist | uniq

diff - Used to compare two files and display a list of the differences
     between them.  This utility does not change the contents of either
     file.  It gives you instructions to add (a), delete (d),
     or change (c) lines in order to convert the first file into the
     second.  Check "man diff" for more information.
     Syntax:  %diff file1 file2
     Example: %diff prog1.jun2 prog2.jun10

Neat AIX Things

Connected to I/O there are several features that are helpful for processing.

Redirection

Redirection describes the various ways you can cause the shell to alter where a command gets its standard input from or where it sends its standard output to. The default standard input and output is the terminal, and this can be "redirected" to a file or another device. An example of output redirected from the terminal and to a file is:

%cat f1 f2 f3 > file4

An example of input coming from a file instead of the terminal is:

%mail alex < memo.alex

which sends the contents of the file memo.alex to Alex using mail; mail is receiving input from the file instead of from the terminal.

Pipes and Filters

Pipes can be used to establish a direct connection from the output of one program to the input of another. A pipe is indicated by a "|" between program names or commands.

Filters are utilities that accept data from stdin (standard input) and write to stdout.

Examples of pipes and filters are:

%cat f1 f2 f3 | sort | uniq
%cat /etc/hosts | grep 'cornell' | pg
%cat /etc/hosts | grep 'r25n01' | wc -l

Some popular filters, that are basically utilities are:

     uniq - mentioned earlier, uniq takes an input stream and outputs
          only one copy of any adjacent lines that are identical.

     grep - searches for a pattern and direct any line containing
          the pattern to standard output.

     sort - sorts the lines of a file by a field.

     pg - displays one screen of information at a time, allowing the user
          to view the data before it scrolls.  Similar to "more".

     wc - returns the number of lines, words and characters in a file.

Processes and Aborting Processes

Everything that you do, whether in foreground or in background, is a process. A process is the execution of a command by the AIX system, where a command can be an AIX utility, running a shell script, or just logging on. Processes can be hierarchical, similar to the file structure, which was explained earlier in the tutorial. A parent process can spawn a child process, if so instructed. If a child process is created, it takes over control while executing the command, and the parent process sleeps. The parent process will wake up again after the child process has completed and died.

When using the c-shell (csh), you may also use job control, which allows you to run a process in the background by ending the command with an &. The child process will run in the background without taking control away from the parent process.

You can look at the current processes running in your present session and their status by typing:

%ps

This will display the unique process identification number (PID), the parent PID (if there is one), and other information. The command man ps explains the utility in detail. If you wish to stop a process, type:

%kill PID

and process PID will be aborted.

You can look at the current jobs running by typing:

%jobs

If you wish to put a program in background after it has started, first type ^z (control z) to suspend the program. If you type "jobs" at this point you will see that the job is listed at "stopped". You may then resume the job in the background by typing:

%bg

To put a process from background to foreground, type:

%fg
%pid

where pid is the job number or name as listed by the "jobs" command.

If you wish to terminate program execution in foreground, press the interrupt key (usually ^c). There is a possibility that your key mappings may be different. If ^c does not work for you, contact your system facility administrator for assistance.


Using Mail

An electronic mail system commonly used in AIX is "mail." To write mailfiles, type:

%mail userid@address

and you will be prompted for the subject. After entering the subject and RETURN, you can then type in your message. Control-D will complete the message and exit you out of the module. You have the option to cc to others after typing your message. If you wish to kill the mail without sending it, enter Control-C twice.

If you wish to read your mail, type:

%mail

and you will see header information on all of the mailfile pending reading. To view mail, enter:

    %t                                 (will display the first mail)
or  %t #id of mail to be read        (will display specified mail)
After viewing the mail file, "d" will delete the mailfile; a RETURN will save the file in your "mbox" file. A "?" entered at the mail prompt will display HELP on the mail module. For additional information, type:

%man mail

We suggest that you use your local system for electronic mail and set up the forwarding mechanism in case any mail is sent to you on this machine.


Help Facilities

There are several information resources available to users. Please note that while there are some differences between UNIX and AIX, the various documentation also reflects subtle differences.

MAN

The "man" (manual) utility displays to the screen pages from the system documentation. It reflects the AIX operating system. To access, type:

%man command name
e.g.
%man awk

and the information will be displayed.

If you are unsure what the command is that you are looking for, enter:

%apropos keyword

which will search for keywords in the title lines of the on-line manual. The command

%man man

will display more information on the "man" utility. To print man pages you can enter:

%man ln > filename

ftp filename to the machine where your local printer is attached, and print with the appropriate print command for your facility.


Web pages

View PDC's online information on the World Wide Web at URL:

    http://www.pdc.kth.se/

Editors - Using vi and GNU-Emacs

The standard editor available on AIX is vi. vi gives you the capability of creating and changing files. Gnu-emacs has also been made available to users who are familiar with it or wish to learn. Gnu-emacs is more command related. There are tutorials on both.


Make

The make utility maintains up-to-date versions of programs, and can be used with Fortran or C programs. Based on rules defined in a "makefile", it will rebuild executables by determining which modules need to be recompiled whenever you make changes to the original source code. See the tutorial and man page for more information.


C Shell and Bourne Shell

The C shell and the Bourne shell are both command interpreters and high-level programming language. As command interpreters, they process commands that are entered in response to its prompt. When they are used as a programming language, they process groups of commands stored in files called shell scripts. A separate tutorial has been written, discussing the C shell.


References and Other Sources

  1. PDC's documentation
  2. "A Practical Guide to the Unix System", Sobell, Mark G., 1989.
  3. "Introducing UNIX System V", Morgan, R. and McGilton, H., 1987.
  4. "The UNIX System", Bourne, S.R., 1983.
  5. "The UNIX Operating System", Christian, K., 1983.

    Appendix

    This list identifies popular utilities and a brief description. Type "man utitlity name" for additional information.

    File characteristic utilities:

         chgrp - change the group that is associated with a file
         chmod - change the access mode of a file
         chown - change ownership of a file
         newgrp - to temporarily change the group identification of a user
    
    File access utilities:
         cat - to join or display files
         cp - copies one or more files
         diff - displays the differences between two files, line by line
         file - classifies files according to their contents
         find - selects files that are located in specified directories
                and are described by an expression
         ln - to make a link to a file
         mv - to move, or rename, one or more files
         rm - to remove a file
         tail - to view the end of a file
         tar - to create, add to, list, and retrieve files from an
               archive file
    
    Directory utilities:
         cd - to change the current working directory
         mkdir - to create a new directory
         rmdir - to remove a directory
    
    Compiler utilities:
         cc - to access the C Language compiler
         xlf - to access the FORTRAN compiler
         make - keeps a set of executable programs current based on
                differences in the modification times of the programs
                and the source files that each is dependent on
    
    Environment utilities:
         kill - to terminate one or more processes
         ps - to display status information about active processes
         mesg - enables or disables reception of messages sent by
                someone using the WRITE utility
         who - to display the names of users currently logged in
         write - to send a message to another user
    
    Filters:
         grep - searches one or more files, line by line, for a pattern
         sort - to sort and/or merge files in sequence
         uniq - to display lines of a file that are unique
         more/pg - allows you to view a text file at a terminal, pausing
                after each screenful
    
    Print utilities:
         lp - to print files
         lpr - to print files
         ls - to display information about one or more files
    
    Other utilities:
         awk, cal, calendar, comm, cpio, date, echo, expr, news,
         nohup, od, pr, sed, sleep, spell, stty, tee, test, touch, tty,
         umask