aix basics


Click here to load reader

Upload: rav11stars

Post on 21-Nov-2014




72 download


unix basics


Page 1: AIX Basics
Page 2: AIX Basics

[email protected]

• UNIX Structure





Page 3: AIX Basics

[email protected]

• 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.

Page 4: AIX Basics

[email protected]

• Logging In

$ login: team01team01’s Password:$

• Logging In

$ <ctrl+d> (or)

$exit (or)


Page 5: AIX Basics

[email protected]

• 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:

$ _

Page 6: AIX Basics

[email protected]

• Command Format– The general format of an AIX command is– command option (s) argument (s)

$ lsvg –l rootvg

command option argument

Page 7: AIX Basics

[email protected]

• Date,Cal commands

$ dateSat Jan 12 09:11:15 GMT 2008

$ cal 5 2008

May 2008Sun Mon Tue Wed Thu Fri Sat

1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 1718 19 20 21 22 23 2425 26 27 28 29 30 31

Page 8: AIX Basics

[email protected]

• 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$$

Page 9: AIX Basics

[email protected]

• Who, Finger commands– The Who and Finger commands are used to find information

about the users.

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

$ who am ijim pts/0 Aug 5 07:40

$ finger jimLogin name: jimDirectory: /home/jim Shell: /user/bin/kshOn since Mar 04 13:23:32 on tty3No Plan.

Page 10: AIX Basics

[email protected]

• Sending Mail

$ mail team01 Mail to a user on the same systemSubject: MeetingThere will be a meeting in room 432 at noon.<ctrl-d>Cc: <Enter>

$ mail team20@sys32 Mail to a user on a different systemSubject: MeetingDo not forget about the meeting.<ctrl-d>Cc: <Enter>

Page 11: AIX Basics

[email protected]

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

$ write samI’ll do that <enter> jim’s terminaloo <enter> oo means over and out<ctrl-d> to end session

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

• write– write provides a conversation like communication with each

user alternatively sending and recieving messages.

Page 12: AIX Basics

[email protected]

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

• wall– The wall command writes to all terminals and useful to notify all

users of a system event.

• 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 connection requested by john@sys1talk: respond with: talk john

$ talk john (fred accepts invitation)

Page 13: AIX Basics

[email protected]

• Files and Directories– A file is a collection of data.

contains text or code data

contains a list of files.Usually represent devices used by the, /dev/cd0

Page 14: AIX Basics

[email protected]

• File Structure– AIX has a Hierarchial File Structure.

Page 15: AIX Basics

[email protected]

• File Structure– AIX has a Hierarchial File Structure.

Page 16: AIX Basics

[email protected]

• File Structure– AIX has a Hierarchial File Structure.

Page 17: AIX Basics

[email protected]

• File Structure– AIX has a Hierarchial File Structure.

Page 18: AIX Basics

[email protected]

• pwd command– The print working directory prints your current directory

$ pwd/home/team01

Page 19: AIX Basics

[email protected]

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

$ lsbb manuals dec.out$ ls -a. .. .profile bb manuals dec.out

$ ls –ltotal 3drwxrwxr-x 2 team01 staff 1024 Jan 15 10:45 abc-rwxrwxr-x 2 team01 staff 512 Aug 18 15:40 ssa

Page 20: AIX Basics

[email protected]

• 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

Page 21: AIX Basics

[email protected]

• mkdir commandmkdir [ 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

Page 22: AIX Basics

[email protected]

• rmdir command rmdir [ directory ]– The rmdir command removes a directory.

$ rmdir /home/team01/aaa

$ cd home

$ rmdir team01rmdir: team01 not empty

$ rmdir –p dir1/dir2/dir3

Page 23: AIX Basics

[email protected]

• rmdir command rmdir [ directory ]– The rmdir command removes a directory.

$ rmdir /home/team01/aaa

$ cd home

$ rmdir team01rmdir: team01 not empty

Directory must be empty in order to delete it

Page 24: AIX Basics

[email protected]

• 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

Subdir1 4

myfile 10

# Type mode links User Group Date Size loc

4 dir 755 2 jim staff jan 10 9:15


10 file 644 1 jim staff jan 10 9:15


$ vi myfile

Page 25: AIX Basics

[email protected]

$ istat mydirInode 51 on device 10/8 DirectoryProtection: rwxr-xr-x

owner: 208(team01) Group: 1 (staff)Link count: 2 Length 512 bytes

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

Page 26: AIX Basics

[email protected]

• touch commandtouch 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

Page 27: AIX Basics

[email protected]

• 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

Page 28: AIX Basics

[email protected]

• move commandmv source target– The mv command can be used to move files and directories

and also rename them.

$ pwd/home/team01$ mv test test.out

Page 29: AIX Basics

[email protected]

• 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 aathis is a file to test the output of cat command.this file is created using vi editor.

$ pg aa

$ more aa

Page 30: AIX Basics

[email protected]

• 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.

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

$ wc -lcw abc_file15 154 996 abc_file




Page 31: AIX Basics

[email protected]

• 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

Page 32: AIX Basics

[email protected]

• 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

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

$ qcan 23

job number

Page 33: AIX Basics

[email protected]

• File protection/permissions

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

Permission bits

file/dir link count



character count

last modified time filename

Page 34: AIX Basics

[email protected]

• File protection/permissions

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

Permission bits

rwx r-x r-x

Owner (u) Owner’s

Group (g)

Others (o)r ---- read

w ---- writex ---- execute all


Page 35: AIX Basics

[email protected]

• Changing permissions

Page 36: AIX Basics

[email protected]

• 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

Page 37: AIX Basics

[email protected]

• octal notation; chmod mod filename

r ---- 4 w ---- 2x ---- 1

rwx r-x rw-



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

U g O

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

Page 38: AIX Basics

[email protected]

• 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.

$ umask022

Page 39: AIX Basics

[email protected]

• The Vi editor

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

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

Page 40: AIX Basics

[email protected]

• The Vi editor

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

Page 41: AIX Basics

[email protected]

• The Vi editor$ vi tstfile~~~~~ ~“tstfile” [New file]

Cursor Movement


a -- add text after cursorA -- add text to the end of linei -- insert text at the cursorI -- insert text at the start of line

To exit TEXT MODE press <Esc>




Page 42: AIX Basics

[email protected]

• 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

Page 43: AIX Basics

[email protected]

• 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


Global Replacement:g/abc/s//xyz/g replaces “abc” with “xyz”

throughout the entire file

yy copy a line p paste the copied line

Page 44: AIX Basics

[email protected]

: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

• vi options– we can change the behaviour of vi by setting some options.– options are stored in the file $HOME/.exrc

Page 45: AIX Basics

[email protected]

$ set –o vi

$ set +o vi turn off command recall facility

• 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.

Page 46: AIX Basics

[email protected]

• vi EDITORS– There are various forms of vi.

read-only form of vi

beginner’s version of vi

subset of vi working in line mode

simple form of ex

Page 47: AIX Basics

[email protected]

• SHELL Basics– The Shell is the primary interface between the user and the OS.

Page 48: AIX Basics

[email protected]

• 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.

Page 49: AIX Basics

[email protected]

$ 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

• Examples

Page 50: AIX Basics

[email protected]

• 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

Page 51: AIX Basics

[email protected]

• 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 –l124

• Filters– A filter is a command that reads from stdin, processes it and

then writes it to stdout.

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


Page 52: AIX Basics

[email protected]

• Tee– The tee command reads stdin and sends the data to both

stdout and a file.

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


ls -l tee wc -l


Page 53: AIX Basics

[email protected]

• 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

Page 54: AIX Basics

[email protected]

• 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


Page 55: AIX Basics

[email protected]

• Setting and Referencing Shell Variables

$ SHELL=/usr/bin/bash assign a value to a shell variable

$ xy=hi friends$ echo $xy referencing a variablehi friends

$ unset xy delete a variable

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

Page 56: AIX Basics

[email protected]

• Commmand substitution

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

Page 57: AIX Basics

[email protected]

• Quoting Metacharacters

– ‘ ‘ Single Quotes Ignores all metacharacters between the quotes.

– “ “ Double Quotes Ignore all metachar., except for $,` and \

– \Backslash Ignore the special meaning of the following character

$ echo ‘$HOME’$HOME

$ echo “$HOME”/home/team01

$ echo \$HOME$HOME

Page 58: AIX Basics

[email protected]

• 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

Page 59: AIX Basics

[email protected]

• 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

kernel loads ksh

Page 60: AIX Basics

[email protected]

• Variables and Processes– variables are part of the process environment.Processes

cannot access or change variables from another process.

– 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.

$ x=4$ ksh$echo $x

$x=1$<ctrl-d>$echo $x4


Page 61: AIX Basics

[email protected]

• Exporting variables

$ x=4$ y=6$ export y$echo $x; echo $y46$ksh$echo $x

$echo $y6$y=11<ctrl-d>$echo $y6


variable is exported to subshell

variable is not exported

Page 62: AIX Basics

[email protected]

• 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 helloecho “hi friends today is $(date)”pwd

$ksh hello execute scripthi friends today is Mon Aug 12 2008 12:34/home/team01


Page 63: AIX Basics

[email protected]

• 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 helloecho “hi friends today is $(date)”pwd

$ chmod +x hello

$ hello execute scripthi friends today is Mon Aug 12 2008 12:34/home/team01


Page 64: AIX Basics

[email protected]

• 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 helloecho “hi friends today is $(date)”pwd

$.hello execute scripthi friends today is Mon Aug 12 2008 12:34/home/team01


Page 65: AIX Basics

[email protected]

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


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

0 = Success1-255 = An error has occured

Page 66: AIX Basics

[email protected]

• ps command– The ps command displays process status information.

$ps -fUID PID PPID ... TTY ... COMMANDjim 205 1 ... tty0 ... lsjim 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

Page 67: AIX Basics

[email protected]

• 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


$ps –f > pro.out background process

Page 68: AIX Basics

[email protected]

• Terminating Processes

$kill 202 (Termination signal)$kill -9 215 (kill signal)

Page 69: AIX Basics

[email protected]

• 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)

Page 70: AIX Basics

[email protected]

• 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] 34sending output to nohup.out$_

Page 71: AIX Basics

[email protected]

• 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

Page 72: AIX Basics

[email protected]

• 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.

Page 73: AIX Basics

[email protected]

• 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.

Page 74: AIX Basics

[email protected]

• User Environment – Login Files






rootcan only be changed by system admin

can only be changed by system admin

can be changed by the user

Page 75: AIX Basics

[email protected]

• 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.


Page 76: AIX Basics

[email protected]

• 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 LOGNAMEumask 022TMOUT=120MAIL=/usr/spool/mail/$LOGNAMEMAILMSG=“[YOU HAVE NEW MAIL]”TERM-ibm3151


Page 77: AIX Basics

[email protected]

• sample .profile

$ cat .profile


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

Page 78: AIX Basics

[email protected]

• 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

Page 79: AIX Basics

[email protected]

• sample .kshrc

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

$ cat .kshrc

# set up the command recall facility

set –o vi

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

Page 80: AIX Basics

[email protected]

• 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’

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

$unalias l

$ lksh: l: not found

Page 81: AIX Basics

[email protected]

• 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 commands2 cd /home/list3 ls –l4 fc –l5 mail

$ r mNo mail for team01

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

Page 82: AIX Basics

[email protected]

• 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

• AIX Utilities

Page 83: AIX Basics

[email protected]

• Executing commands with find– The exec command executes a command on each of the files


– 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.

$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

Page 84: AIX Basics

[email protected]

• Interactive command execution– The ok option causes command execution on an interactive


$find . –name m\* –ok rm {} \;<rm ... ./shape/misc>? y<rm ... ./shape/medium>? y<rm ... ./misc>? n

Page 85: AIX Basics

[email protected]

• 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”

Page 86: AIX Basics

[email protected]

• 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

Page 87: AIX Basics

[email protected]

• find with the –links option

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

$ find /home –type f –links +1 | xargs ls –li

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

same i-node

no. of linkssame no. of bytes

Page 88: AIX Basics

[email protected]

• 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 phone1Hotline HW 800 322-4500

$ps –ef | grep team01team01 10514 13254 0 09:54:55 pts/1 0:00 -ksh

Page 89: AIX Basics

[email protected]

• 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

Page 90: AIX Basics

[email protected]

• grep examples

$ps –ef | grep team01team01 10514 13254 0 09:54:55 pts/1 0:00 -ksh

$grep ‘^B’ phone1Baker jim 454-3414

$grep ‘5$’ phone1Avis Betty 125-4625

$grep ‘^[DH]’ phone1Dade travel sam 434-5643Hotline HL 322-4500

^ - start

$ - end

[DH] - enumeration

Page 91: AIX Basics

[email protected]

• 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

Page 92: AIX Basics

[email protected]

• Other greps• fgrep fast grep only fixed strings;no


• egrep Extended grep allows multiple patterns

$fgrep ‘HW’ phone1Hotline HW 800 322-3455 slightly faster

$egrep ‘800|817’ phone1 slightly slowerHotline HW 800 322-3455sam jim 817 322-3434

Page 93: AIX Basics

[email protected]

• sort command– The sort command sorts lins and writes the result to standard


$ cat animalsdog.2cat.4rabbit.7$ sort animals default sort ordercat.4dog.2rabbit.7$ cat animals | sort +0.1 sort by second char.,rabbit.7cat.4dog.2

Page 94: AIX Basics

[email protected]

• 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

Page 95: AIX Basics

[email protected]

• 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 oldfilesfile1file2file3file4

$cat oldfiles | xargs –t rmrm file1 file2 file3 file4

Page 96: AIX Basics

[email protected]

• xargs more examples– Here we create a list of files to be printed and queue them up for

printing through xargs.

– Here { } is called a placeholder and the –I flag tells xargs to insert each line of the ls directory listing where { } appears.

$ls > printlist$xargs –t qprt < printlist qprt file1 file2 file3

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

Page 97: AIX Basics

[email protected]

• xargs,find and grep– Using xargs is more efficient and easier to remember than the

find commanad

$ find . –type f –mtime +30 | xargs –t rmrm ./file1 ./file2 ./file3

$ find . –type f | xargs –t grep –l Hellogrep –l Hello ./file4 ./file7 ./file10

Page 98: AIX Basics

[email protected]

• 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

Page 99: AIX Basics

[email protected]

• 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 clcl: ascii file

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

Page 100: AIX Basics

[email protected]

• 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

1c1< Carol---->Caroline4d3< Don5a5> Sam

names names.old

Carol carolineBob jimJim MaryDon SamMary <

>a indicates lines that should be appended to first file to 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.

Page 101: AIX Basics

[email protected]

• cmp (compare)– The compare command works with all types of files and it

reads two files until it finds any differences and reports them.

– 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.

$ cmp names names.oldnames names.old differ: byte 6,line1

$ cmp –l names names.old6 12 1517 102 154........cmp:EOF on names

Page 102: AIX Basics

[email protected]

$tn miamiTrying ...connected to miami...

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

• Telnet– The tn command allows to login to remote systems.

Page 103: AIX Basics

[email protected]

$ftp miamiconnected to miami220 FTP server readyName (miami: team01): team05Password rewquired for team05.Password:230 User team05 logged in.ftp>

• FTP– The ftp command allows us to transfer files in a network.

ftp prompt

Page 104: AIX Basics

[email protected]

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

• FTP subcommands– The most important ftp subcommands are:

Page 105: AIX Basics

[email protected]

• 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

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

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

Page 106: AIX Basics

[email protected]

• 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 filetar –tvf /dev/rmt0

Page 107: AIX Basics

[email protected]

• compress,uncompress,zcat– The compress command compresses a file and replaces the original

file with a .z appended to it.$ ls –l file1127 –rw-r--r– 3 team01 staff 13354 oct 29 12:15 /home/file1

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

$ ls –l file1127 –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 file1127 –rw-r--r– 3 team01 staff 13354 oct 29 12:15 /home/file1

Page 108: AIX Basics

[email protected]

• 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

Page 109: AIX Basics

[email protected]

• Positional Parameters– Parameters can be passed to shell scripts as arguments on the

command line

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

$ ascript good morning friendsfirst parameter is goodsecond parameter is morningthird parameter is friends

Page 110: AIX Basics

[email protected]

• expr Utility– The expr utility can be used to perform integer arithmetic.

– \* multiplication– / integer divison– % remainder– + addition– - subtraction

$ x=6$ y=3$ expr $x/$y2$ expr $x-$y3$ expr \($x+$y)\*4 \(\) to group expressions36



precedence order

Page 111: AIX Basics

[email protected]

• conditional execution– The exit value from a command or a group of commands can be

used to determine whether to do the next command.

$ ls s* && rm s*

command1 && command2if command1 is succesful then do command2

$ cd /dir1 || echo cannot change to dir1

command1 || command2if command1 is not succesful then do command2

Page 112: AIX Basics

[email protected]

• 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

Page 113: AIX Basics

[email protected]

• if command

• The exit statement is used to terminate a process.

if condition is truethen carry out this set of actionselse carry out these alternative actions optionalfi

Page 114: AIX Basics

[email protected]

• if command (example)

$ cat activeusage=“$0: userid”

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

if who | grep $1 > /dev/nullthen echo “$1 is active”else echo “$1 is not active” fi


Page 115: AIX Basics

[email protected]

$ cat delfile

# usage: delfileecho “please enter the filename:”read nameif [[ -f $name ]]then

rm $nameelse

echo “error: $name is not an ordinary file”fi

• read command– The read command reads one line from stdin and assigns the values

of each field to a shell variable.

– 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...

Page 116: AIX Basics

[email protected]

$ cat countfor var in ls.out err.outdowc –l $vardone

$ count12 ls.out34 err.out

• for loop

for variable in listdo


$ cat rm_tmpfor file in /tmp/*doecho “removing $file”rm $filedone

Page 117: AIX Basics

[email protected]

$ cat infox=1while [[ $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


• While loop

while expressiondo


Page 118: AIX Basics

[email protected]

• command search order• The shell looks for a in the following order.

Page 119: AIX Basics

[email protected]

• 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.

Page 120: AIX Basics

[email protected]

• X Window– The X-window is a N/W based graphics system.

X-station RISC workstation RS/6000 Workstation

RS/6000 Workstation RS/6000 server Intel PC

Page 121: AIX Basics

[email protected]

• 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.

Page 122: AIX Basics

[email protected]

• 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

Page 123: AIX Basics

[email protected]

• 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.

Page 124: AIX Basics

[email protected]

• X Server– Each X server controls one keyboard. one mouse and one or more


– 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

Page 125: AIX Basics

[email protected]

• 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.

Page 126: AIX Basics

[email protected]

• 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

Page 127: AIX Basics

[email protected]

• 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.

Page 128: AIX Basics

[email protected]

• Running a Client on Another System– Here sys2 runs the client application(aixterm) while sys1 needs to

display the output.

sys1 sys2

$ rexec sys2 aixterm –display sys1:0

remote execute comand

xclient application xserver

Page 129: AIX Basics

[email protected]

• 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

Page 130: AIX Basics

[email protected]

• 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.,

Page 131: AIX Basics

[email protected]

• 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.

Page 132: AIX Basics

[email protected]

• 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/.XdefaultsAixterm*background: greyAixterm*foreground: navyAixterm*font: rom10xclock*update: 1Mwm*keyboardFocusPolicy: explicit

Page 133: AIX Basics

[email protected]

• 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.