App C PDF
App C PDF
— IZAAK WALTON
So is UNIX.
— K. Nandakumar
Appendix C
user@machine:dir> chsh
This command will display your current shell, and prompt you for the
C.1
C.1. INTRODUCTION TO THE SHELL AND THE DESKTOP C.2
name of the new shell. The change takes effect when you login the next
time. At any time you can invoke a new shell, different from the login
shell, e.g.,
user@machine:dir> csh
invokes a C-shell.
You can invoke a desktop at any time on AIX machines by entering
user@machine:dir> xdt3
Since the use of desktop is supposed to be rather intuitive, you are en-
couraged to explore its features on your own!
PATH=$PATH:$HOME/bin:$KHOROS_HOME/bin
HOSTNAME=‘hostname‘
PS1=’ $LOGNAME@$HOSTNAME:$PWD>’
EDITOR=emacs
user@machine:dir> alias
By default, the "rm" command removes files without prompting you for
confirmation which could result in accidental deletion of files. The alias
defined above, assigns ’rm -i’ to "rm". The keyword "-i" stands for inter-
active mode and hence you will always be prompted before removing a
file.
The variables defined in a shell environment are available only to that
shell environment and not to other shells that you may start from the
current one. The export command is used to export the variables to all
subsequent shells. The last line in the above example exports several
environment variables.
To look at all of the environment variables defined in the current ksh
shell, enter,
user@machine:dir> set
user@machine:dir> DUMMY=junk
C.2. MANAGING FILES C.4
In managing your files and directories, you need to be able to list the
contents of a directory or file, copy and move files, compress and uncom-
press files, create and delete files and directories, control the ownership
and access to files etc. Commands to carryout these tasks are illustrated
below with specific examples. Try them out at a terminal. To get a com-
plete description of each command use the man pages i.e.,
user@machine:dir> man command
The ls command produces a listing of all the files in the current direc-
tory. In its most useful form, you will use the “-al” keywords, i.e.,
Typically, files that begin with the “.” ( e.g., .profile) are treated as hidden
files. They keyword “-a” however lists all of the files including the hid-
den ones. The keyword “-l” produces the long listing, a sample of which
is shown in figure C.1. This listing provides information on file access
control, ownership, size, time stamp etc. Each line contains information
for a file or directory. The first character identifies whether it is a file (-),
a directory (d) or a symbolic link (l). A symbolic link is a pointer to some
other file (think of it as an alias). The next set of nine characters iden-
tify the file access control, in groups of three. Since AIX is a multiuser
environment, users can control ownership and access of their files to
others. The possible access modes are: read (r), write (w) execute (x) or
none(-). These modes apply to (user, group, others). The groups are es-
tablished by the system administrator. The owner and group names are
listed next, followed by file size in bytes, the time stamp for last change
and the file name.
C.2. MANAGING FILES C.5
permission
time stamp File name
{
{
control Owner Group File size
{
{
{
{
drwxr-sr-x 27 kumar sys 1536 May 24 23:14 .
drwxr-sr-x 59 sys sys 1536 May 13 08:52 ..
-rw-r--r-- 1 kumar others 1937 Jan 07 11:47 .Xdefaults
drwx------ 2 kumar others 512 Jul 21 1992 .elm
-rw-r--r-- 1 kumar sys 2504 May 19 12:08 .mwmrc
-rwxr-xr-x 1 kumar sys 610 May 04 12:36 .profile
-rw------- 1 kumar sys 348 May 14 12:22 .rhosts
drwxr-xr-x 3 kumar others 512 Jul 21 1992 .tin
-rw-r--r-- 1 kumar sys 136 May 11 14:11 .xdt3
-rw-r----- 1 kumar others 1222 Jan 19 1992 Ass1.m
drwxr-xr-x 2 kumar others 512 May 19 13:12 CHEM2
drwx------ 2 kumar others 512 May 27 1992 Mail
{
r read permission
w write permission 1st set applies to owner
x execute permission 2nd set applies to group
- no permission 3rd set applies to all
d indicates a directory
l indicates a symbolic link
Examples:
The file .profile has (read,write,execute) permission for owner (kumar in this case) and
(read,execute) permission for both the group (sys in this case) and everyone.
The command
chmod g+r file
will give read access to group for file, while
chmod o-w file
takes away write access to all for file
Other related Unix commands
ls -al - detailed listing of directory such as the above
chmod - change permission on files and directories
chown - change ownership of files and directories
rm - remove or delete a file
rmdir - remove or delete a directory
mkdir - create a new directory
The chmod command allows you to modify the access control of files and
directories.
Examples
Note the the "-R" flag stands for recursive use of the command for
all files in all subdirectories.
The mv (move) command moves files and directories from one directory
to another, or renames a file or directory. You cannot move a file onto
itself.
Warning: The mv command can overwrite many existing files unless you
specify the -i flag. The -i flag prompts you to confirm before it overwrites
a file.
Examples
This moves all files and directories under olddir to the directory
named newdir, if newdir exists. Otherwise, the directory olddir is
renamed to newdir.
Examples
If file.new does not already exist, then the cp command creates it.
If it does exist, then the cp command replaces it with a copy of the
file.old file.
Also try the GNU version of compress utility called gzip and gunzip -
they are more efficient in both speed and size.
Examples
user@machine:dir> rm myfile
If there is another link to this file, then the file remains under that
name, but the name myfile is removed. If myfile is the only link,
the file itself is deleted. Caution: You are not asked for confir-
mation before deleting the file. It is useful to set an alias in your
".profile" file to redefine "rm" as
After each file name is displayed, enter "y" to delete the file, or
press the Enter key to keep it.
user@machine:dir> ps -ael
This provides a long listing of all the currently running processes in-
cluding all of the daemons started by the root at the time of booting the
computer. A typical sample output might look like,
The process name (or the command name) is shown in the last col-
umn. Other useful parameters are the process identification number
(PID), the nice value (NI) which determines the priority of the process,
C.3. MANAGING PROCESSES C.10
and the cpu time (TIME) used up by the task. In the above example
listing, sendmail is the mail program, lmgrd is the license manager dae-
mon, CFDSd is the license server for FLOW3D program, nfsd is the NFS
daemon; all of these tasks are run by root with a user identification num-
ber (UID) of 0. Note that the ps command itself is a task.
user@machine:dir> ctrl-z
The PID number is displayed at that time. Even if you did not note it
down, you can find a list of all suspended jobs with the command
user@machine:dir> jobs
user@machine:dir> fg %n
where n is the job number produced by the jobs command (and not the
PID number!). The "fg" command brings a job to the foreground.
Except for the super user (or root), one can terminate only those pro-
cesses that belong to (or initiated by) individual users.
When used in its simplest form as above, any output that would normally
appear on the screen will be saved in a file named nohup.out in the
current directory. Wait before logging off because the nohup command
takes a moment to start the command or script you specified. If you
log off too quickly, your command or script may not run at all. Once
your command or script starts, logging off does not affect it. Note that
in order to run a script, the script file must have execute permission.
In the above script we start MATLAB in the first line and redirect any
output generated by MATLAB for the standard output ( i.e., screen during
an interactive session) to a file named out. During an interactive session,
MATLAB expects commands from the standard input ( i.e., the keyboard).
Such inputs are now taken from the script file itself as seen in the next
few lines where we execute some MATLAB functions and finally quit
MATLAB.
The contents of such a script file can be executed interactively while
logged in to a machine by simply entering the file name as
user@machine:dir> test.bat
user@machine:dir> pg /usr/local/matlab/bin/matlab
C.4. LIST OF OTHER USEFUL AIX COMMAND C.12
which will begin executing the script file at 21:00 hours. To examine a
listing of all the jobs scheduled use,
user@machine:dir> at -l
To remove a job that you have accidentally submitted, you can use,
A list of less frequently used AIX commands is given in Table C.1. You
can use either the man page feature with
or the
user@machine:dir> info
command which starts the InfoExplorer to find out about the syntax and
usage of these and other commands. The directory /usr/bin contains
all of the Unix commands.
C.4. LIST OF OTHER USEFUL AIX COMMAND C.13
command Function
at to schedule a task to start at a given time
cat to list a file
cd to change directory
diff compare two files
dosformat formats a floppy diskette using MS-DOS standards
dosread copies a DOS file from a floppy
doswrite copies a unix file to a DOS formatted floppy
find find a file
info InfoExplorer - online documentation
ksh start a Kron Shell
make a powerful UNIX make facility
mail read mail
mkdir create a directory
man display online manual pages
logout logout of current AIX session
lpq list the queue of print jobs
lpr send a print job to a network printer
lprm remove a print job from a queue
nice control job priority
nohup Don’t kill a process upon logout
pg display a file, one page at a time
ping to check if another machine is alive
pwd display present working directory
rlogin remote login to another machine
rcp remote copy files from one host to other
need to have ".rhosts" file setup
rm remove (delete) files
rmdir remove directories
rsh execute a command on a remote machine
need to have ".rhosts" file setup
rusers list remote users in the local area network
script logs a terminal session to a file
talk talk to another user currently signed on
tar archive files
telnet connect to remote hosts
whoami find out the current user
xinit start X-server
xlc c-compiler
xlC c++ compiler
xlf Fortran compiler