31 May 2013

Vi editor commands to edit files

AIX Text Editor (Vi Editor) Commands

  • Esc To switch between insert or command mode
  • Insert mode
    • a Insert text after the cursor
    • i Insert text before the cursor
    • I Insert text of the top of the line
    • A Insert text of the bottom of the line
    • x Supress a character
    • o Insert text in the next line
    • O insert text in the previous line
    • r Replace the current character
    • R Edit the current line in typeover
    • cc Change line
    • cw Change word
    • C Change from current position to the end of line
    • dw Delete a word from the cursor position
    • dd Delete the line and place to the buffer
    • yy Copy line in the buffer
    • p Copy the content of the buffer after the current line
    • P Copy the content of the buffer before the current line

  • Position command
    • l Go  right
    • h Go left
    • k Go  up
    • j Go down
    • b Go a word left
    • w Go a word right
    • $ Go to the end of the line
    • O Go to the top of the line
    • :24 Go to  line 24
    • gg or 1G  Go to the first line of the document
    • G Go the last line of the document
  • Global Comand
    • / Search string
    • :1,$s/a/b/g Replace character b from a, from the 1st line to the end of a file
    • :r Insert a file at the position of the cursor
    • :q!  Quit without saving a fle
    • :w  Write  a file
    • :wq Write and quit a file

28 May 2013

Troubleshooting booting problems in AIX

Display information about volume groups
  • lsvg -l rootvg
Display if a hard drive is bootable
  • ipl_varyon -i
Display and alters the list of boot devices available to the system
  • bootlist -m normal hdisk0
 Create boot image
  • bosboot -ad /dev/hdisk0
Create boot image, the boot record, and the service record
  • mkboot -a -d /dev/hdisk0
Changes the characteristics of physical volume in a volume group
  • chpv -c hdisk0
Synchronizes or rebuilds the logical volume control block
  • synclvodm rootvg hd5
See detailled information about a volume
  • lqueryvg -Avtp hdisk0
Display attribute characteristics and possible values of attributes for devices
  • lsaltr -El hdisk90

Recreating the boot logical volume

After booting from CD, tape or NIM an Installation and Maintenance Menu  is shown and you can startup the maintenance mode. After accessing the  rootvg, you can repair the boot logical volume with the bosboot  command. You need to specify the corresponding disk device, for example  hdisk0: 

bosboot -ad /dev/hdisk0

It is important that you do a proper shutdown. All changes need to be  written from memory to disk. The bosboot command requires that the boot  logical volume (hd5) exists. 

If you ever need to re-create the BLV from scratch, maybe it had been  deleted by mistake or the LVCB of hd5 has been damaged, the following  steps should be followed: 

1. Boot your machine in maintenance mode (from CD or tape (F5 or 5) or  use (F1 or 1) to access the Systems Management Services (SMS) to select boot device).

2. Remove the old hd5 logical volume.

# rmlv hd5 

3. Clear the boot record at the beginning of the disk.

# chpv -c hdisk0

4. Create a new hd5 logical volume: one physical partition in size, must be in rootvg and outer edge as intrapolicy. Specify boot as logical   volume type.

# mklv -y hd5 -t boot -a e rootvg 1 

5. Run the bosboot command as described on the visual.

# bosboot -ad /dev/hdisk0

6. Check the actual boot list.

# bootlist -m normal -o 

7. Write data immediately to disk.

# sync
# sync

Boot an AIX from NIM and HMC - boot problem

  • Define the machine on NIM
  • smitty NIM
    • Perform NIM Adimistration Tasks
    • Manage Machines
    • Define a machine
      • NIM Machine Name (machine name)
      • Machine Type (standalone)
      • Hardware Platform Type (chrp)
      • Cable Type (bnc)
      • NIM Network (Nim network Name)
      • Host Name (host name)
      • Network Adapter Hardware (Network Adapter Adress)
        • The network adress can be found booting in SMS Mode -Setup Remote IPL
    • Perform NIM AdministrationTasks
    • Manage Machines
    • Perform Operations on Machines
    • Machine name
    • maint_boot = enable a machine to boot in maintenance mode
    • SPOT (spot name)
  • Boot from HMC in maintenance Mode
    • In advanced option boot on SMS
    • Choose open a terminal
      • 5. Select Boot Options
      • 1. Select Instal/Boot device
      • 6. Network
      • 1. Virtual Ethernet
      • 3. Normal Mode Boot
      • 1. Access a Root Volume Group
      • 2) Volume Group....
      • 2) Access this Volume Group and start a shell before mounting filesystems
      • Also you can make some intervention on disk
        • fsck -y /dev/hd1
        • mount /dev/hd1

Utilities to manage Files and Directories

AIX Commands for Managing files and directories

  • cd Change directory
  • ls Display the content of a directory
      • ls -la Display the content of a library long format
      • ls -latr Display the content of a library in chronogical order
  • cat Display, create, copy, concat a file
    • cat file.input Display file.input
    • cat file1.input file2.input > file.outpout Concat file1 et file2
  • more Display each page of a file
  • cp  Copy files or directories
  • mv Move or rename file
  • grep Search a string in a file
    • grep -r "text" /tmp Search the string text in the /tmp directory
  • wc Count word, line in a file
  • ln Make a hard or soft link of a file
  • touch Create an empty file
  • find Find a file
    • find . -name "text.txt" Find the file text.txt
    • find . -name "*.txt" | xargs -n1 ls -la Find the files *.txt if there is too many occurences 
    • find . -name "text*" | xargs rm Find all the file with the argument text* and remove it
    •  find . -type f -mtime +10 | xargs -n1 rm Find all files older than 10 days and remove it
  • chmod Modify the permission of a file or directory
    • chmod ugo+rwx Set the permission for user - group - other + Read - Write - execute
  • chown Change the owner of a file or directory
    • chown user file
  • chgrp Change the group of a file or directory
    • chgrp group file
  • cut Cut certain colonn of a file
  • head Display the head of a file
  • sdiff Display the difference between two files
  • sort Sort the content of a file
  • tail Display the last lines of a file
    • tail -f /var/log/error.log Display in "real time" the content of a log file
  • mkdir Make a directory
  • rmdir Remove a directory
  • nl Number lines in a file
    • nl -ba file.txt

AIX utlitites - Transforming and converting files

 Here are listed some "utilities" with example to transform files.
  • tr
    • tr '\332' '012'< file.input > file.output To transform character 'DA' (hex) to '0A' (hex). The value 332 and 012 are in octal
    • tr -d '\025' < file.input > file.output To delete the character '15' (hex). The value 025 are in octal
    • tr 'A-Z' 'a-z' < file.input > file.output To transform upercase to lowercase
    • tr 'àçéèêëîïôöùüÂÇÉÈÊËÎÏÔÖÙÜ' 'aceeeeiioouuACEEEEIIOOUU' < file.input > file.output
  • sed
    • sed
  • perl
    • perl -pe 's/\332/\012/g' < file.input > file.output To transform character 'DA' (hex) to '0A' (hex). The value 332 and 012 are in octal
    • perl -pe 's/\332/\015\012/g' < file.input > file.output To transform character 'DA' (hex) to '0D0A' (hex. Thel value 332, 015 and 012 are in octal.
    • perl -n -e 'chop; printf "%-120s\n",$_;'  < file.input > file.output To transform a file with a Carriage Return at the position 120
    • perl -e '1,2d' < file.input > file.output To suppress the first two line of a file
    • perl -e 'while (read(STDIN, $l, 160)){printf "%s\n",$l;}' < file.input >file.output To add a carriage return at the position 160
  • iconv To convert from one encoding to another encoding
      • iconv -f ISO8859-1 -t IBM-850 file.input > file.output To convert file from ISO8859-1 to IBM-850 encoding
  • awk
    • ls -la * | tail -1 | awk '{print $9}' To display information of the colon 9 in a ls command
    • ls -ltr | grep "Jan 24" | awk '{print $9}' | xargs -n1 -i cp {} /work/toto/
  • dd
    • dd if=/tmp/file.input of=/tmp/file.output conv=ascii To convert input file from bin to ascii
  • Sript to transform "dos file" to Unix (in particular ^M)
    • #!/usr/bin/ksh

      if [ $# -ne 1 ]
      echo "Usage: $0 filename"

      sed 's/^M$//' $1 > tmp
      mv tmp $1
      chmod 755 $1
  • Tips to transform Dos file to Unix
    • # to convert DOS file to Unix in place:
      • perl -i -pe 's/\r//g' file
    • # Unix to DOS:
      • perl -pe 's/$/\r/g' < infile > outfile
    • # Unix to DOS in place:
      • perl -i -pe 's/\n/\r\n/' file
    • # to check for <CR> :
      • perl -ne 'print if /\r/' < infile

25 May 2013

Compressing and Archiving files in AIX Operating System

Some AIX basic commands

  • who Display the connected users
  • whoami Display the current user connected
  • man Display manual of a command
    • man ls
  • df Display information about total space and available space on a file system
  • du Display the file space usage
  • chfs Change attributes of a file system
    • chfs -a size=+500M /usr
  • su Change the current user connected
    • su - user
  • lp Sent a file to the spooler
  • lpr Sent a file to the spooler
  • wget  Wget is a free utility for non-interactive download of files from the Web.
    • wget -b ftp://ftp.arcudi.org/file.tar.gz Download the file.tar.gz in backgroup
  • lastreboot See when the system is rebooted the last time

AIX Compress and Archive Commands

  • gzip Compress a file
    • gzip file.tar Create a compressed file file.tar.gz
    • gzip -d Unpack a *.gz file Uncompress a file.tar.gz file
    • tar cvf - directory/ | gzip > toto.tar.gz Create a compressed tar file in a single command
  • zip Compress a file
  • tar  Archive a file
    • tar -tvf file Verify the content of a tar file
    • tar -xvf file Unpack a tar file
    • tar -c file repertory Create a tar file
    • tar -cvfX file.tar exclude.txt /tmp/toto/ Create a tar file exluding directories that are present in the exclude.txt file
    • tar cvf - directory/ | gzip > toto.tar.gz Create a compressed tar file in a single command
  • history See the last command entered
  • nl Number lines in a file
    • nl -ba file.txt
  • lssrc See the status of a subsystem
    • lssrc -ls dhcpsd

23 May 2013

How to list open files in AIX Operating System

Listing AIX Open Files


lsof is a useful command to list open files. When lsof is called without parameters, it will show all the files opened by any processes. Below are listed with some examples the use of lsof

To See which process use a library 
    • lsof /dir  
Show what files are opened by processes whose names starts by "s" (smb...).
  •   lsof -c s
  •   lsof -c smb
 Show what files are opened by processes whose names starts by "smb", but exclude those whose owner is the user "toto":
  • lsof -c courier -u ^toto
 Show the processes opened by user toto :
  • lsof -u toto
 Show what files are using the process (PID 86397):
  • lsof +p 86397
 Search for all opened instances of directory /tmp and all the files and directories it contains:
  • lsof +D /tmp
 List all opened internet sockets and sockets related to port 80:
  • lsof -i
  • lsof -i :80
 List all opened Internet and UNIX domain files:
  • lsof -i -U
 Show what process(es) has an connection opened to or from the host www.arcudi.org :
 Useful link to lsof :

22 May 2013

User profiles administration commands

AIX User administration commands

  • mkuser Creates a new user
    • smitty mkuser
  • passwd Creates or changes the password of a user
  • chuser Changes user attributes (except password)
  • lsuser Lists user attributes
  • rmuser Removes a user and its attributes
  • chsec Changes security related stanzas
  • login Initiates a user session
  • who Identifies the users currently logged in
  • dtconfig Enables or disables the desktop autostart feature

AIX User administration files

  • /etc/security/environ Contains the environment attributes for users
  • /etc/security/lastlog Contains the last login attributes for users
  • /etc/security/limits Contains process resource limits for users
  • /etc/security/user Contains extended attributes for users
  • /usr/lib/security/mkuser.default Contains the default attributes for new users
  • /usr/lib/security/mkuser.sys Customizes new user accounts
  • /etc/passwd Contains the basic attributes of users
  • /etc/security/passwd Contains password information
  • /etc/security/login.cfg Contains configuration information for login and user authentication
  • /etc/utmp Contains the record of users logged into the system
  • /var/adm/wtmp Contains connect time accounting records
  • /etc/security/failedlogin Records all failed login attempts
  • /etc/motd Contains the message to be displayed every time a user logs in to the system
  • /etc/environment Specifies the basic environment for all processes
  • /etc/profile Specifies additional environment settings for all users
  • $HOME/.profile Specifies environment settings for specific user needs
  • /etc/group Contains the basic attributes of groups
  • /etc/security/group Contains the extended attributes of groups

19 May 2013

System and Software Maintenance commands

The following AIX performance tools provide general information and metrics related to performance.

CPU Monitoringvmstat, iostat, topas, sar, time/timex
Memory Montiroingvmstat, topas, ps, lsps, ipcs
I/O Subsystemvmstat, topas, iostat, lvmstat, lsps, lsatt/lsdev, lspv/lsvg/lslv
Networknetstat, topas, atmstat, entstat, tokstat, fddistat, nfsstat, ifconfig
Processes ps, pstat, topas

AIX System information

  • prtconf | more Print system information
  • lstattr -EL -l sys0 To display system level attribute
  • lsattr -El sys0 -realmem Display amout of ram
  • lsattr -l rmt0 -E To list the current values of the attributes for the tape device, rmt0
  • lscfg Detailled configuration of my system
    • lscfg | grep proc Display number of processor
  • oslevel Returns the major level of the OS
    • oslevel -r Returns the detailled level of the OS
    • oslevel -s To see which service pack is currently installed
  • uname -a Type of the machine
  • unmae -uM Type of the machine and serial number
  • oslevel Reports the latest installed maintenance level of the system (VIO)
  • lspv To display the number of hard disks on your system
    • lspv hdisk1 To find details about hdisk1
  • lsconf To document the machine
  • bootinfo Reports some system information
    • bootinfo -r How much memory does machine have
    • bootinfo -y Display if the hardware is 32 or 64 bit

Software packaging and Maintenance Level

  • oslevel
    • oslevel -q (List filesets of known technology)
    • oslevel -r (Applies all flags to tehnology levels)
    • oslevel -sq (List all know service pack)
  • installp to install additional software or PTF (Program Temporary Fix)
  • instfix to list, update or update an individual fix
    • instfix -i | grep ML Show what fileset are found for maintenance release and if they are complete
    • insfix -ik <fix> Show if a particular fix is installed on the system
  • lslpp to view the maintenance level
    • lslpp -l
    • lslpp -l <fileset> to see information about a fileset (fileset -l bos.iconv.ucs.com)
  • lppchk -v Show fileset that are incompletly installed
  • lscfg -vp | grep alterable Show firmware level

Monitoring and system performance

  • Nagios  an open source program to monitor all your systems
  • topas to see in "real time" system stats (CPU, IO etc...)
  • nmon a free tool to analyse AIX and Linux performance
  • iostat Reports CPU and I/O statistics
  • vmstat Reports virtual-memory activity and other system statistics
  • netstat Displays the contents of network-related data structures
  • ps Displays the status of processes
  • lsattr Displays the attributes of devices
  • lslv Displays information about a logical volume or the logical volume allocations of a physical volume
  • nfsstat Displays statistics about Network File System (NFS) and Remote Procedure Call (RPC) activity
  • nice Runs a command at higher- or lower-than-normal priority
  • no Displays or sets network options
  • renice Changes the priority of one or more processes
  • reorgvg Reorganizes the physical-partition allocation within a volume group
  • sar Collects and reports or records system-activity information
  • schedtune Sets parameters for CPU scheduler and Virtual Memory Manager processing
  • svmon Captures and analyzes a snapshot of virtual memory
  • time Prints the elapsed execution time and the user and system processing time attributed to a command
  • tprof Reports CPU usage for individual programs and the whole system
  • trace Records and reports selected system events
  • filemon To find out the busy filesystems and files

17 May 2013

Troubleshooting hardware issues in AIX Operating System

Use the below commands to troubleshoot any hardware related issues in AIX operating system. The most frequently used command by many AIX adminisrators to find any hardware related issues in the errpt command. errpt command will reprort all  the hardware errors in that system.
  • lsdev Displays devices on the system and their characteristics
    • lsdev -Cc adapter Display information about adapter
    • lsdev -Cc disk Display information about disk
    • lsdev -c | grep ent Display information about netwok adaptater
  • lsvg Diplays information on a volume group
    • lsvg -o Displays volume group active
    • lsvg -l rootvg Displays the status of disks
  • lspv Displays information about a physical volume within a volume group
    • lspv hdisk0
  • mkvg Creates a volume group
    • mkvg -y datavg hdisk1 hdisk2
  • lsfs Displays the filesystems and their characteristics
  • lsattr Displays information about the attributes of a given device
    • lsattr -El sys0 -a realmem (amount of ram)
  • cfgmgr command is used to onfigure devices and, optionally, install device software into the system
  • mkdev To create a new device
    • mkdev -vadapter vhost2 -vdev hdisk17 -dev disk17_data
  • rmdev To delete a device
    • rmdev -d1 scraid1 To delete scraid1 device
    • rmdev -l pdisk8 To change the device state from Available to Defined
    • rmdev -l pdisk8 -d To delete pdisk8 device
  • fsck To make a file check after a disk problem
    • fsck -y /dev/fslv00 Check disk without prompting
  • lsmcode Displays microcode and firmware levels of the systemTo make a file check after a disk problem
  • fuser Identifies processes using a file or a file structure
    • fuser /etc/passwd
    • fuser -c /home/ See all the PID using the ressource
  • lsvgfs Display a list of file systems belonging to a volume group
    • lsvgfs rootvg      

      Diagnosing Hardware Problems in AIX

    • errpt command to retrieve an error record from the error log (errpt -a)
  • errclear to delete entries from the error log (errclear -0)
  • diag command is the starting point to run a wide choice of tasks and service aids that are used to perform hardware problem determination
  • To log system messages, AIX uses syslogd. The syslogd daemon reads a atagram socket and sends each message line to a destination described by the /etc/syslog.conf configuration file.
    • to start it use startsrc -s syslogd
    • to stop it use stopsrc -s syslogd
    • to see if the service is running use ps -ef | grep syslogd 
  • snap To make an image for the system configuration for the support
    • snap -r To supress the old snap
    • snap -gc To create a snap for the support

15 May 2013

Working with Vi editor in AIX

The visual (Vi) editor is a screen editor that comes with the AIX operating system. The vi program is used to create and edit text files. Initially, the editor is in command mode. Vi is based on the ex line editor, but unlike ex, vi will allow you to use the arror keys if you are using (or emulating) a terminal that provides support for them. If your terminal does not support the full screen mode (eg. using TELNET from the IBM 4381), you may still edit text by issuing the appropriate commands.

When you edit a file, vi makes a copy of the file to a memory buffer. This way, if any unwanted changes are made, the original file is not destroyed. When your work is completeed, you must remeber to save the buffer which contains your changes. The visual editor has two modes of operation: text input mode and command mode.

The vi editor can be executed by issuing the command:

         vi [-l] [-R] [+n | +/pattern] [filename]
where filename is the name of the file to be edited or created, n is the line number on which to start the display, and pattern is a string specifying which line on which to start. You will then be placed in command mode. The -l option tells vi to create indents appropriate for LISP code. Passing the -R option tells vi to open the file read-only -- the same as if the view command was used. When editing a file, vi places a tilde (~) as the first character of lines past the end of your file. These lines are not part of your file, and are for display purposes only.

Using vi Editor

Moving the Cursor

There are over forty commands that can be used to move the cursor throughout the file. The table below will show some of the more common key sequences and their actions on the cursor. To repeat a command, type the number of times the command is to be performed and then press the command key sequence.

    Key               Action               Key                Action
h or [Left Arrow]  Left one character   l or [Right Arrow]   Right one character
j or [Down Arrow]  Down one line        k or [Up Arrow]      Up one character

^    1st character on current line           $  End of current line
0    1st position of current line            G  Last line of the file
+    1st character of next line             :n  Line n of the file
-    1st character of previous line          H  Top line of screen
nH   n lines after top line                  M  Middle line of screen
nL   n lines before last line                L  Last line of screen

B  Back one word (ignore punctuation)        b Back one word
E  End of next word (ignore punctuation)     e End of next word
W  Start of next word (ignore punctuation)   w Start of next word
(  Beginning of previous sentence            ) Beginning of next sentence
[[ Back one section                         ]] Forward one section
{  Beginning of previous paragraph           } Beginning of next paragraph

[CTRL][B]   Scroll back one screen      [CTRL][F] Scroll forward one screen
[CTRL][U]   Scroll back half screen     [CTRL][D] Scroll forward half screen
[CTRL][E]   Scroll up one line          [CTRL][Y] Scroll down one line

Marking Text and Returning

Facilities are provided for placing a mark within a line of text. You can then move the cursor to that mark with a few simple keystrokes. To place a mark at the current cursor position, use the m command followed by a single, lowercase letter. This letter will be the mark placed in the line. Later when you wish to return to the mark, enter the ` command followed by the mark character. To go to the beginning of the line which contains the mark, use the ' command followed by the mark character. If you moved a block of text, you can return to the previous mark by issuing the " command.

Text Input Mode

Text input mode can be used to enter and delete new text in your file. Below is a table showing the various key sequences to place you into text input mode as well as those to return to command mode and perform operation while in text input mode. When you are in text input mode, everything you type will be placed into your document until you press the [ESC] key.
Key        Action                       Key       Action
a          Insert after cursor        A           Append to end of line
i          Insert before cursor       I           Insert at beginning of line
o          Insert line below cursor   O           Insert one line above cursor
[CTRL][J]  Move down one line         [CTRL][W]   Move back one word
[ENTER]    Add a new line             [Backspace] Move back one character
kill       Delete line (set by stty)  [CTRL][H]   Move back one character
[CTRL][I]  Insert a tab               [CTRL][T]   Move to next tab setting
[ESC]      Returns to command mode    [CTRL][V]   Quote next character

Deleting and Changing text

These commands let you change or delete the text that is currently in your file. Each command can be repeated by entering the number of times the command is to be performed before entering the command. The table below shows some of the more common editing commands:
Key  Action                          Key  Action
cw   Change word                     cc   Change line
C    Change text from current        cl   change character right of cursor
     position to end of line         .    Repeat last change
dd   Delete current line             ndd  Delete n lines
D    Delete remainder of line        dw   Delete a word
d}   Delete to next paragraph        d^   Delete back to beginning of line
dh   Delete char left                d/pattern  Delete up to pattern
dn   Delete up to pattern            dL   Delete up to last line on screen
dfa  Delete up to and                dta  Delete up to a
     including a
dG   Delete to end of file           ~  Reverse case
p    Inserts last deleted text       P  Inserts last deleted text before cursor
     after cursor
rx   Replaces character with x       Rtext   Replaces text beginning at cursor
s    Substitute character            S  Substitute entire line
x    Delete current cursor position  X  Delete back one character

Moving and Copying Text

You can also move and copy text within a file by use of a temporary buffer in vi. When you issue one of the deletion commands mentioned in the previous section, vi places the deleted text in a temporary buffer. You can then place that text after or before cursor position by issuing the p or P command respectively. Sometimes, however, you want to copy the text to a new location. To save you from having to delete the text and put it back from where it was deleted, vi provided a series of text moving functions.
Pressing Y or yy will copy the current line to the buffer. The y]] command will copy the text up to the next section heading. You can also copy to the end of a word by using the ye command.

The vi editor also provides a series of numbered buffers that you can use for storing multiple selections of text. To use these buffers, type a " followed by the buffer number before the yy, d, or p commands. This will respectively yank the current line, delete the character, and put the contents of the specified buffer into the file. Since buffer one is used by vi for normal deletion, you may wish to use a safer buffer when moving or copying text. This can be done by using a lower case letter as the buffer number. As an example, to yank the next 3 lines of text and place them in buffer r you would type:


Searching for Text

The vi editor also provides an extensive set of search commands while in command mode. You can search forwards and backwards for a specific character by using the f and F commands respectively. The character for which you are searching should be specified after the search command. You can repeat the last character search by pressing the ; key. Pressing the , will reverse the search direction for character searches.
If you are programming in LISP or writing equations, you may find it useful to match your parenthesis and brackets. This can be done in vi by use of the % command. This command will find the match for the current brace, bracket, or parenthesis.

You can also search for a text string by placing a / in front of the text for which you are searching. The vi editor will then place the cursor at the first location after the cursor of the specified text. To search backwards from the cursor, use the ? instead of a /. You can repeat the previous search by pressing n, repeat the search in the opposite direction with the N command, repeat the forward search with the / command, and using ? will repeat the previous backwards search command.

Aligning Text You can tell vi to shift your text 8 spaces to the right or left by use of the > > and < < commands respectively. If you wish to shift your text from the current line to the end of the screen, use the > L and < L commands. You can also join two lines by using the J command. This command will place the next line at the end of the current line, wrapping the text to the next line as necessary. If you want to break up a line into two or more lines, place the cursor at the position where the line is to be broken, and insert a carriage return ([ENTER]).

Undoing Changes

Sometimes you will make a change and then immediately wish you could undo it. Such a wish is possible with vi. To undo an action, you must be in command mode. Pressing u will undo the last command entered. Pressing U, will cause vi to undo all the changes made to the current line.

Saving and Leaving vi

There are several ways to quit vi both with and without saving your file. Each of these commands should be entered in the command mode. If you wish to save your file and continue working, use the :w command. If you have not given your file a name you should do so by specifying the filename after the :f command. Then you can use :w to save the file. If you want to save the file under a different name, you can specify it after the :w command. Specifying an ! after the :W command will force vi to overwrite an existing file if the changed name represents a file that already exists. You can also write specific lines to a file by specifying the start and ending line numbers (separated by a comma) between the : and the w. For example, the command 
      :3,25w partial.file 
will save lines 3 through 25 to the partial.file file.
If you want to save your work and exit the editor, you can do that by issuing the ZZ or the :wq command. If you wish to quit vi without saving and you have not made any changes to the file, you can use the :q command. If you have made changes to the file, but you wish to exit vi without saving them, use the :q! command.

Using ex Commands

The vi editor is the open/visual mode of the ex editor. Therefore, when using vi, you can easily switch to ex's command mode. The ex editor provides some commands which are unavailable in vi. For example, the commands to perform global search and replace operations. To get a list of ex commands, please see the appropriate man pages. To switch to ex while you are editing a file, press Q. This will place you in ex's command mode. When you wish to quit ex and return to vi, type the vi command.

Editing Multiple Files

The vi editor provides facilities for editing several files. To edit a new file while in vi, enter the :e command followed by the name of the file. The current file becomes the alternate file if no changes have been made, otherwise, the new file becomes the alternate file. To switch to the alternate file, enter the command :e # or press [CTRL] [A] . If you wish to discard the changes in the current file and reload the last saved version, issue the :e! command. You can also specify the line on which to start editing by specifying a + followed by a line number between the :e command and the filename.
You can make a list of files to edit by placing each filename after the :n command. To edit the next file in the list, issue the :n command.

Including Text from Files and Command Output

It is also possible to insert a file into the current file. The editor will place the new file after the cursor. To insert the file, use the :r command followed by the name of the file to be inserted. The editor also lets you insert the output of an AIX command into your document. To do this, issue the :r ! command followed by the name of the AIX command to run. You can also specify which line of the output to start including by placing it between the : and the r.

vi Editor Tips

  • You can suspend the process running vi by pressing [CTRL] [Z] . This will bring you back to your OS prompt. To return to vi, make the process the foreground process with the fg command.
  • You can issue AIX commands from within vi by typing :! followed by the command.
  • You can create a subshell by issuing the :sh command. When you are done, press [CTRL] [D] or type EXIT [ENTER] to return to vi.
  • You can move the cursor to a specific column by specifying the column number and then the vertical bar ( | ) character.
  • You can set the column position for vi to wrap the text by setting the wrap margin variable. For example, to set the warp at column 65 you would enter the command :set wm=15 where 15 is 80 - desired column position.

12 May 2013

Using cp, mv, cat and rm commands in AIX

You can use the regular commands which we generally use in any UNIX platforms to access files or directories in AIX aswell. Use cp command to copy the files from one directory to another directory and similarly use mv command to move the files from one directory to another directory. Also use cat, pg and more commands to read a file and use rm command to delete a file or directory.

Commands used to manage AIX Files and Directories are

cp Command


To Copy a File to another File

cp [ -f ] [ -h ] [ -i ] [ -p ][ -- ] SourceFile TargetFile

To Copy a File to a Directory

cp [ -f ] [ -h ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory

To Copy a Directory to a Directory

cp [ -f ] [ -h ] [ -i ] [ -p ] [ -- ] { -r | -R } SourceDirectory TargetDirectory


The cp command copies the source file specified by the SourceFile parameter to the destination file specified by the TargetFile parameter. If the target file exists, cp overwrites the contents, but the mode, owner, and group associated with it are not changed.

When using the cp command, if the file specified as the target file already exists, then the copy operation will write over the original contents of the file without warning. To avoid this use cp -i (interactive copy). If you are copying more than one file in one operation, then the specified target must be a directory. If the target is a directory, the copies will have the same file names as the original. cp -R can be used to recursively copy all files, subdirectories, and the files in those subdirectories to a new directory. For example, cp -R /home/team01/mydir /home/team01/newdir

To make a copy of a file in the current directory, enter:

     cp prog.c prog.bak
This copies prog.c to prog.bak. If the prog.bak file does not already      exist, the cp command creates it. If it does exist, the cp command replaces  it with a copy of the prog.c file. 

mv Command


To Move Files to a Directory Maintaining Original File Names

mv [ -i | -f ] SourceFile TargetFile

To Move and Rename a File or Directory

mv [ -i | -f ] SourceFile ... TargetDirectory


    Attention: The mv command can overwrite many existing files unless you     specify the -i flag. The -i flag prompts you to confirm before it overwrites     a file. If both the -f and -i flags are specified in combination, the last     flag specified takes precedence.

The mv command moves files and directories from one directory to another or renames a file or directory. If you move a file or directory to a new directory, it retains the base file name. When you move a file, all links to other files remain intact, except when you move it to a different file system. When you move a directory into an existing directory, the directory and its contents are added under the existing directory.

When you use the mv command to rename a file or directory, the TargetDirectory parameter can specify either a new file name or a new directory path name.

  1. To rename a file, enter:

     mv appendix apndx.a

     This command renames appendix to apndx.a. If a file named apndx.a already      exists, its old contents are replaced with those of appendix.

cat Command


cat [ - q ] [ -r ] [ - s ] [ - S ] [ - u ] [ - n [ - b ] ] [ - v [ - e ] [ - t ] ] [ - | File ... ]


The cat command reads each File parameter in sequence and writes it to standard output. If you do not specify a file name, the cat command reads from standard input. You can also specify a file name of - (dash) for standard input.

    Attention: Do not redirect output to one of the input files using the     redirection symbol, > (caret). If you do this, you lose the original data in     the input file because the shell truncates the file before the cat command     can read it. See "Redirecting Input and Output in the Korn Shell" in AIX 5L     Version 5.1 System User's Guide: Operating System and Devices for more     information.


 Attention: Do not redirect output to one of the input files using the     redirection symbol, > (caret).

  1. To display a file at the workstation, enter:

     cat notes

     This command displays the data in the notes file. If the file is more than  one less than the number of available display lines, some of the file      scrolls off the screen. To list a file one page at a time, use the pg

pg and more Commands

The pg command reads the file names specified and displays the files one page at a time. Each screen is followed by a prompt. Press Enter to display the next page down. The more command works in much the same way as the pg command - it displays continuous text one screen at a time. It pauses after each screen and prints the word More at the bottom of the screen. If you press Enter, it displays an additional line. If you press the space bar, it displays another screen of text. When more is reading from a file, it displays a % with the More prompt. This provides the fraction of the file (in characters) that the more command has read.

Apart from moving down one page at a time, both the pg and the more commands support subcommands to perform other functions, for example to move up by one page with more use the b character. To move up one page with the pg command use the - (dash) character. Don't forget that with the pg command you must hit the Enter key after a subcommand, whereas with the more command the action takes place as soon as the subcommand is entered.

wc Command


wc [ -c | -m ] [ -l ] [ -w ] [ File ... ]

wc -k [ -c ] [ -l ] [ -w ] [ File ... ]


By default, the wc command counts the number of lines, words, and bytes in the files specified by the File parameter. The command writes the number of newline characters, words, and bytes to the standard output and keeps a total count for all named files.


  1. To display the line, word, and byte counts of a file, enter:

     wc chap1

     The wc command displays the number of lines, words, and bytes in the chap1   file.

ln Command


To Link a File to a File

ln [ -f ] [ -s ] SourceFile [ TargetFile ]

To Link a File or Files to a Directory

ln [ -f ] [ -s ] SourceFile ... TargetDirectory


The ln command links the file designated in the SourceFile parameter to the file designated by the TargetFile parameter or to the same file name in another directory specified by the TargetDirectory parameter. By default, the ln command creates hard links. To use the ln command to create symbolic links, designate the -s flag.

A symbolic link is an indirect pointer to a file; its directory entry contains the name of the file to which it is linked. Symbolic links may span file systems and may refer to directories. If you are linking a file to a new name, you can list only one file. If you are linking to a directory, you can list more than one file.

The TargetFile parameter is optional. If you do not designate a target file, the ln command creates a new file in your current directory. The new file inherits the name of the file designated in the SourceFile parameter.

  1. To create another link (alias) to a file, enter:

     ln  -f chap1  intro

     This links chap1 to the new name, intro. If intro does not already exist,  the file name is created. If intro does exist, the file is replaced by a  link to chap1. Then both the chap1 and intro file names will refer to the  same file. Any changes made to one also appear in the other. If one file  name is deleted with the rm command, the file is not completely deleted  since it remains under the other name.

rm Command


rm [ -f ] [ -r ] [ -R ] [ -i ] [ -e ] File ...


The rm command removes the entries for the specified File parameter from a directory. If an entry is the last link to a file, the file is then deleted. If you do not have write permission for a file and the standard input is a
terminal, you are prompted with the file name and ask to confirm that you want to delete the file. If you type a y (for yes), the file is deleted, type any other character and the file is not deleted. You do not need read or write permission for the file you want to remove. However, you must have write permission for the directory containing the file.

If the file is a symbolic link, the link is removed, but the file or directory that the symbolic link refers to remains. You do not need write permission to delete a symbolic link, if you have write permission in the directory.

The -r option permits recursive removal of directories and their contents if a directory is specified. Be careful when using this option as it does not require the directory to be empty in order for this option to work.

1. To delete a file, enter:

     rm myfile

     If there is another link to this file, then the file remains under that  name, but the name myfile is removed. If myfile is the only link, the file itself is deleted.