Some Basic Unix Commands: Appendix C
Some Basic Unix Commands: Appendix C
Appendix C
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 encouraged to explore its features on your own!
C.1.1
The ".profile" file is used to customize the shell environment for ksh.
The following is a typical example of a ".profile" file.
PATH=$PATH:$HOME/bin:$KHOROS_HOME/bin
HOSTNAME=hostname
PS1= $LOGNAME@$HOSTNAME:$PWD>
EDITOR=emacs
#defines alias for commonly used commands
alias ls=ls -al
alias rm=rm -i
#export environment variables to other processes ...
export PATH HOSTNAME PS1 EDITOR TERM
Here, several environment variables such as PATH, HOSTNAME, PS1 etc.
have been defined. The concept of the environment is like a bulletin
board. You can post definitions of any number of variables there. Application programs that expect specific variables can look for them and
use their values, if they are defined. Note that when you set the value of
a variable ( i.e., left hand side of an equal sign), the name is used without
any prefix. When you want to retrieve the value the $ prefix is used. For
example try,
user@machine:dir> echo $PATH
to look at the value of the current path.
C.3
C.4
C.2
Managing files
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 uncompress 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 complete description of each command use the man pages i.e.,
user@machine:dir> man command
C.2.1
The ls command produces a listing of all the files in the current directory. In its most useful form, you will use the -al keywords, i.e.,
user@machine:dir> ls -al dir
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 hidden 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 identify 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 established 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.
drwxr-sr-x
drwxr-sr-x
-rw-r--r-drwx------rw-r--r--rwxr-xr-x
-rw------drwxr-xr-x
-rw-r--r--rw-r----drwxr-xr-x
drwx-----r
w
x
-
Group
File size
sys
sys
others
others
sys
sys
sys
others
sys
others
others
others
1536
1536
1937
512
2504
610
348
512
136
1222
512
512
time stamp
File name
{
{
{
Owner
{
{
permission
control
C.5
27
59
1
2
1
1
1
3
1
1
2
2
kumar
sys
kumar
kumar
kumar
kumar
kumar
kumar
kumar
kumar
kumar
kumar
read permission
write permission
execute permission
no permission
May
May
Jan
Jul
May
May
May
Jul
May
Jan
May
May
24
13
07
21
19
04
14
21
11
19
19
27
23:14
08:52
11:47
1992
12:08
12:36
12:22
1992
14:11
1992
13:12
1992
.
..
.Xdefaults
.elm
.mwmrc
.profile
.rhosts
.tin
.xdt3
Ass1.m
CHEM2
Mail
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 directory Mail has (read,write,execute) permission for owner only
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
ls -al
chmod
chown
rm
rmdir
mkdir
C.2.2
C.6
The chmod command allows you to modify the access control of files and
directories.
Examples
To give read permission to group for file use,
user@machine:dir> chmod g+r file
To give write permission to everyone for all the files in a directory
use,
user@machine:dir> chmod -R a+w dir
Note the the "-R" flag stands for recursive use of the command for
all files in all subdirectories.
Note that, in order to give read permission to a directory, the execute permission at the directory level must be set.
user@machine:dir> chmod a+x dir
C.2.3
Moving files
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
To rename a file, enter:
user@machine:dir> mv oldname newname
This renames file oldname to newname. If a file named newname
already exists, its contents are replaced with those of oldname.
C.7
C.2.4
Copying files
C.2.5
C.8
The chown command changes the owner of the file specified by the File
parameter to the user specified by the Owner parameter. The Owner
parameter can be specified either as a user ID or as a lo- gin name found
in the /etc/passwd file. Optionally, a group can also be specified. The
group can be specified either as a group ID or as a group name found in
the /etc/group file. The syntax is,
user@machine:dir> chown -R owner:group file
Only the root user can change the owner of a file.
C.2.6
The compress command reduces the size of files using adaptive LempelZev coding. Each original file specified by the file parameter is replaced
by a compressed file with a ".Z" appended to its name. The compressed
file retains the same ownership, modes, and access and modification
times of the original file. If compression does not reduce the size of a
file, a message is written to standard error and the original file is not
replaced. The syntax is,
user@machine:dir> compress file
To restore the file to its original state use the command,
user@machine:dir> uncompress file
Also try the GNU version of compress utility called gzip and gunzip they are more efficient in both speed and size.
C.2.7
The rm command removes the entries for the specified file or files from a
directory. If an entry is the last link to a file, the file is then deleted. You
do not need read or write permission for the file you want to remove.
However, you must have write permission for the directory containing
that file.
Examples
To delete a file, enter:
C.9
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 confirmation before deleting the file. It is useful to set an alias in your
".profile" file to redefine "rm" as
alias rm=rm -i
After each file name is displayed, enter "y" to delete the file, or
press the Enter key to keep it.
C.3
Managing processes
C.3.1
The ps command displays a set of currently running tasks. In its simplest and most useful form, the command is,
user@machine:dir> ps -ael
This provides a long listing of all the currently running processes including all of the daemons started by the root at the time of booting the
computer. A typical sample output might look like,
F
200001
240801
260801
260801
222801
40801
S UID
PID PPID
R 21 15101 17095
S 21 17095 16070
S
0 3637 3112
S
0 12169
1
S
0 12938 12169
S
0 10342 8542
C PRI NI ADDR
13 66 20 196d
3 61 20 1dce
0 60 20 b25
0 60 20 8a5
0 60 20 16aa
0 60 20 357a
SZ
116
108
260
152
352
196
WCHAN
TTY
pts/0
pts/0
hft/0
hft/0
-
The process name (or the command name) is shown in the last column. Other useful parameters are the process identification number
(PID), the nice value (NI) which determines the priority of the process,
TIME
0:00
0:00
0:00
0:00
0:05
0:11
CMD
ps
ksh
sendmail
lmgrd
CFDSd
nfsd
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 daemon, 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 number (UID) of 0. Note that the ps command itself is a task.
C.3.2
If you started a process like "emacs" or "matlab" and you want to suspend that task and return to the shell you can do so with the key sequence
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
To resume the job, enter
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.
C.3.3
If you started a process in error and want to terminate it, you can use the
"kill" command. You need to find out the PID number of the process
using "ps command.
user@machine:dir> kill -9 PID
Except for the super user (or root), one can terminate only those processes that belong to (or initiated by) individual users.
C.3.4
C.11
C.3.5
C.12
C.4
A list of less frequently used AIX commands is given in Table C.1. You
can use either the man page feature with
user@machine:dir> man command
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.
command
at
cat
cd
diff
dosformat
dosread
doswrite
find
info
ksh
make
mail
mkdir
man
logout
lpq
lpr
lprm
nice
nohup
pg
ping
pwd
rlogin
rcp
rm
rmdir
rsh
rusers
script
talk
tar
telnet
whoami
xinit
xlc
xlC
xlf
C.13
Function
to schedule a task to start at a given time
to list a file
to change directory
compare two files
formats a floppy diskette using MS-DOS standards
copies a DOS file from a floppy
copies a unix file to a DOS formatted floppy
find a file
InfoExplorer - online documentation
start a Kron Shell
a powerful UNIX make facility
read mail
create a directory
display online manual pages
logout of current AIX session
list the queue of print jobs
send a print job to a network printer
remove a print job from a queue
control job priority
Dont kill a process upon logout
display a file, one page at a time
to check if another machine is alive
display present working directory
remote login to another machine
remote copy files from one host to other
need to have ".rhosts" file setup
remove (delete) files
remove directories
execute a command on a remote machine
need to have ".rhosts" file setup
list remote users in the local area network
logs a terminal session to a file
talk to another user currently signed on
archive files
connect to remote hosts
find out the current user
start X-server
c-compiler
c++ compiler
Fortran compiler