Saturday, March 31, 2012

VI TUTORIAL


vi Editor, Learn vi

About vi editor
  • vi is Found on Nearly Every Unix Computer
  • vi is the standard Unix editor
  • vi is Powerful and Fast
  • Your terminal displays a section of the file you are editing
  • vi can do anything you want
  • You don't need to remove your fingers from the standard typing keys-the keys themselves give commands to vi
  • vi Stays Out of Your Way
  • vi has no menus
  • vi commands are short


Starting vi
Open a file with vi.
Type: vi myfile.txt
If myfile.txt does not exist, a screen will appear with just a cursor at the top followed by tildes (~) in the first column.

If myfile.txt does exist, the first few line of the file will appear.

The status line at the bottom of your screen shows error messages and provides information and feedback, including the name of the file.

vi Modes

Command Mode
·  Command mode is the mode you are in when you start (default mode)
·  Command mode is the mode in which commands are given to move around in the file, to make changes, and to leave the file
·  Commands are case sensitive: j not the same as J
·  Most commands do not appear on the screen as you type them. Some commands will appear on the last line: : / ?

Insert (or Text) Mode
·  The mode in which text is created. (You must press at the end of each line unless you've set wrap margin.)
·  There is more than one way to get into insert mode but only one way to leave: return to command mode by pressing
·  When in doubt about which mode you are in, press

Basic Cursor Movement
k
Up one line
j
Down one line
h
Left one character
l
Right one character (or use )
w
Right one word
b
Left one word

NOTE: Many vi commands can take a leading count (e. g., 6k, 7e).

Entering, Deleting, and Changing Text
i
Enter text entry mode
x
Delete a character
dd
Delete a line
r
Replace a character
R
Overwrite text, press to end


Setting Basic Options in vi
Displaying Line Numbers
:set nu
Display line numbers
:set nonu
Hide line numbers

Setting Right Margin
:set wm=number
Set Wrap Margin number of spaces from right edge of screen
:set wm=10
Set Wrap Margin 10 spaces from right edge of screen
:set wm=0
Turn off Wrap Margin

Exiting vi
To exit you must be in command mode-press if you are not in command mode

You must press after commands that begin with a : (colon)
ZZ
Write (if there were changes), then quit
:wq
Write, then quit
:q
Quit (will only work if file has not been changed)
:q!
Quit without saving changes to file


Basics Summary
A Basic vi Session
To enter vi, type: vi filename
To enter insert mode, type: i
Type in the text: This is easy.
To leave insert mode and return to command mode, press:
In command mode, save changes and exit vi by typing: :wq
You are back at the Unix prompt.


INTERMEDIATE VI
More On Cursor Movement
e
Move to end of current word
$
Move to end of current line
^
Move to beginning of current line
+
Move to beginning of next line
-
Move to beginning of previous line
G
Go to last line of the file
:n
Go to line with this number (:10 goes to line 10)
d
Scroll down one-half screen
u
Scroll up one-half screen
f
Scroll forward one full screen
b
Scroll backward one full screen
)
Move to the next sentence
(
Move to the previous sentence
}
Move to the next paragraph
{
Move to the previous paragraph
H
Move to the top line of the screen
M
Move to the middle line of the screen
L
Move to the last line of the screen
%
Move to matching bracket: ( { [ ] } )


Entering Text Mode
i
Insert text before current character
a
Append text after current character
I
Begin text insertion at the beginning of a line
A
Append text at end of a line
o
Open a new line below current line
O
Open a new line above current line


Commands and Objects
Format
Example
operator number object
c2w
number operator object
2cw


Operators
c
change
d
delete
y
yank

Objects and Locations
w
one word forward
b
one word backward
e
end of word
H, M, L
top, middle, or bottom line on screen
), (
next sentence, previous sentence
}, {
next paragraph, previous paragraph
^, $
beginning of line, end of line
/pattern/
forward to pattern


Replacing and Changing Text
r
Replace only the character under the cursor. (Note: using r you remain in command mode.)
R
Beginning with the character under the cursor, replace as many characters on this line as you want. (You are in overtype mode until you press
cw
Beginning with the character under the cursor, change a word to whatever you type. (You are in insert mode until you press )
c$
Beginning with the character under the cursor,
C
change a line to whatever you type. (You are in insert mode until you press )


Deleting Text
x
Delete a character
dw
Delete an alphabetic word and the following space (6dw deletes six words)
dW
Delete a blank-delimited word and the following space
dd
Delete a line (6dd deletes six lines)
d$
Delete all characters to the end of the line.
d}
Delete all characters to the end of the paragraph.
:5,30d
Delete lines 5 through 30

Deleted text goes into a temporary buffer that is replaced each time you delete (or copy) more text. The current contents of the buffer can be put back into your file.

Copying and Pasting Text
yy
Copy (yank) the current line
6yy
Copy (yank) six lines, beginning with the current line
yw
Copy the current word
p
Put the text after the cursor position
P
Put the text before the cursor position
Copied text goes into a temporary buffer that is replaced each time you copy (or delete) more text. Only the current contents of the temporary buffer can be put back into your file. As a result, when you use copy (y), use the put (p) command immediately.

A yank and put procedure using colon commands:
:5,10y Copy lines 5-10

Move cursor
:put Put after cursor

Other Useful Commands
.
Repeat last command
n.
Repeat last command n number of times
J
Join next line to current line
u
Undo last single change
U
Restore current line
~
Change letter's case (capital to lower and vice versa)


Buffers
Temporary Buffer
Deleted or copied text goes into a temporary unnamed buffer. The contents of the temporary buffer may be retrieved by using the p or P commands.
p
Put words from temporary buffer after cursor or put lines from temporary buffer below current line
P
Put words from temporary buffer before cursor or put lines from temporary buffer above current line


Lettered Buffers
There are 26 lettered buffers (a-z). Contents of a lettered buffer are saved until you copy or delete more characters into it, or until you quit your current vi session.
"ayy
Copy (yank) a line into buffer a
"Ayy
Appends to buffer a
"a10yy
Copies 10 lines into buffer a
"a10dd
Deletes 10 lines of text into buffer a
"ap
Put contents of lettered buffer a below the current line

Both temporary and lettered buffers last only for the current vi session.

Copying, Deleting, or Moving Text Using Line Numbers
These commands start with a colon (:) and end with a or g shows the line number of the current line
The basic form of colon commands is

:beginning_line, ending_line command destination

where destination is the line after which you want the text placed.
:5,10 co 105
Copy lines 5-10 to the line after 105
:5,20 m $
Move lines 5-20 to end of file
:7,300 d
Delete lines 7-300 (to buffer)


Searching for Text
/text
Search forward (down) for text (text can include spaces and characters with special meanings.)
?text
Search backward (up) for text
n
Repeat last search in the same direction
N
Repeat last search in the opposite direction
fchar
Search forward for a charcter on current line
Fchar
Search backward for a character on current line
;
Repeat last character search in the same direction
%
Find matching ( ), { }, or [ ]


Substitutions
The simplest way to do substitutions over a range of lines, or throughout the file, is to use the s colon command. The basic form of this command is the following:

:n1,n2s/old/new/gc
n1
is the beginning line
n2
is the ending line number
s
means to substitute text matching the pattern (old) with text specified by (new)
g (global)
is optional. It indicates you want to substitute all occurrences on the indicated lines. If you use g, the editor substitutes only the first occurrence on the indicated lines.
c (confirm)
is optional. It indicates you want to confirm each substitution before vi completes it.

:%s/old/new/g
Substitutes old with new throughout the file
:.,$s/old/new/g
Substitutes old with new from the current cursor position to the end of the file
:^,.s/old/new/g
Substitutes old with new from the beginning of the file to the current cursor position
:&
Repeats the last substitute (:s) command


ADVANCED VI TUTORIAL

Writing to and Reading from Files
:w file
Write current file to file
:w>>file
Append current file to file
:5,10w file
Write lines 5 through 10 to file
:5,10w>>file
Append Lines 5 through 10 to file
:r file
Read a copy of file into current file
:!ls
See a list of files in your current directory


More About Options From Command Mode-within vi for the current file only
:set all
Display all options
:set
Display current settings of options
:set nooption
Unset option
:set ai
Set Auto Indentation during text entry
:set ic
Set Ignore Case during searches
:set nu
Show line Numbers
:set sm
Show Matching ( or { when ) or } is entered
:set wm=10
Set Wrap Margin 10 spaces from right edge of screen


Customizing vi Sessions Options can be set four ways:
·  During a vi session
  • :set nu
·  In a .exrc file in your home directory. Sample contents of a .exrc file
  • set nu
  • set ai
  • set wm=10
·  In a .exrc file in a subdirectory.
·  By setting the EXINIT environmental variable. Example of setting the EXINIT environmental variable
  • setenv EXINIT "set nu ai ic"


Order of Precedence
·  If a .exrc file exists in the current directory, vi reads it when beginning a session.
·  If no .exrc file exists in the current directory, vi checks the home directory for a .exrc file. If such a file exists, vi reads it when beginning a session.
·  If no .exrc file is found, vi uses its defaults.
·  Values set in the EXINIT environmental variable override any values set in a .exrc file.

Creating a .exrc File

At the system prompt, type: vi .exrc
Type the following commands, each on a separate line:
·  set ai
·  set ic
·  set nu
·  set wm=8 Do not leave blank lines at the beginning or end of the .exrc file.
When you are finished, type: ZZ

Abbreviations & Mapping
Abbreviations are text strings that automatically expand into larger strings during insert mode.
:ab SK Senthilkumar Muthusamy

Mapping defines a single key to execute a sequence of keystrokes when the single key is pressed in command mode. In the following example,the @ key is mapped to replace the current word with "Senthilkumar Muthusamy". The v allows you to enter the key into the command sequence.
:map @ cwSenthilkumar Muthusamy v

Mapping can also be used to call commands external to vi, such as sort or fmt. In the following example, the @ sign is mapped to the sort command, so that the current paragraph (indicated by the }) will be sorted. The v allows you to enter the key into the command sequence. The second completes the map command.
:map @ !}sort v

Note: You can also put abbreviation and mapping commands in your .exrc file.

TIPS AND TRICKS

Find the line that reads
editor=
Change it to read
editor=vi
Write and quit the file. (ZZ or :wq) vi-ing More Than One File
You can edit more than one file at a time with vi.
From The Unix Shell Prompt
vi file1 file2 vi two (or more) files at the same time From Command Mode
:n
Move to file2 from file1
:rew
Rewind back to file1
:e!
Restore original file1 file2 (start all over)
ZZ
Save and quit file. (Must be done for each file.)


Moving the Left Margin
When you print a file you may want the left margin moved to the right. This leaves room for a three-hole punch.
:1,$>
Move entire file 1 shift width (eight spaces) to the right
:1,$<
Move entire file eight spaces to the left
:%s/^/ /g
Insert any number of spaces at the beginning of each line in the entire file. Simply press the space bar the desired number of times.
:20>>
Moves next 20 lines over 1 shift width.


Issuing Shell Commands From vi
You can issue a single shell command while in the vi editor. For example, to list the files in your directory (ls), follow these steps:
:w
Write changes to your file (just in case).
:!ls
List contents of your current directory on the screen. Press to return to vi. You can issue many shell commands by temporarily leaving the vi editor. From Command Mode
:w
Write changes to your file.
:sh
Return to the shell to enter a number of commands without leaving vi.

Press d to return to vi editing.

Double Spacing a File
Occasionally, you may want a double spaced version of your file for editing or review.


:w
original.backup Save a backup copy of the original file
:%! sed G
Double space the entire file.
:1,5! sed G
Double space the lines from 1-5.



AIX COMMANDS LIST


 VG COMMANDS


lsvg                                                         Display all VGs
lsvg -o                                                    Display all active VGs
lsvg rootvg                                             Display info about rootvg
lsvg  -l rootvg                                         Display info about all LVs in rootvg
lsvg -o |lsvg -il                                        Display info about all LVs in all VGs
lsvg  -p rootvg                                        Display info about all PVs in rootvg
mkvg  -s 8 hdisk1                                  Create VG with name vgxx on hdisk1 with partition size 8MB
mkvg -s 8 -y sivg hdisk1                        Create VG with name sivg on hdisk1 with partition size 8MB
mkvg -s 4 -t 2 -y sivg hdisk1                 Create sivg on hdisk1 with PP size 4 and no of partions 2 * 1016
chvg -a y newvg                                   To cuase VG newvg automatically activated at startup
chvg -a n newvg                                   To deactivate the automatic activation at startup
chvg -t 2 newvg                                    To change maximum no. of PP to 2032 on vg newvg
chvg -Q n newvg                                  To disable quorum on VG newvg
reorgvg  newvg                                     Reorganises PP allocation of  VG newvg
extendvg newvg hdisk3 hdisk4             Add PV hdisk3 and hdisk4 to VG newvg
exportvg newvg                                   Exports the VG newvg
importvg -V 44 -y newvg   hdisk2    Import the hdisk2 with name  newvg, and assign major number 44
redcucevg newvg hdisk3                    Remove PV hdisk3 from VG newvg
varyoffvg newvg                                 To deactviate VG newvg
varyonvg newvg                                  To activate VG newvg
syncvg -v sivg                                       To sync the mirrored LV in the VG sivg
mirrorvg -S -m sivg hdisk2                 To mirror LVs of sivg with hdisk2 (-m for exact mirror, -S
forbackground  mirror)
unmirrorvg sivg hdisk2                       To remove the mirrored PV from the set.

FS COMMANDS


lsfs                                                          Lists all filesystems in the /etc/filesystems entry
lsfs -q                                                     List all filesystems with detailed info
lsfs -a                                                     To list all filesystems (default)
lsfs -l                                                       Specify the output in list format
lsfs -c                                                      Specify the output in column format
lsfs -v jfs                                                Lists all jfs filesystems
chfs -a size=24576 /si                         Change size of FS /si to 24576 x 512 bytes blocks (12 MB)
chfs -a size=+24576 /si                       Add 24576 x 512 byte blocks to FS /si
chfs -asize=-500M /file/system        you can also decrease size
chfs -m /si /bi                                        Change the mount point from /si to /bi
chfs -A /si                                              To auto mount the filesystem si
chfs -d account /si                               Remove account attribute of /si. ( from /etc/filesystems file)
chfs -a splitcopy=/backup -a copy=2 /oracle  This will mount the 2nd copy of mirrored filesystem oracle to
/backup in read-only mode
crfs -v jfs -g testvg -a size=64465 -m /siju    Creates FS /siju of type jfs in VG testvg of blocksize 64465
crfs -v jfs -d /dev/lv00 -m /siju         Create FS /siju of type jfs on device /dev/lv00
rmfs /siju                                               Deletes FS /siju and associated LV
rmfs -r /siju                                           Deletes FS /siju its mount point and associated LV
defragfs /sifs                                         To defragment the file system /sifs
defragfs -q /sifs                                    Display the current defrag status of the file system
fsck  -y n /dev/lv00                             To fsck the filesystem associated to /dev/lv00 assuming response "yes"
fsck -p /dev/lv00                                 To restore superblock from backup superblock 

PV COMMANDS


lspv hdisk0                                            Display status and characteristics of the PV
lspv -p hdisk0                                       Display  PP usage of hdisk0                                                             
lspv -l hdisk0                                        To list all logical volumes on PV hdisk0
chpv -v r hdisk1                                   Close the PV (Used while removing PV without varyon)
chpv -v a hdisk1                                  Open the PV
chpv -c hdisk0                                      Clear the master boot record on PV hdisk0
migratepv  hdisk1 hdisk2                   To move PPs from PV hdisk1 to hdisk2
migratepv -l silv hdisk1 hdisk2         To migrate LV silv from PV hdisk1 to hdisk2




LV COMMANDS


lslv -l lv00                                              Display info about LV by PV
lslv -p hdisk1                                        Display LV allocation map for hdisk1
chlv -t copy lv00                                  To change the lv00 to copy type
chlv –n silv lv00                                   To rename lv00 to silv
chlv -x 950 ora1data_lv                    To change the ora1data_lv to <XXX to 950 PP>
chlv -p r lv00                                        To change the lv00 to readonly mode
rmlv silv                                                 To remove silv
rmlv -f silv                                             To remove silv without user intervention
mklv  -s n -c 3 silv hdisk1                   To make LV silv  with three copies on hdisk1
extendlv  silv 5                                     To extend the LV silv with 5 LPs
mklvcopy -s n lvsi 2 hdisk1               To mirror LV lvsi on same PV with 2 copies
mklvcopy lvsi 3 hdisk1 hdisk2         To mirror LV lvsi on PV hdisk1 and hdisk2 with 3 copies
rmlvcopy lvsi 2 hdisk1                       Will remove one copy of  LV lsvi from hdisk1
mklv -t jfslog -y log00 newvg 2        To create a jfslog with name log00 on VG newvg with 2LPs
logform /dev/log00                             To format jfslog volume log00
mklv/extendlv -a = PP alocation policy
-am = middle   -ac = center   -ae = edge
-aie = inner edge    -aim = inner middle
migratepv -l (lv) (old pv) (new pv)
Move a logical volume between physical volumes. Both physical volumes
must be in the same volume group !
mklv -y (lv) -t jfslog (vg) (No of PP's) (pv Name optional)
Creates a JFSlog logical volume.
logform (/dev/lv)       Initialises an LV for use as an JFSlog
getlvcb -AT (lv)        Displays Logical Volume Control Block information


BLV COMMANDS


bootlist -m normal -o                          To see the boot sequence in normal mode
bootlist -m service -o                           To see the boot sequence in service mode
bootlist -m normal cd0 hdisk0          To change boot sequence to cd0,hdisk0 in normal mode
bootlist -m service cd0 rmt0 hdisk0                 To change boot sequence to cd0,rmt0,hdisk0 in service mode
bosboot -ad /dev/hdisk1                    To create boot image on PV hdisk1
mkboot -cd /dev/hdisk1                     To clear the boot image
bootinfo -b                                            Specifies the bootable disk
bootinfo - t                                            Specifies the type of boot
bootinfo -e                                            Check the machine can boot from tape
bootinfo -T                                           To see the machine hardware type
bootinfo -s hdisk0                               To see the size of hdisk0
bootinfo -r                                             To see the size of memory
bootinfo –k                                           To see the key position
bootinfo –m                                         To see the machine model code
bootinfo –o hdisk0                              To list the location code of hdisk0
bootinfo –z                                           To see the machine is multiprocessor capable
bootinfo –p                                           To see the machine
bosboot -a -d (/dev/pv)                    Creates a complete boot image on a physical volume.
mkboot -c -d (/dev/pv)                     Zero's out the boot records on the physical volume.
savebase -d (/dev/pv)                       Saves customised ODM info onto the boot device.

PAGE SPACE COMMANDS


lsps -a                                                     To list out all paging spaces
lsps hd6                                                 To display the details of the paging space hd6
chps -a y paging00                              To turn on the paging space paging00
chps -a n paging00                              To turn off the paging space paging00
chps -s4 paging00                                To increase the size of the paging space in 4 LP blocks
mkps -a -n -s4 sivg                              To create a paging space on VG sivg of 4 LP size (-s4) and activate it
immediately (-n) and activate it at every restarts
rmps paging00                                     To remove the paging space paging00
swapon -a                                             To invoke all entries in /etc/swapspaces file
swapon /dev/paging00                       To make available swap space paging00


SYSTEM DUMP COMMANDS


sysdumpdev -l                                      To list the current dump destination
sysdumpdev -L                                    List the details of the previous dump
sysdumpstart -p                                   Starts dump in the primary dump device
sysdumpstart -s                                    Starts dump in the secondary dump device
sysdumpdev -p /dev/lv00                  To make lv00 as primary dump device
sysdumpdev -P -p /dev/lv00             To make lv00 as primary dump device permanently
sysdumpdev -s /dev/rmt0                  To make rmt0 as secondary dump device
sysdumpdev -z                                     To determine a new system dump occurred

   SYSTEM DUMP
--------------------------------------------------------------------------------
sysdumpdev -e        Estimates dumpsize of the current system in bytes.
(MCA machine can also dump if key is in service position and the reset
 button is pressed)
sysdumpdev -p (dump device) -P        Sets the default dump device, permanently
Analyse dump file :-
echo "stat\n status\n t -m" | crash /var/adm/ras/vmcore.0


 

Device related commands


cfgmgr                                                   To configure devices and installs device software in system
cfgmgr -l vscsi0                                    To configure the components connected to the vscsi0 interface
lscfg                                                        To display config, diagnostics and vital product definition info
lscfg -l mem0                                        Display info about device mem0
lscfg -l ent*                                           Display info about all Ethernet cards
lscfg -v                                                   Display vpd
lscfg -v -l hdisk0                                   Display vpd of hdisk0
mkdev   -l rmt0                                    To change device rmt0 from defined state to available state
lsdev -P                                                  To lists all supported devices
lsdev -P -c disk                                     To list all supported disks
lscfg -vp|grep -ip cabinet                   To list all cabinets
lsdev -P -r class                                     To display supported class
lsdev -P -r subclass                              To display all sub class
lsdev -C                                                 To lists all configured devices
lsdev -C -l mem0                                 To display the properties of mem0
chdev -l sys0 -a maxproc=100         To change default maxproc value to 100
chdev -l rmt0 -a blocksize=512        To change the block size to 512
chdev -l rmt0 -a ret=no                       To avoid tape retension
rmdev -l rmt0                                       To remove the device rmt0
rmdev -d -l rmt0                                   To remove the device totally from database
rmdev -l rmt0 -S                                   To change the state of the device stopped
lsparent -C -k  rs232                            To display possible parent devices which accept rs232 devices
lsparent -C -l hdisk0                            To display parent devices which accept child device hdisk0
lsattr -Dl rmt0                                       To see the default values of the device rmt0
lsattr -El rmt0                                       To see the current values of the device rmt0
lsattr -El tty0 -a login -R                     To see all possible values of the login attribute of tty0
lsattr -R -l ent0 -a media_speed
lsconn -p scsi0                                      To list all possible connection scsi0 can accept
lvlstmajor                                              To list the available major numbers
mknod /dev/null c 2 2                        Create null device with major (2) and minor (2) nos. (c - char device)
lsattr -E -l sys0 -a maxuproc


Console emulation commands


lscons                                                     To list the current console
lscons -b                                                To list the console at next boot
chcons /dev/tty3                                  To change the console to tty3
chcons -a login=enable /dev/tty3     Redirect console to tty3 and provide login prompt
swcons /dev/tty3                                 To change system console to tty3 temporarily
alog  -L –t console                               To see the current attributes of log type console
alog –t console –o                               To see the console messages
alog –t boot –o                                     To see the boot time messages

Installation specific commands


lslpp -l                                                    To see the details of installed file sets
lslpp -ha bos.net.*                               To list the installation history of all file set in bos.net packages
lslpp -f bos.rte                                       To list the files in the bos.rte package
lslpp -w /etc/hosts                                To list the file set which contain /etc/hosts file
lslpp -p bos.net.nfs.server                   To list the pre requisites for bos.net.nfs.server file set
installp -L -d /dev/rmt0.1                   To list the installable products on the device rmt0
installp -aX -d /dev/rmt0.1 bos.net  To install all filesets within bos.net and expands file system if it requires
installp -u bos.net                                                To remove bos.net
installp -r                                               To reject the applied software
installp -c -f <product>                       To commit the <product>
installp -C                                              To cleanup an incomplete installation
lppchk -c <product>                            To check the <product>
instfix -k IX9999 -d /dev/rmt0.1      To install the file set associated with fix IX9999 from rmt0
instfix  -ik IX9999                               To verify fix IX9999 installed


Network related commands


host 193.9.200.1                                  Resolves ip to host name (from /etc/hosts file)
host ibm                                                                Resolve ibm to ip address (from /etc/hosts file)
hostname ibm                                      To change the host name to ibm
entstat en0                                            To the status of ethernet device en0
entstat -d en0                                       To list the detailed status of device en0
no -a                                                       To list all net configurable attributes and their values
no -d thewall                                         To change thewall parameter to its default value
no -o ipforwarding=1                          To make the machine as router in tcpip networks
traceroute ibm                                      To trace the route to ibm
ping ibm                                                                To tcp ping to the machine ibm
ifconfig -a                                             To show the status of all network interfaces
ifconfig en0                                          To show the status of en0
ifconfig en0 up                                     Turns on network card en0
ifconfig en0 down                               Turns off network card en0
ifconfig en0 detach                             Removes en0 card from the network interface list
ifconfig en0 inet 194.35.52.1 netmask 255.255.255.0 up         
                                                                Configure en0 starts immediately
ifconfig en0 alias 195.60.60.1          Create alias ip address for en0
route add 0 192.100.13.7                  To make 192.100.13.7 as default gateway for entire network
route add 192.100.12.0  192.100.13.7    To make 13.7 as gateway for 12.0 network
route -f                                                   To clear the gateway table
chdev -l inet0 -a hostname=si           To change the host name to si permanently
netstat -a                                               To show the state of all sockets
netstat -c                                               To show the network buffers cache
netstat -D                                              To show the net drops of packets
netstat -i                                                                To display interface statistics
netstat -r                                                                To show the routing table
netstat -rn                                              To show routing table (ip will be given instead of host names)
netstat -s                                                To show the statistics of the protocols
netstat -s -p < tcp/udp/ipv6>             To show the statistics of respective protocols


Space usage commands


du -k                                                       To list number of bytes in 1k blocks
du -l                                                        To list number of bytes in 512 bytes blocks
du -s                                                       To list only the total disk usage in the current directory
df -i                                                         To display no of free and used inodes
df -k                                                       To display diskspace in 1024 bytes format
pstat –s                                                  Page space information
dumpfs <disk>                                     shows superblock, i-node map and disk map information for the file system specified.
Ex : dumpfs /dev/hd3|more
/dev/hd3:

magic                   0x43218765      cpu type                0x0
file system type        0               file system version     0
file system size        196608          fragment size           4096
block size              4096            allocation group size   2048 (frags)
inodes/allocation grp   2048            compress                0
file system name        /tmp            volume name             /tmp
log device              0xa0003         log serial number       0xb4
file system state       1               read only               0
last update             Thu Sep 24 14:31:28 BST 1998

lsfs            Lists all filesystems
lsfs -q (fs)    Lists the file system details
mount               Lists all the mounted filesystems
mount (fs or lv)    Mounts a named filesystem
mount -a            Mounts all filesystems
mount all
mount -r -v cdrfs /dev/cd0 /cdrom        mounts cd0 drive over /cdrom
crfs -v jfs -d(lv) -m(mount point) -A yes
Will create a file system on the whole of the logical volume, adds entry into
/etc/filesystems and will create mount point directory if it does not exist.
crfs -v jfs -g(vg) -m(mount point) -a size=(size of fs) -A yes
Will create a logical volume on the volume group and create the file system on
the logical volume. All at the size stated. Will add entry into
/etc/filesystems and will create the mount point directory if it does not exist.



Backup commands

mksysb -i -X /dev/rmt0                      Creates image.data and system backup (-X expands /tmp if required)
mksysb -m /dev/rmt0                         Creates image.data file with map file and system backup
mksysb -e /dev/rmt0                           Creates system data but excludes the files listed in /etc/exclude.rootvg
mkszfile                                                 Creates /image.data file
mkcd -d /dev/cd1                                                Creates system boot backup to the CD-R device /dev/cd1
mkcd -d /dev/cd1 -v vg00                 Creates  backup of vg vg00 to CD-R device /dev/cd1
mkcd -d /dev/cd1 -G                           Creates  generic boot backup
savevg -i -f /dev/rmt0 vg00               Creates vg00.data image file and backup vg vg00
savevg -ef  /dev/rmt0 vg00                               Creates vg00 backup but excludes files listed in the /etc/exclude.vg00
find / -print | backup -ivf /dev/rmt0 Backup entire system to rmt0
backup -0vf /dev/rmt0 /home          Backup /home directory to rmt0 with backup level 0
restore -Tvf /dev/rmt0                        List the archive in rmt0
restore -xvf /dev/rmt0 /home            Restore /home from archive in device rmt0
find ./home -print |cpio -ocvumB > /dev/rmt0
Archives /home directory
cpio -icvdumB < /dev/rmt0               Restores cpio archive from rmt0
cpio -ivt < /dev/rmt0                           List the contents of cpio archive from rmt0
cpio -icvd < /dev/rmt0 /home           Restores /home directory from rmt0
tar -cvf /dev/rmt0                /home                   Archives /home to rmt0 device
tar -tvf /dev/rmt0                                                List the archives in rmt0
tar -xvf /dev/rmt0 /home                   Extract /home from rmt0
dd if=si of=si1 conv=ebcdic              Convert and copy ascii file si to ebcdic si1
dd if=/dev/rmt0 ibs=512 obs=1024 of=/dev/rmt1
                                                                To copy blocks from rmt0 with 512 blocks to rmt1 with 1024 blocks
tctl -f /dev/rmt0 rewind                      To rewind the tape
tctl -f /dev/rmt0 offline                      To eject the tape
tctl -f /dev/rmt0 status                        To show the status of tape
chdev -l rmt0 -a block_size=512      To change the block size of the tape to 512

Print commands

qchk -q                                                  To display the default q
qchk -P lp0                                            To display the status of the printer lp0
qchk -# 123                                          To display the status of job number 123
qchk -A                                                  To display the status of all queues
qcan -x 123                                          To cancel the print job 123
qcan -X -P lp0                                      To cancel all jobs submitted to lp0
qpri -#570 -a 25                                   To change the priority of the job to 25
qhld # 569                                             To hold the  job 569
qhld -r -#569                                         To remove holding from 569
qmov -m lpa -#11                               To move the job 11 to queue lpa
enable psq                                             To enable queue psq
disable psq                                            To disable queue psq
cancel -#111                                         To cancel job 111
lpstat                                                      To display the status all queues
lpstat -p lp0                                           To display the status of print queue lp0
lpstat -u root                                         To display the jobs submitted by user root
lpq -P lp0                                               To display the status of queue lp0


last                                                          To list all the records in the /var/adm/wtmp file
last |grep shutdown                             To show the shutdown sessions
uptime   (w -u )                                     To show how long the system has been up

splp (device)                                          Displays/changes printer driver settings
splp /dev/lp0
export $LPDEST="pqname"             Set default printer queue for login session
lsvirprt                                     Lists/changes virtual printer attributes.
rmvirprt -q queuename -d queuedevice        Removes a virtual printer
qpri -#(job No) -a(new priority)            Change a queue job priority.
qhld -#(job No)                                    Put a hold on hold
qhld -r #(job No)                                  Release a held job

Licensing commands


oslevel                                                    To list the operating system level
lslicense                                                 To see the number of license
chlicense -u30                                      To change the fixed user license to 30
chlicense -f  on                                     To enable floating user license


User commands
id                                                             To list all system identifications for current user
id -gn                                                      To list the default group for current user
id -Gn                                                     To list all system groups for current user
lsuser root                                              To list the attribute of user root
lsuser ALL                                             To list the attributes of all users
lsuser -a HOME ALL                          To list the home directory of all users
lsuser -a ALL                                           To list all usernames
lsuser -a auth1 auth2 ALL                    To list the authentication method for all users
lsuser -a expires ALL                             To list expiry date
lsuser -a account_locked ALL             To check account lock status of all users
chsec -f /etc/security/user -a account_locked=false -s user
chuser -a login=true san                        To enable the user san
chuser -a rlogin=true san                        Enable san to login remotely
chuser  maxexpired = -1 <User Name>     Passwor never expairs for user}
mkuser si                                                  Creates user si with default values in /usr/lib/security/mkuser.defalault
mkuser su=false   si                                 Create user si without su facility
rmuser si                                                   To remove user si
rmuser -p si                                               To remove user si and his all attributes
who                                                            List users with tty nos and ip numbers
who /var/adm/wtmp                               Lists history of login logout system startup and shutdowns
who -r                                                         To list the run level
who am i /who -m                                   To list the current user
mkgroup dcm                                           To create the group dcm
chgroup users=u1,u2,u3 dcm                To add users u1 u2 and u3 to dcm  group
rmgroup dcm                                            To delete the group dcm
chauthent                                                  To change the authentication methods
 
Force a user to change their password on their next login:
pwdadm -f ADMCHG username
Note that this works with some sshd's and not others

Subsystem Commands
lssrc -a                                                    To list the status of all subsystems
lssrc -h node1 -a                                   To list the status of all subsystems  on foreign host node1
lssrc -s kadmind                                   To list the status of the subsystem kadmind
lssrc -g tcpip                                          To get the status of the subsystem group tcpip
mkssys                                                   To add a subsystem
rmssys -s kerberos                               To remove the subsystem kerberos
chssys -s kerb -s kad                           To rename the subsystem kerb to kad
startsrc -s kadmin                                To start the subsystem kadmin
startsrc -g tcpip                                     To start the subsystem group tcpip
stopsrc -s kadmin                                                To stop the subsystem kadmin
stopsrc -g tcpip                                     To stop the subsystem group tcpip
refresh -s nfsd                                       To refresh nfsd subsystem
refresh -g tcpip                                     To refresh tcpip subsystem group


Scheduling commands
crontab -l                                               To list the crontab entries
crontab -e                                              To edit the crontab entries
crontab -l > /si                                      To copies the entries of crontab to /si file
crontab -r                                              To remove all crontab entries
crontab -v                                             To list the submission time
/var/adm/cron/cron.allow                  File containing users who allowed cron service
/var/adm/cron/cron.deny                  File containing users denied cron service
at -l                                                         To list the jobs scheduled via at command
at -r  root.dfjdhjdh.21                         To remove the scheduled job root.dfjdhjdh.21
/var/adm/cron/at.allow                      File containing users who allowed at service
/var/adm/cron/at.deny                       File containing users denied at service
batch                                                      To run the command when the system load permits
atq  joe                                                  To list all the jobs submitted by user joe


ODM Commands

odmget sm_menu_opt                     
To get the objects from class sm_menu_opt
odmget -q "id=licenses" sm_menu_opt
                                To list objects that matches query id=licenses from object sm_menu_opt
odmdelete -o sm_menu_opt -q "id=licenses"
                                To delete the entries from class sm_menu_opt which agrees the query id=licenses
odmshow sm_menu_opt
                                To show the object class definition
odmdrop -o sm_menu_opt
                                To drop sm_menu_opt object class
odmchange -o sm_menu_opt -q "id=licenses" file1
                                To change the attributes from file1