100% found this document useful (1 vote)
2K views133 pages

AIX Basics

The document discusses the key components and commands of the AIX operating system. It describes the kernel, shell, logging in/out processes, password changing, date/calendar commands, file listing, directory navigation, file manipulation, and communication commands. Key concepts covered include the UNIX system structure, command formats, and the hierarchical file structure.

Uploaded by

rav11stars
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPS, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views133 pages

AIX Basics

The document discusses the key components and commands of the AIX operating system. It describes the kernel, shell, logging in/out processes, password changing, date/calendar commands, file listing, directory navigation, file manipulation, and communication commands. Key concepts covered include the UNIX system structure, command formats, and the hierarchical file structure.

Uploaded by

rav11stars
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPS, PDF, TXT or read online on Scribd
You are on page 1/ 133

• UNIX Structure

Applications
Shell

kernel

H/W

[email protected]
2
• Kernel
– The Kernel interfaces directly with the hardware devices and
controls their access.
– It also controls the processes that are started by users.

• Shell is a command interpreter and acts as an interface


between user and kernel.
– Also the Shell is a programming language.
– We can write Shell scripts to automate tasks.

[email protected]
3
• Logging In

$ login: team01
team01’s Password:
$
• Logging In

$ <ctrl+d> (or)

$exit (or)

$logout

[email protected]
4
• Passwd
– Passwd command is used to change the user password.

$ passwd

Changing password for “team01”


team01’s Old password :
team01’s New password:
Enter the new password again:

$ _

[email protected]
5
• Command Format
– The general format of an AIX command is
– command option (s) argument (s)

$ lsvg –l rootvg

command option argument

[email protected]
6
• Date,Cal commands

$ date
Sat Jan 12 09:11:15 GMT 2008

$ cal 5 2008

May 2008
Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
[email protected]
7
• Clear,echo and banner
– The Clear command clears the terminal window.

$ clear
$
$ echo dinner is at 20:00
$ dinner is at 20:00
$
$ banner hello
$
$

[email protected]
8
• Who, Finger commands
– The Who and Finger commands are used to find information
about the users.

$ who
root lft0 Aug 5 05:45
jim pts/0 Aug 5 07:40

$ who am i
jim pts/0 Aug 5 07:40

$ finger jim
Login name: jim
Directory: /home/jim Shell: /user/bin/ksh
On since Mar 04 13:23:32 on tty3
No Plan.
[email protected]
9
• Sending Mail
$ mail team01  Mail to a user on the same system
Subject: Meeting
There will be a meeting in room 432 at noon.
<ctrl-d>
Cc: <Enter>

$ mail team20@sys32  Mail to a user on a different system


Subject: Meeting
Do not forget about the meeting.
<ctrl-d>
Cc: <Enter>

[email protected]
10
• write
– write provides a conversation like communication with each
user alternatively sending and recieving messages.

$ write jim
<enter>
reboot sys2 at noon <enter> sam’s terminal
o <enter>  o means over

$ write sam
I’ll do that <enter> jim’s terminal
oo <enter>  oo means over and out
<ctrl-d>  to end session

$ write sarah@system23  use write across a N/W

[email protected]
11
• wall
– The wall command writes to all terminals and useful to notify all
users of a system event.

$ wall The server will be down from 23:00 today.


• talk
– The talk command allows two users to hold a conversation.

$ talk fred

(fred recieves this message)


Message from TalkDaemon@sys1 at sys1 at 5:23 ...
talk: connection requested by john@sys1
talk: respond with: talk john

$ talk john (fred accepts invitation)


[email protected]
12
• Files and Directories
– A file is a collection of data.

Usually represent
contains text or code contains a list of files. devices used by the
data system.eg., /dev/cd0

[email protected]
13
• File Structure
– AIX has a Hierarchial File Structure.

[email protected]
14
• File Structure
– AIX has a Hierarchial File Structure.

[email protected]
15
• File Structure
– AIX has a Hierarchial File Structure.

[email protected]
16
• File Structure
– AIX has a Hierarchial File Structure.

[email protected]
17
• pwd command
– The print working directory prints your current directory

$ pwd
/home/team01

[email protected]
18
• list command ls [ directory ]
– The list command is used to list the contents of a directory.

$ ls
bb manuals dec.out
$ ls -a
. .. .profile bb manuals dec.out
$ ls –l
total 3
drwxrwxr-x 2 team01 staff 1024 Jan 15 10:45 abc
-rwxrwxr-x 2 team01 staff 512 Aug 18 15:40 ssa

[email protected]
19
• cd command cd [ directory ]
– The cd command changes our current directory.

$ cd home relative path

$ cd /home/team01 absolute path

$ cd moves to your home directory

$ cd .. moves to the parent directory

[email protected]
20
• mkdir command mkdir [ directory ]
– The mkdir command creates one or more new directories.

$ mkdir /home/team01/test full pathname

$ cd /home/team01 relative pathname

$ mkdir test

$ mkdir –p dir1/dir2/dir3 create multiple dir

[email protected]
21
• rmdir command rmdir [ directory ]
– The rmdir command removes a directory.

$ rmdir /home/team01/aaa

$ cd home

$ rmdir team01
rmdir: team01 not empty

$ rmdir –p dir1/dir2/dir3

[email protected]
22
• rmdir command rmdir [ directory ]
– The rmdir command removes a directory.

$ rmdir /home/team01/aaa

$ cd home

$ rmdir team01 Directory must be empty in order


rmdir: team01 not empty to delete it

[email protected]
23
• display directory info
– The istat command displays the i-node information for a
particular file or dir.
– Every file has an associated i-node number.
– When a file is accessed the filename is matched with the
corresponding i-node number and the data is located.

name i-node # Type mode links User Group Date Size loc
Subdir1 4 4 dir 755 2 jim staff jan 10 512
myfile 10 9:15

10 file 644 1 jim staff jan 10 96


9:15

$ vi myfile

[email protected]
24
$ istat mydir
Inode 51 on device 10/8 Directory
Protection: rwxr-xr-x

owner: 208(team01) Group: 1 (staff)


Link count: 2 Length 512 bytes

Last updated: Mon Jan 17 21:05:43 2000


Last modified: Mon Jan 17 21:05:43 2000
Last accessed: Tue Jan 18 13:25:43 2000

[email protected]
25
• touch command touch filename
– The touch command creates a zero-length file.
– If a file with the name already exists the last modification time
is updated with the current time.

$ touch aa

[email protected]
26
• copy command cp source target cp file1 file2 ... target_dir
– The cp command can be used to copy files and directories.
$ pwd
/home/team01
$ cp /home/team02/aa bb
$ cp –R /home/team01  Recursive copy

[email protected]
27
• move command mv source target
– The mv command can be used to move files and directories
and also rename them.
$ pwd
/home/team01
$ mv test test.out

[email protected]
28
• cat, pg and more commands
– The cat command lists a file but if the file is longer than one
screen space it scrolls down to the end of the file.
– The pg command displays the file one page at a time.
– The more command also works the same way but you can
scroll one line at a time by pressing Enter and one screen at a
time by pressing the space bar.

$ cat aa
this is a file to test the output of cat command.
this file is created using vi editor.

$ pg aa

$ more aa

[email protected]
29
• wc command wc [-c] [-l] [-w] filename
– The wc command counts the number of lines,words and bytes in a
named file.
– This command is very useful when comparing files.

$ wc -lcw abc_file
15 154 996 abc_file

words
Characters

Lines

– If no options are used the order will be lines,words and characters


[email protected]
30
• link command ln source_file target_file
– The ln command allows one file to have more than one name.
– Both copies have the same i-node.

$ pwd
/home/team01

$ ln abc /home/team02/xyz

[email protected]
31
• print command qprt filename1 filename2
– To queue files to the printer we use the qprt command.
– The qchk command displays the current status of a print queue.
– To cancel a print job use the qcan command.

$ qprt ls.out aa.txt


$ qprt –P lp2 mail  to specify a non-default printer

$ qchk
Queue Dev Status Job Files User PP% Blks Cp Rnk
lp0 lp0 Running 99 aa jim 1 1 1 1

$ qcan 23

job number
[email protected]
32
• File protection/permissions

$ ls -l
-rwxr-xr-x 2 team01 staff 1024 jan 12 10:35 test

Permission user user


bits name group
last
modified
file/dir link character time
count count filename

[email protected]
33
• File protection/permissions

$ ls -l
-rwxr-xr-x 2 team01 staff 1024 jan 12 10:35 test

rwx r-x r-x

Permission bits

Others
r ---- read Owner
Owner’s (o)
(u)
w ---- write Group
(g)
x ---- execute
all
(a)
[email protected]
34
• Changing permissions

[email protected]
35
• symbolic notation; chmod mod filename

$ ls -l
-rwxr-xr-x 2 team01 staff 1024 jan 12 10:35 test

r ---- read permission + --- add permission


w ---- write permission - --- remove permission
x ---- execute permission = --- clear permission

u --- owner
g --- owner’s group a --- all
o --- others

$ chmod go-x test


-rwxr--r-- 2 team01 staff 1024 jan 12 10:35 test

[email protected]
36
• octal notation; chmod mod filename U g O
r ---- 4 rwx r-x rw-
w ---- 2
x ---- 1
4+2+1=7 4+2=6
4+1=5
$ ls -l
-rwxr-xrw- 2 team01 staff 1024 jan 12 10:35 test
To change permissions so that group also has write perm., and others do not have
write perm:

$ chmod 774 test


$ ls –l
-rwxrwxr-- 2 team01 staff 1024 jan 12 10:35 test

[email protected]
37
• umask
– umask is an octal number which specifies what permission bits
will be set on a new file or directory when created.
– It has a default value of 022 which is set in /etc/security/user.

$ umask
022

[email protected]
38
• The Vi editor

$ vi tstfile
~
~
~
~
~
~
“tstfile” [New file]

If the file doesn’t exist a new file “tstfile” is created.

[email protected]
39
• The Vi editor

$ vi tstfile
~ ~ represents empty lines
~
~ The editor starts in command mode
~
~
~
“tstfile” [New file]

[email protected]
40
commands
• The Vi editor
$ vi tstfile a -- add text after cursor
~ A -- add text to the end of line
~ i -- insert text at the cursor
~ I -- insert text at the start of line
~
~ To exit TEXT MODE press <Esc>
~
“tstfile” [New file]
k

Cursor Movement 
h l

j
[email protected]
41
• The Vi editor more commands

:q! -- quit without saving


:w -- write changes and stay in editor
:wq
:x -- write changes and quit
<shift-zz>

x -- delete a single character


dw -- delete to the end of current word
d$ -- delete to the end of the line
d0 -- delete to the start of the line
dd -- delete the whole line
:20,40d -- delete a range of lines (20,40 are
line numbers)
u -- undo last change
[email protected]
42
• The Vi editor search for a pattern

/the  search forward for “the”


?the  search backward for “the”
n  continue search in same direction
N  continue search in opposite
direction

Global Replacement
:g/abc/s//xyz/g replaces “abc” with “xyz”
throughout the entire file

yy  copy a line
p  paste the copied line

[email protected]
43
• vi options
– we can change the behaviour of vi by setting some options.
– options are stored in the file $HOME/.exrc
:set all display all settings
:set ai set autoindent on
:set noai set autoindent off
:set nu enable line numbers
:set nonu disable line numbers
:set list displays non-printable characters
:set nolist hide non-printable characters
:set ic ignore case sensitivity
:set noic case sensitive

[email protected]
44
• command-line editing
– To enable the functionality of vi editor in the command line.
– To recall previous commands press <esc-k>,use k,j keys to
scroll through previously entered commands.

$ set –o vi

$ set +o vi  turn off command recall facility

[email protected]
45
• vi EDITORS
– There are various forms of vi.

read-only form beginner’s version subset of vi simple form


of vi of vi working in of ex
line mode

[email protected]
46
• SHELL Basics
– The Shell is the primary interface between the user and the OS.

[email protected]
47
• Metacharacters and Wildcards
– These are characters that the shell interprets as having a special
meaning.
– These should not be used as a part of any filename.
– Wildcards are used to search for and match file patterns.

[email protected]
48
• Examples
$ ls ne?
net new  ? is expanded by the shell to match
$ ls ?e? any single character in a filename.
few new den

$ ls n*
net new no node2.out

$ ls ne[stw]
net new

[email protected]
49
• Standard files and Redirection
– Three files are automatically opened for each process.

– standard input (0)  default is keyboard ---- stdin <

– standard output (1) ---- stdout >


–  default is screen
– standard error (2) ---- stderr 2>

– These defaults can be changed by redirection.


$ ls > ls.out  output redirection

$mail team01 < letter  input redirection

$cat abc 2> errfile  error redirection


[email protected]
50
• Pipes
– A pipe is a sequence of one or more commands where the
stdout of one command becomes the stdin of the next
command.
$ cat abc | wc –l
124
• Filters
– A filter is a command that reads from stdin, processes it and
then writes it to stdout.

$ ls –l | grep “d” | wc –l

Filter
[email protected]
51
• Tee
– The tee command reads stdin and sends the data to both
stdout and a file.

$ ls –l | tee /tmp/ls.out | wc –l

mail.txt tee
ls -l wc -l
err.out
ast.pdf

/tmp/ls.out
[email protected]
52
• command grouping
– Multiple commands can be entered on the same line seperated
by a semi-colon.
$ ls –R > ls.out ; cat aa
• Line continuation
– \ can be used to continue a command on a seperate line.
– A ‘>’ prompt id issued by the shell to indicate line continuation.

$ cat /home/mydir/mails/mail2 \
> /home/jim/imp/data.txt

[email protected]
53
• Shell Variables
– Variables represent data whose value may change.
– Shell variables define your environment...HOME,TERM,PATH etc.,
– Shell variable names are case sensitive.
– The convention is that UPPERCASE are used for system-defined
variables and lowercase are used for user-defined variables.

$ set  displays your current settings

HOME=/home/team01
PATH=/bin:/usr/bin:/etc:/home/team01/bin:
PS1=$
PS2=>
SHELL=/usr/bin/ksh
TERM=ibm3151
$_

[email protected]
54
• Setting and Referencing Shell Variables

$ SHELL=/usr/bin/bash  assign a value to a


shell variable

$ xy=hi friends
$ echo $xy  referencing a variable
hi friends

$ unset xy  delete a variable

$ xy=day
$ echo tomorrow is sun$xy
tomorrow is sunday

[email protected]
55
• Commmand substitution

$ date
Thu 13 Oct 23:43:55 2008
$ now=$(date)
$ echo $now
Thu 13 Oct 23:43:55 2008

[email protected]
56
• Quoting Metacharacters

– ‘ ‘ Single Quotes Ignores all metacharacters


between the quotes.
$ echo ‘$HOME’
$HOME

– “ “ Double Quotes Ignore all metachar., except for


$,` and \
$ echo “$HOME”
/home/team01

– \Backslash Ignore the special meaning of


the following character
$ echo \$HOME
$HOME

[email protected]
57
• Process
– A program or a command that is actually running on a system
is referred to as a process.
– Every process has a Process ID (PID).
– PID 1 is always assigned to the init process which is the first
process that is started during the boot process.
– A PPID is the parent PID.
– The variable $$ shows the PID of the current shell.

PID PPID
$ ls 205 1
$date 206 205
$clear 207 20

$echo $$
4353
[email protected]
58
• The Login Process
– When a user logs into a system a new process is started with a
PID that is randomly allocated by the Kernel.
– The program usr/bin/ksh is loaded into this process.

PID=345 -ksh

Login kernel loads ksh

[email protected]
59
• Variables and Processes
– variables are part of the process environment.Processes
cannot access or change variables from another process.

$ x=4
$ ksh
$echo $x

Subshell
$x=1
$<ctrl-d>
$echo $x
4

– Each program runs in its own process environment.Variable x


is not known in the subshell.
– To pass variables into a subshell we need to execute the
export command.
[email protected]
60
• Exporting variables

$ x=4
$ y=6
$ export y variable is exported to
$echo $x; echo $y subshell
4
6
$ksh
$echo $x

$echo $y Subshell
6
$y=11 variable is not exported
<ctrl-d>
$echo $y
6
[email protected]
61
• Shell Script
– A shell script is a collection of commands stored in a text file.
– Any text editor can be used to create a shell script.
– Here we start ksh and pass the script name as an argument.

$ cat hello
echo “hi friends today is $(date)”
pwd Subshell

$ksh hello  execute script


hi friends today is Mon Aug 12 2008 12:34
/home/team01

[email protected]
62
• Invoking Shell Script
– The shell uses the PATH variable to find executable programs.
– The directory in which the script is stored must be defined in
the path variable.

$ cat hello
echo “hi friends today is $(date)”
pwd

$ chmod +x hello Subshell

$ hello  execute script


hi friends today is Mon Aug 12 2008 12:34
/home/team01

[email protected]
63
• Invoking Shell Script
– Each Shell Script is executed in a subshell.
– Variables defined in a shell script cannot be passed back to the
parent shell.
– If the script is invoked with a .(dot) it runs in the current shell.

$ cat hello
echo “hi friends today is $(date)”
pwd Subshell

$.hello  execute script


hi friends today is Mon Aug 12 2008 12:34
/home/team01

[email protected]
64
• Exit Codes
– A command returns an exit value to the parent process.
– The environment variable $? contains the exit value of last
command.

0 = Success
1-255 = An error has occured

$ cd /etc/security
ksh: /etc/security: permission denied
$ echo $?
1

[email protected]
65
• ps command
– The ps command displays process status information.
$ps -f
UID PID PPID ... TTY ... COMMAND
jim 205 1 ... tty0 ... ls
jim 206 205 ... tty0 ... date

$ps -f  FULL listing

$ps -e  displays info about every


process running in the system

$ps –l  Long listing

$ps –u team05  shows all processes from user


team05
[email protected]
66
• Types of Processes
– Processes that are started from and require interaction with the
terminal are called Foreground processes.
– Processes that can run independently are called Background
processes.
$ps –f > pro.out  background process

[email protected]
67
• Terminating Processes

$kill 202  (Termination signal)


$kill -9 215  (kill signal)

[email protected]
68
• Termination Signals
Signal Meaning

01 hangup signal is sent to a process if its


parent dies

02 Interrupt signal is generated when <ctrl-c>


is pressed

03 Quit signal is generated when the quit key


is pressed <ctrl-\>

09 Kill signal (USE WITH CAUTION)

15 Termination signal (Default)

[email protected]
69
• Running long processes
– The nohup command will prevent a process from being killed if
you log off the system before it completes.
– If you do not redirect output, nohup will redirect output to a file
nohup.out
– nohup tells the process to ignore signals 01 and 03.

$nohup ls –R / > ls.out &


[1] 34
$_

$nohup ls –R /
[1] 34
sending output to nohup.out
$_

[email protected]
70
• Job control

$jobs  List jobs


[1] + Running ls –R / > ls.out

<ctrl-z>  Suspend a foreground job

$fg %1  execute job in foreground

$bg %1  execute job in background

$kill %1  kill a job

[email protected]
71
• Daemons
– A daemon is a never ending process that controls a system
resource (printer queue).
– It starts when the system is started and runs until the system is
down.
– For example qdaemon tracks print job requests and the
printers available to handle them.

[email protected]
72
• User Environment – Login Files
– The first file that the OS uses at login time is the
/etc/environment file which contains variables specifying the
basic environment for all processes.

– The second file is the /etc/profile file which controls system-


wide default variables.

– The third file is the .profile file which resides in a user’s login
login directory and enables the user to customize their working
environment.

[email protected]
73
• User Environment – Login Files

root
can only be changed
/etc/environment by system admin

root
can only be changed
/etc/profile by system admin

User
can be changed by the
$HOME/.profile user

[email protected]
74
• sample /etc/environment

$ cat /etc/environment

# WARNING: This file is only for establishing


# environment variables.Execution of commands from this
# file or any lines specified above may cause failure of
# the initialization process.

PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin
TZ=EST5EDT
LANG=C
LOCPATH=/usr/lib/nls/loc
NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat

[email protected]
75
• sample /etc/profile

$ cat /etc/profile

#System-wide profile.All variables set here may be


#overridden by a user’s personal .profile file in their
#$HOME directory.However all commands here will be
#executed at login regardless.

readonly LOGNAME
umask 022
TMOUT=120
MAIL=/usr/spool/mail/$LOGNAME
MAILMSG=“[YOU HAVE NEW MAIL]”
TERM-ibm3151

export LOGNAME MAIL MAILMSG TERM TMOUT

[email protected]
76
• sample .profile

$ cat .profile

PATH=/bin:/usr/bin:/etc:$HOME/bin:

PS1=‘ $PWD=> ’

if [ -s “$MAIL” ]
then
echo “$MAILMSG”

ENV=“$HOME/.kshrc”  execute this file every time a new


ksh is started

export PATH PS1 ENV

[email protected]
77
• Environment Variables

LOGNAME  It is a read-only variable which contains


your login name.
TMOUT  Time after which the terminal is logged off
by the system.
MAIL  Holds the name of the file where your mail
is sent.

TERM  The terminal type that we are using.

TERM  A list of colon seperated directories that


the shell searches for commands

PS1  Primary system prompt(default is $)

ENV  Pointer to a file containing Korn shell


settings
[email protected]
78
• sample .kshrc
$ cat .kshrc

# set up the command recall facility

set –o vi

# set up aliases
alias l=‘ls -l’
alias p=‘ps -f’
alias up=‘cd ..’

– The difference between .profile and .kshrc is that .kshrc is read each
time a subshell is spawned whereas .profile is read once at login.

[email protected]
79
• ksh features-Aliases
– The alias command invoked with no arguments prints the list of
aliases in the form name=value.
– The unalias command will cancel the alias named and removes it
from the alias list.
$ alias p=‘ps -ef’
$ alias l=‘ls -l’

$ alias
history=‘fc -l’
l=‘ls -l’
p=‘ps -ef’
r=‘fc –e-’

$unalias l

$ l
ksh: l: not found
[email protected]
80
• ksh features-History
– The last 128 commands are stored in $HOME/.sh_history.
– The r command allows you to recall previously entered commands.

$ fc –l  lists the last 16 commands


2 cd /home/list
3 ls –l
4 fc –l
5 mail

$ r m
No mail for team01

$ r 3
-rw-r-—r– john staff 345 aug 23 12:35 fileout

[email protected]
81
• AIX Utilities

• find command (find path expression)


– Searches one or more dir structures recursively for files
meeting certain specified criteria and displays those filenames
or executes commands against them.

$find . –name sum -print


./color/sum
./shape/sum

[email protected]
82
• Executing commands with find
– The exec command executes a command on each of the files
found.

$find . –name ‘m*’ –exec ls –l {} \;


-rw-r-—r– john staff 45 aug 23 11:35 fileout
-rw-r-xr– john staff 465 aug 23 23:11 df.out
-rwxrw—r– john staff 12 aug 23 03:12 aa

– The command following –exec (ls) is executed for each file


name found.
– \; is hard coded with the find command and is required for use
with –exec and –ok.

[email protected]
83
• Interactive command execution
– The ok option causes command execution on an interactive
basis.

$find . –name m\* –ok rm {} \;


<rm ... ./shape/misc>? y
<rm ... ./shape/medium>? y
<rm ... ./misc>? n

[email protected]
84
• Additional Options
-type f  ordinary file
d  directory

-size +n  larger than n blocks


-n  smaller than n blocks
n  equal to n blocks

-mtime +x  modified more than x days ago


-x  modified less than x days ago

-perm onum  access permissions match “onum”


mode  access permissions match “mode” values

-user user  find files owned by user


-o  logical “or”

[email protected]
85
• find examples
$find . –name ‘s*’ –type f –size +2 –exec ls –l {} \;
-rw-r-—r– john staff 3545 aug 23 11:35 sum.out
-rwxr-—r– john staff 4543 aug 11 23:12 ss.out

$find . –perm 644 –mtime +4 –print


./impfiles/misc

$find . –name imp –o –name misc


./files/misc
./imp

$find / –name ‘security’–print 2> err.out


/var/security
/usr/lib/security

[email protected]
86
• find with the –links option
$ find /home –type f –links +1 | xargs ls –li

127 –rw-r--r– 3 team01 staff 156 oct 29 12:15 /home/file1


127 –rw-r--r– 3 team01 staff 156 oct 29 12:15 /home/filecopy1
127 –rw-r--r– 3 team01 staff 156 oct 29 12:15 /home/filecopy2

same i-node same no. of bytes


no. of links

• The –links +1 option lists the files that have more than one
link associated with them.

[email protected]
87
• grep command (grep [options] pattern [file1 file2....])
– Searches for lines matching specified pattern and also displays
the name of the file containing the pattern.

$grep 800 phone1


Hotline HW 800 322-4500

$ps –ef | grep team01


team01 10514 13254 0 09:54:55 pts/1 0:00 -ksh

[email protected]
88
• grep with regular expressions
– When * is used with the grep command ti will match zero or
more occurences of the previous character.
Valid metacharacters

.  any single character

*  zero or more occurences of the


preceeding character
[aA]  Enumeration: a or A

[a-f]  any one of the char between a to f

^a  Any lines that start with a

z$  Any lines that end with a z


[email protected]
89
• grep examples
$ps –ef | grep team01
team01 10514 13254 0 09:54:55 pts/1 0:00 -ksh

$grep ‘^B’ phone1


^ - start
Baker jim 454-3414

$grep ‘5$’ phone1 $ - end


Avis Betty 125-4625

$grep ‘^[DH]’ phone1


Dade travel sam 434-5643 [DH] - enumeration
Hotline HL 322-4500

[email protected]
90
• grep options

-v  print lines that do not match

-c  print only a count of matching lines


-l  print only the names of the files with
matching lines

-n  number the matching lines

-i  ignore case senitivity

-w  do a whole word search

[email protected]
91
• Other greps
• fgrep  fast grep  only fixed strings;no expressions
$fgrep ‘HW’ phone1
Hotline HW 800 322-3455  slightly faster

• egrep  Extended grep  allows multiple patterns

$egrep ‘800|817’ phone1  slightly slower


Hotline HW 800 322-3455
sam jim 817 322-3434

[email protected]
92
• sort command
– The sort command sorts lins and writes the result to standard
output.
$ cat animals
dog.2
cat.4
rabbit.7
$ sort animals default sort order
cat.4
dog.2
rabbit.7
$ cat animals | sort +0.1 sort by second char.,
rabbit.7
cat.4
dog.2

[email protected]
93
• head and tail commands
– head command can be used to view the first few lines of a file
or files.
– tail command displays a file beginning at a specified point and
displaying a specified number of lines.

$head -5 ls.out  read first 5 lines

$tail -20 myfile


$tail –f /tmp/err.out  displays lines as
they are added to the file

[email protected]
94
• xargs
– The xargs command reads a group of commands from stdin
and runs an AIX command with that group of arguments.
– Here cat passes xargs the list of files and allows xargs to pass
them to rm.
– The –t flag echoes the constructed command line to stderr.

$cat oldfiles
file1
file2
file3
file4

$cat oldfiles | xargs –t rm


rm file1 file2 file3 file4

[email protected]
95
• xargs more examples
– Here we create a list of files to be printed and queue them up for
printing through xargs.

$ls > printlist


$xargs –t qprt < printlist
qprt file1 file2 file3

$ls | xargs –t –I {} mv {} {}.old


mv mail mail.old

– Here { } is called a placeholder and the –I flag tells xargs to insert


each line of the ls directory listing where { } appears.

[email protected]
96
• xargs,find and grep
– Using xargs is more efficient and easier to remember than the
find commanad

$ find . –type f –mtime +30 | xargs –t rm


rm ./file1 ./file2 ./file3

$ find . –type f | xargs –t grep –l Hello


grep –l Hello ./file4 ./file7 ./file10

[email protected]
97
• which,whereis,whence
– which command takes a list of program names and looks for
the files that are executed when these names are given as a
command.
– whereis also takes a list of program names but only searches
in some standard locations.
– Whence is a ksh-specific command which also searches for
ksh aliases.
$ which find
/usr/bin/find

$ whereis find
/usr/bin/find

$ whence find
/usr/bin/find

[email protected]
98
• file command
– The file command can be used to determine the type of a file.
– It also tells us under what OS version it is compiled.
$file /usr/bin/vi
/usr/bin/vi:executable (RISC System/6000) or object module

$file cl
cl: ascii file

$file /usr/bin
/usr/bin: directory

[email protected]
99
• diff (Differential File Comparator)
– The diff command works only with text files and and reports the
differences between the two files.

>
$ diff names names.old names names.old

1c1 Carol caroline


Bob jim

<
< Carol
Jim Mary
---- Don Sam
>Caroline Mary
4d3
< Don
5a5 a  indicates lines that should be appended to first file to
> Sam obtain the second file
d  indicates lines that are missing from second file.
c  indicates lines that are changed between the first
file and second file.

[email protected]
100
• cmp (compare)
– The compare command works with all types of files and it
reads two files until it finds any differences and reports them.

$ cmp names names.old


names names.old differ: byte 6,line1

$ cmp –l names names.old


6 12 151
7 102 154
....
....
cmp:EOF on names

– Here the first column is the byte number and the second and
third columns are the octal values of the bytes from first file and
second file respectively that differ.

[email protected]
101
• Telnet
– The tn command allows to login to remote systems.
$tn miami
Trying ...
connected to miami
...

AIX Version 5
(C) Copyright by IBM and others 1982,1996
login: team01

[email protected]
102
• FTP
– The ftp command allows us to transfer files in a network.
$ftp miami
connected to miami
220 FTP server ready
Name (miami: team01): team05
Password rewquired for team05.
Password:
230 User team05 logged in.
ftp>

ftp prompt

[email protected]
103
• FTP subcommands
– The most important ftp subcommands are:
ftp> pwd

ftp> cd remotedir

ftp> dir (or) ls -l

ftp> get remotefile [localfile] get file1 /tmp/file1

ftp> put localfile [remotefile] put /im/ls.out ls.out

ftp> help [subcommand]

ftp> quit

[email protected]
104
• tar: Backup and Restore files
– tar(tape archiver) saves files recursively and stores them as
one archive file.
tape
tar –cvf /dev/rmt0 . tar –xvf /dev/rmt0

floppy
tar –cvf /dev/fd0 . tar –xvf /dev/fd0

disk
tar –cvf /tmp/file1.tar . tar –xvf /tmp/file1.tar

[email protected]
105
• tar: more options
– If the .(dot) is specified then the files are saved relatively which
allows you to restore the files in a new directory.

The tar options are

-c create
-t table of contents
-v verbose
-f filename
-r extend archive
-x extract

To show the contents of archive file


tar –tvf /dev/rmt0

[email protected]
106
• compress,uncompress,zcat
– The compress command compresses a file and replaces the original
file with a .z appended to it.
$ ls –l file1
127 –rw-r--r– 3 team01 staff 13354 oct 29 12:15 /home/file1

$ compress –v filel
file1: compression 56.99% file1 is replaced with file1.z

$ ls –l file1
127 –rw-r--r– 3 team01 staff 5756 oct 29 12:15 /home/file1

$ zcat file1.z  view a compressed file

$ uncompress filel.z

$ ls –l file1
127 –rw-r--r– 3 team01 staff 13354 oct 29 12:15 /home/file1
[email protected]
107
• Additional Shell Features---Important Shell Variables
– These variables are set by the shell or a shell script.
$$  PID

$0  name of currently executing shellscript

$#  no., of arguments passed to shellscript

$*  All command-line arguments passed to script

$?  Exit value of last command

$!  PID of last background process

[email protected]
108
• Positional Parameters
– Parameters can be passed to shell scripts as arguments on the
command line

$ cat ascript
echo first parameter is $1
echo second parameter is $2
echo third parameter is $3

$ ascript good morning friends


first parameter is good
second parameter is morning
third parameter is friends

[email protected]
109
• expr Utility
– The expr utility can be used to perform integer arithmetic.
– \*  multiplication high
–/  integer divison
–%  remainder precedence order
–+  addition
–-  subtraction low
$ x=6
$ y=3
$ expr $x/$y
2
$ expr $x-$y
3
$ expr \($x+$y)\*4  \(\) to group expressions
36

[email protected]
110
• conditional execution
– The exit value from a command or a group of commands can be
used to determine whether to do the next command.

command1 && command2


if command1 is succesful then do command2

$ ls s* && rm s*

command1 || command2
if command1 is not succesful then do command2

$ cd /dir1 || echo cannot change to dir1

[email protected]
111
• test command
– The test command allows you to test for a given condition.

test expression or [ expression ] or [[ expression ]]


The test command evaluates the expression and returns true or false.
Operator Returns true if
$string1 = $string2 strings are equal
$string1 != $string2 strings are not equal

$number1 -eq $number2 numbres are equal


$number1 -ne $number2 numbers are not equal

-a $file file exists

-d $file file is a directory


-r $file file is readable
-w $file file is writeable
[email protected]
112
• if command
if condition is true
then
carry out this set of actions
else
carry out these alternative actions optional
fi

• The exit statement is used to terminate a process.

[email protected]
113
• if command (example)

$ cat active
usage=“$0: userid”

if [[ $# -ne 1 ]]
then
echo “proper usage: $USAGE”
exit 1
fi

if who | grep $1 > /dev/null


then
echo “$1 is active”
else
echo “$1 is not active”
fi

exit0

[email protected]
114
• read command
– The read command reads one line from stdin and assigns the values
of each field to a shell variable.
$ cat delfile

# usage: delfile
echo “please enter the filename:”
read name
if [[ -f $name ]]
then
rm $name
else
echo “error: $name is not an ordinary file”
fi

– The read command can be used to assign more than one variable.
– Here if delfile is invoked with more than one filename then then first
variable is assigned first filename and so on...
[email protected]
115
• for loop

for variable in list


do
commands
done

$ cat count $ cat rm_tmp


for var in ls.out err.out for file in /tmp/*
do do
wc –l $var echo “removing $file”
done rm $file
done
$ count
12 ls.out
34 err.out

[email protected]
116
• While loop

while expression
do
commands
done

$ cat info
x=1
while [[ $x –lt 9 ]]
do
echo “it is now $(date)”
echo “there are $(ps –e | wc -l) processes running”
echo “there are $(who | wc -l) users logged in”
x=$(expr $x + 1)
sleep 600
done

[email protected]
117
• command search order
• The shell looks for a in the following order.

[email protected]
118
• X Window
– The X-window is a N/W based graphics system.
– It enables us to work with multiple items simultaneously.

– It provides the capability to manage local and remote displays.


– X window uses a client/server environment.

– So the graphic application can run on one system, yet display its
output on another system.
– X window is platform independent.

– It allows a keyboard and display attached to one system to use


programs running on a completely different system.

[email protected]
119
• X Window
– The X-window is a N/W based graphics system.

X-station RISC workstation RS/6000 Workstation

Intel PC
RS/6000 Workstation RS/6000 server
[email protected]
120
• X Window
– X window function is split into terminal and application support.
– Typically the application support runs on a UNIX system and the
terminal system can run on any system.

– The system providing application support is called client and the one
providing terminal support is called server.
– In most cases both will be on the same system.

– Client is the application that is running and needs to display graphics


to a user.
– Clients recieve keyboard and mouse input from the associated
x server.

– X servers respond to requests from clients and to actions from users.

[email protected]
121
• X Clients
– X clients are the aplications which the users run under the X window
system:common X clients are

xterm  Standard terminal emulator

aixterm  IBM AIX terminal emulator

xclock  displays a clock

xcalc  displays a calculator

xwd  dumps the image of an x window

mwm  motif window manager

[email protected]
122
• X Clients
– standard X client command line options are:

-bg color  specifies the color for window background

-bd color  specifies the color for window border

-bw number  specifies window border in pixels

-display Name:Number  Identifies the host server name and the X


server display number where the command is
to run.

-fg color  specifies the color for the window foreground

-fn number  specifies the normal sized text fontset.

[email protected]
123
• X Server
– Each X server controls one keyboard. one mouse and one or more
screens.

– Allows simultaneous access by several clients

– Performs basic graphic operations

– Provides information such as fonts and colors

– Routes keyboard and mouse I/P to the correct clients

[email protected]
124
• Starting AIXwindow
– The startx command is used to start the AIXwindows environment.

– If the workstation is not an X Station then startx will execute the xinit
command.

– By default startx starts three clients aixterm,xclock and mwm.

– Any errors occuring during will be logged in a file $HOME/.xerrors.

– We use <ctrl><alt><backspace> to close AIXwindows and return to


command prompt.

– Some windows like aixterm accept and display information while


some like xclock and xcalc simply display information.

[email protected]
125
• The aixterm Window
– An aixterm can be started in two ways:
– In SHELL  aixterm
– Display Root menu and select New Window

– To create an additional aixterm window enter aixterm & at the


command prompt.

– The aixterm window can be closed by


– Type exit or <ctrl>+d

[email protected]
126
• Running a Client on Another System
– With AIXwindows it is possible to run a client on a remote system in
the network yet display the application window on your screen.

– we need to tell the client process where to display its window.

– AIXwindows uses the DISPLAY environment variable to indicate the


name of the server where it should display its output.

– To override this value we need to specify a value using the –display


flag when starting the client.

– The value is generally :0.0 for local severs or sys1:0:0 for a remote
server.

[email protected]
127
• Running a Client on Another System
– Here sys2 runs the client application(aixterm) while sys1 needs to
display the output.

sys2
sys1

$ rexec sys2 aixterm –display sys1:0

remote xclient application xserver


execute
comand
[email protected]
128
• xhost command
– The xhost command adds and deletes hosts on the list of machines
from which the xserver accepts connections.
– The X server allows connections only from X clients running on the
same machine or clients listed in /etc/X0.hosts.
– The X host command must be executed on the machine to which the
display is attached.

$ xhost  displays names of hosts allowed access to


Xserver

$ xhost + hostname  add a hostname

$ xhost – hostname  remove a hostname

[email protected]
129
• AIXwindows Startup
– The xhost command adds and deletes hosts on the list of machines
from which the xserver accepts connections.
– After a customizable script .xinitrc will execute.It starts a user’s
clients and then starts mwm.
– mwm starts Motif and tailors it according to files .Xdefaults
and .mwmrc.
– Xdefaults file contains a user’s personal preferences like
colors,fonts etc., and can be found in the user’s $HOME dir.
– mwmrc is used to customize things like Root menu etc.,

[email protected]
130
• Customizing AIXwindows --- .xinitrc
– The startx first searches for a file specified by the user’s XINITRC
environment variable.

– If it is not set (not set by default) then it searches the user’s HOME
dir for a file called .Xinit,.xinit,.Xinitrc,.xinitrc or .xsession respectively
to begin X client programs.

– If these files are not found then it uses the system-wide


/usr/lpp/X11/defaults/xinitrc.

– If a user wishes to customize their own AIXwindows startup env.,


they should copy the system-wide file into their HOME dir and
modify it.

– The file /usr/lib/X11/rgb.txt contains a list of valid colors which we


can use while customizing AIXwindows files.
[email protected]
131
• Customizing AIXwindows --- .Xdefaults
– Fonts are stored in /usr/lib/X11/fonts and can be listed using
$ custom -e font.
– Most of the customization is done through the use of resources.
– For example the bgcolor of aixterm,preferred focus policy are all
resources.
– Most of these resources are set in a user’s .Xdefaults file and they
look like object*attribute: value.

$ vi $HOME/.Xdefaults
Aixterm*background: grey
Aixterm*foreground: navy
Aixterm*font: rom10
xclock*update: 1
Mwm*keyboardFocusPolicy: explicit

[email protected]
132
• Customizing AIXwindows --- .mwmrc
– Root menu,window menu and mouse options can be customized in
the .mwmrc file.
– DO NOT MODIFY SYSTEM-WIDE FILE which can be found in
/usr/lpp/X11/defaults/Motif1.2/system.mwmrc.
– To customize we need to copy this file to our HOME dir and modify it
as it will override the system-wide version.

[email protected]
133

You might also like