Site hosted by Angelfire.com: Build your free website today!

Summary of Basic vi Commands

The following table provides a convenient reference for basic vi commands.

Table 8 - Basic vi Commands

Command

Meaning

Starting vi

 

vi filename

Open or create file

vi

Open new file to be named later

vi -r filename

Recover crashed file

view filename

Open file read-only

Cursor Commands

 

h

Move left one character

j

Move down one line

k

Move up one line

l

Move right one character

w

Move right one word

W

Move right one word (past punctuation)

b

Move left one word

B

Move left one word (past punctuation)

e

Move to end of current word

Return

Move down one line

Backspace

Move left one character

Spacebar

Move right one character

H

Move to top of screen

M

Move to middle of screen

L

Move to bottom of screen

Ctrl-F

Page forward one screen

Ctrl-D

Scroll forward one-half screen

Ctrl-B

Page backward one screen

Ctrl-U

Scroll backward one-half screen

Inserting Characters and Lines

 

a

Insert characters to right of cursor

A

Insert characters at end of line

i

Insert characters to left of cursor

I

Insert characters at beginning of line

o

Insert line below cursor

O

Insert line above cursor

Changing Text

 

cw

Change word (or part of word) to right of cursor

cc

Change line

C

Change from cursor to end of line

s

Substitute string for character(s) from cursor forward

r

Replace character at cursor with one other character

r Return

Break line

J

Join current line and line below

xp

Transpose character at cursor and character to right

~

Change case of letter (upper or lower)

u

Undo previous command

 

 

Command

Meaning

U

Undo all changes to current line

:u

Undo previous last-line command

Deleting Text

 

x

Delete character at the cursor

X

Delete character to the left of the cursor

dw

Delete word (or part of word to right of cursor)

dd

Delete line containing the cursor

D

Delete part of line to right of cursor

dG

Delete to end of file

d1G

Delete from beginning of file to cursor

:5,10 d

Delete lines 5-10

Copying and Moving Text

 

yy

Yank or copy line

Y

Yank or copy line

p

Put yanked or deleted line below current line

P

Put yanked or deleted line above current line

:1,2 co 3

Copy lines 1-2 and put after line 3

:4,5 m 6

Move lines 4-5 and put after line 6

Setting Line Numbers

 

:set nu

Show line numbers

:set nonu

Hide line numbers

 

Setting Case-sensitivity

:set ic

Searches should ignore case

:set noic

Searches should be case-sensitive

Finding a Line

 

G

Go to last line of file

1G

Go to first line of file

21G

Go to line 21

Searching and Replacing

 

/string

Search for string

?string

Search backward for string

n

Find next occurrence of string in search direction

N

Find previous occurrence of string in search direction

:g/search/s//replace/g

Search and replace

Clearing the Screen

 

Ctrl-L

Clear (refresh) scrambled screen

Inserting a File into a File

 

:r filename

Insert (read) file after cursor

:34 r filename

Insert file after line 34

Saving and Quitting

 

:w

Save changes (write buffer)

:w filename

Write buffer to named file

:wq

Save changes and quit vi

ZZ

Save changes and quit vi

:q!

Quit without saving changes

 

                                                                                               

command information listed:

 

  • passwd, shutdown,
  • useradd, userdel, usermod, groupadd,groupdel, groupmod
  • pkgadd, pkgrm,pkginfo, pkgchk
  • ufsdump,ufsrestore, tar,cpio
  • ls,chmod, chown, chgrp
  • prstat,pgrep, pkill, kill, ps, find
  • mount,
  • cp, mkdir, rmdir, rm, mv

 

 

From MAN of various command:

===========================

 

passwd:

 

--> always prompt for old password

--> pwconv command update the /etc/shadow with the info from /etc/passwd

--> each password should have PASSLENGTH character defined at /etc/default/passwd and

                it is default 6 and first 8 character are significant

 

--> Each password must contain  at  least  two  alphabetic characters and at least one numeric or special character. In this case, "alphabetic" refers to all upper orlower case letters.

 

        o  Each password must differ from the user's  login  name and  any reverse or circular shift of that login name.

           For comparison purposes, an upper case letter and  its corresponding lower case letter are equivalent.

 

        o  New passwords must differ from the  old  by  at  least three  characters.  For  comparison purposes, an upper

           case letter and its corresponding  lower  case  letter are equivalent.

 

--> if NIS or NIS+ running then use passwd -r option to change the local machine password.

 

--> Remember always NIS pasword and local password are differnet.

 

 

passwd -e shell change

                -r ldap , nis or nis+

                -g change the gecos or finger information      

                -h change the homedirectory

                -s name   -- show password attributes for name

                -f force user to change the password at next login

                -w warning

                -d delete pasword for name (login name don't need password ..only works for repository)

=================================

 

 

shutdown:

 

/usr/sbin/shutdown

 

OPTIONS

     -y    Pre-answer the confirmation question  so  the  command  can be run without user intervention.

 

     -g grace-period

           Allow the super user to change the number  of  seconds  from the 60-second default.

 

     -i init-state

           If there are warnings,  init-state specifies the state  init  is  to  be  in.  By default, system state `s' is

           used.

 

example# shutdown -i S -g 120 "===== disk replacement ====="

     Shutdown started.   Tue Jun   7  14:51:40 PDT  1994

 

     Broadcast Message from root (pts/1) on foo Tue Jun  7 14:51:41...

     The system will be shut down in 2 minutes

 

 

                # shutdown -i 0 -g 300 -y

                # shutdown -i 1 -g 300 -y

                # shutdown -i 5 -g 300 -y

 

=====================================================

 

useradd:

 

administer a new user login on the system

 

 useradd [ -c comment  ]   [  -d dir  ]   [  -e expire  ]   [

     -f inactive ]  [ -g group ]  [  -G group  [  ,  group ...  ]

     ]  [  -m  [ -k skel_dir ]  ]   [   -u uid   [  -o  ]   ]   [

     -s shell  ]  [ -A authorization  [ ,authorization... ]  ]  [

     -P profile  [ ,profile... ]  ]  [ -R role  [ ,role...  ]   ]

     login

 

     useradd -D  [ -b base_dir ]  [ -e expire ]  [ -f inactive  ]

     [ -g group ]

 

#useradd -D --> to see the default value that system should use.

 

 

The system files line has limitation of 512 character per line

 

login and role field contain character no more then 8 character and first character  should be alphabetic and atleast one character should be lower case. Thouhg system should just place an warning and should add the user to system.

 

login and role field contain atleast one character and should not contain : or \n (new line)

 

date mask assigned at /etc/datemask

 

==================================

 

 

userdel:

 

userdel - delete a user's login from the system

 

 userdel [ -r ]  login

 

                -r --> to remove with home directory

 

 

==================================

usermod:

 

 usermod - modify a user's login information on the system

 

SYNOPSIS

     usermod [  -u uid  [ -o ]  ]  [ -g group ]  [   -G group   [

     ,   group  ...   ]  ]  [  -d dir  [ -m ]  ]  [ -s shell ]  [

     -c comment ]  [ -l new_name ]  [ -f inactive ]  [  -e expire

     ]   [ -A authorization  [ , authorization ]  ]  [ -P profile

     [ , profile ]  ]  [ -R role  [ , role ]  ]  login

 

 

==========================================

groupadd:

 

groupadd - add (create) a new group definition on the system

 

/usr/sbin/groupadd [  -g gid  [ -o ]  ]  group

 

 -g gid

           Assigns the group id gid for the new group. This group  id must be a non-negative decimal integer below MAXUID as defined in /usr/include/sys/param.h. The  group  ID defaults  to  the next available (unique) number above

           the highest number currently assigned. For example, if groups  100, 105, and  200 are assigned as groups, the

           next default group number will  be   201.  (Group  Ids from   0-99  are reserved by SunOS for future applica-

           tions.)

 

     -o    Allows the gid to be duplicated (non-unique).

 

===============================

 

groupdel:

 

 groupdel - delete a group definition from the system

 

  /usr/sbin/groupdel group

 

 

EXIT STATUS

     The following exit values are returned:

 

     0     Success.

     2     Invalid command syntax. A usage message for the group- del command is displayed.

     6     group does not exist.

     10    Cannot update the /etc/group file.

 

===================================================

groupmod:

 

groupmod - modify a group definition on the system

 

 /usr/sbin/groupmod [  -g gid  [ -o ]  ]  [ -n name ]  group

 

OPTIONS

     The following options are supported:

 

     -ggid Specify the new group ID for the group. This group  ID must  be a non-negative decimal integer less than MAX- UID, as defined in <param.h>. The group ID defaults to the  next  available  (unique) number above 99. (Group

           IDs from 0-99 are reserved by SunOS for future  applications.)

 

     -o    Allow the gid to be duplicated (non-unique).

 

     -nname

           Specify the new name for the group.  The name argument is  a string of no more than eight bytes consisting of

           characters from the set of lower case alphabetic characters and numeric characters.  A warning message will

           be written if  these  restrictions  are  not  met.   A future  Solaris  release  may  refuse  to accept group

           fields that do not meet these requirements.  The  name argument  must contain at least one character and must

           not include a colon (:)  or NEWLINE (\n).

 

=========================================================

pkgadd:

 

pkgadd - transfer software packages to the system

 

     pkgadd transfers the contents of a software package from the distribution medium or directory to install it onto the system. Used without the -d option, pkgadd looks in the default spool  directory for the package (var/spool//pkg). Used with the -s option, it writes the package to  a  spool  directory  instead of installing it.

 

example% pkgadd -d /cdrom/cdrom0/s0/Solaris_2.6

 

 

EXIT STATUS

     0     Successful execution.

     1     Fatal error.

     2     Warning.

     3     Interruption.

     4     Administration.

     5     Administration. Interaction is required.  Do  not  use

           pkgadd -n.

     10    Reboot after removal of all packages.

     20    Reboot after removal of this package.

 

===============================================

 

pkgrm:

 

 

pkgrm - remove a package from the system

 

pkgrm [ -nv ]  [ -a admin ]  [  [ -A | -M ]  -R root_path  ]

     [ -V fs_file ]  [ pkginst ... ]

 

     pkgrm -s spool  [ pkginst ... ]

 

 

     pkgrm  will  remove  a  previously  installed  or  partially installed package from the system. A check is made to determine if any other packages depend on the one being  removed. If  a  dependency exists, the action taken is defined in the admin file.

 

     The default state for the command is  in  interactive  mode, meaning  that prompt messages are given during processing to allow the administrator to confirm the actions being  taken. Non-interactive mode can be requested with the -n option.

 

     The -s option can be used  to  specify  the  directory  from which spooled packages should be removed.

 

======================================

pkginfo:

 

pkginfo - display software package information

 

pkginfo [ -q | -x  | -l ]  [ -p | -i ]  [ -r ]  [ -a arch  ]

     [ -v version ]  [ -c category ... ]  [ pkginst ... ]

 

     pkginfo [ -d device ]  [ -R root_path ]  [ -q | -x  |  -l  ]

     [  -a arch ]  [ -v version ]  [ -c category ... ]  [ pkginst

     ... ]

 

     Without options, pkginfo lists the primary category, package

     instance, and the names of all completely installed and par-

     tially installed packages. It displays  one  line  for  each

     package selected.

 

     The -p and -i options are meaningless if used in conjunction

     with the -d option.

 

# pkginfo |wc -l   --> to count how many package installed

 

# pkginfo -l SUNWaudio

 

==========================================

pkgchk:

 

pkgchk - check package installation accuracy

 

     pkgchk checks the accuracy of installed files or,  by  using the  -l  option,  displays  information about package files.

     pkgchk checks the  integrity  of  directory  structures  and  files.  Discrepancies  are  written  to standard error along

     with a detailed explanation of the problem.

 

SYNOPSIS

     pkgchk [ -l | -acfnqvx ]  [ -i file ]  [ -p path  ...  ]   [

     -R root_path  ]   [  [   -m  pkgmap   [ -e envfile ]  ] |  [

     pkginst ]  ... ]

 

     pkgchk -d device  [ -l | -fv ]  [  -i file  ]   [  -M  ]   [

     -p path ... ]  [ -V fs_file ]  [ pkginst ... ]

 

 

 

# pkgchk -p /etc/passwd

 

===================================================

ufsdump:

 

ufsdump - incremental file system dump

 

/usr/sbin/ufsdump [ options ]  [ arguments ]  files_to_dump

 

0-9   0 --> full backup 1-9 --> Incremental backup

 

                -f option use to change the default /dev/rmt/0  tape device

                -D use to take backup on floppy

                -S option use to make the estimate the size of backup without doing real backup

               

 

# ufsdump 2v /dev/rdsk/c0t0d0s0

# ufsdump 3v /dev/rdsk/c0t0d0s0

# ufsdump 3vf /dev/rmt/1 /dev/rdsk/c0t0d0s0

 

 

                   /etc/dumpdates

           dump date record

               

==========================================

ufsrestore:

 

 ufsrestore - incremental file system restore

 

  i --> Interactive mode (allow to browse the list of archieve and can choose file)

  r --> recursively restore whole things

  R --> Resume restore

  t --> list the content of archieve

  d --> Tturn on debugging output

 

# ufsrestore ivf /dev/rmt/0

 

Recover the root (/) or /usr file systems

To back up the root filesystem, perform the following  from Single user login

# ufsdump 0uf /dev/rmt/0 /dev/rdsk/c0t0d0s0

# ufsrestore tvf /dev/rmt/0

 

The root file system must be recovered using ufsrestore after booting from a CDROM. The following steps can be performed:

ok boot cdrom –s

# newfs /dev/rdsk/c0t0d0s0

# mount /dev/dsk/c0t0d0s0 /restore

# cd /restore

# ufsrestore rvf /dev/rmt/0

# rm restoresymtable

# installboot bootblk /dev/rdsk/c0t0d0s0

# fsck /dev/rdsk/c0t0d0s0

# init 6

 

======================================================

tar:

 

tar - create tape archives and add or extract files

 

# tar cvf filename.tar /export/home  --> To create the tar file

 

# tar tvf filename.tar or /dev/rmt/0  --> to list the content of backup

 

# tar xvf filename.tar  --> just to extract

 

# tar xvf backup.tar install.log  --> to extract install.log file from backup.tar

 

 

Similar program like tar which compress each file before archieving and similar syntex

is zcat.

 

================================

cpio:

 

cpio - copy file archives in and out

 

How to copy all files in a directory to a tape (cpio)

 

$ ls | cpio -oc > /dev/rmt/n

 

                ls --> Provides the cpio command with a list of file name

                cpio -oc --> specify that cpio should work in copy out(-o ) mode

               

                > /dev/rmt/0 --> specifies where the file should go

 

 

Verify that file that copied by cpio is ok using the following command

 

$ cpio -civt < /dev/rmt/o

 

                -c --> specify cpio should read files in ASCII character format

                -i --> work in copy -in mode

                -v -> Output like ls -l format

                -t --> list the content

 

using absolutely path is a prob as it may over write your existing file when you restore.

 

File restore:

 

$ cpio -icvd < /dev/rmt/o

 

                -d --> create directory as needed

                                all options are same as before

 

Retrive specific file from tape

 

$ cpio -icv "*file" < /dev/rmt/0

 

                                "*file" --> that match this pattern should be restored.

 

Copy to remote tape drive:

 

$ tar cf - files | rsh remotehost dd of=/dev/rmt/n obs=blocksize

 

$ tar cvf - * | rsh mercury dd of=/dev/rmt/0 obs=126b

 

                - --> Represents a place holder for the tape drive

                |rsh remotehost --> pipe the tar commands output to remote host shell

                dd of=/dev/rmt/n --> Represents the out put device

                obs=blocksize--> Represents the blocking factor.

 

====================

ls:

 

ls - list contents of directory

 

                -rwxrwxrwx+  1 smith  dev    10876  May 16 9:42 part2

               

                meanings:

                               

                                File name --> part2

                                Time modified --> May 16 9:42

                                Group --> dev

                                username --> smith

                                Links --> 1

                                regular file  --> -rwxrwxrwx+

                                last + sign indicates that it contain ACL entry

 

 

                                -rwsrwsrwx  --> set uid is on and set gid is on

 

                                                                if execution field have s for usr or group field

                                                                so setuid and setgid is on if we see S instead of s

                                                                then uid/gid bit is set but execution is off

 

                                chmod 4777 --> setuid

                                chmod 2777 -> setgid

                                chmod g+s  for directory.

                               

                                -rwxrwxrwt  --> if other execution filed contain t so it is sticky bit

                                                                and if T then sticky bit set but execution is off

 

 

                                chmod 1777 --> sticky bit set

 

                                Remember if stilcky bit set then may be that folder be writable by all but only user who write this can access that file usefull /tmp

 

                               

NOTE:

 

To see the listing of file or directory which names begins with a,b or c and that ends with 1

 

# ps -ld [abc]*1

 

if want to see the file that ends with either 1,2 or 3 then use

 

# ps -ld a*[123]

 

================================

chmod:

 

chmod - change the permissions mode of a file

 

                -R --> Recursively

 

chmod works in two format 1. absolute mode which represents by octal number or symbolic mode-list which can be represents by u g 0 for user group other.

 

                chmod 4000 file --> set uid exection

                chmod 2000 file --> set gid execition

 

                chmod 666 file --> -rw-rw-rw- file

 

 

     Note that the setgid bit cannot be set (or cleared) in absolute  mode;  it  must  be  set (or cleared) in symbolic mode

     using g+s (or g-s)

 

symbolic mode permission setup:

 

                who operator permission

 

                who --> u --> user

                                g --> group

                                o --> other

                                a --> all

                operator + --> set

                                - --> remove

                                = --> assign permission absolutely

 

                permission:            r     read permission

                                w     write permission

                                x     execute permission

                                l     mandatory locking

                                s     user or group set-ID

                                t     sticky bit

                               

Example 1: Deny execute permission to everyone:

 

     example% chmod a-x file

 

 

Make a file readable and writable  by  the  group and others:

 

     example% chmod go+rw file

     example% chmod 066 file

 

Cause a file to be locked during access:

 

     example% chmod +l file

 

 

Allow everyone to read, write,  and  execute  the file and turn on the set group-ID.

 

     example% chmod a=rwx,g+s file

     example% chmod 2777 file

 

=====================================

chown:

 

chown username:groupname filename

 

                -R --> for recursively

 

                 -h     If the file is a symbolic link, change  the  owner  of the  symbolic  link. Without this option, the owner of

                the file referenced by the symbolic link is changed.

 

==============================

 

chgrp:

 

 chgrp [ -fhR ]  group  file ..

 

 

                 -h    If the file is a symbolic link, change  the  group  of  the  symbolic  link. Without this option, the group of

               

                -R --> Recursive

               

===========================================

prstat:

 

prstat - report active process statistics

 

                -a                displays separate user and process reports

                -c                continuously prints new reports

                -p pids       displays processes with pids that match the list

                -s key        displays sorted list sorted by key.  Keys can only be: cpu, time, size, rss and pri

                -t                reports a usage summary for each user

 

==============================

pgrep:

 

 pgrep, pkill - find or signal processes by  name  and  other attributes

 

# pgrep –lf mail

returns

1924 /usr/dt/bin/dtmail

2412 /usr/lib/sendmail –bd –q15m

all the processes that have mail in the name.

Using pkill to terminate the processes:

# pkill –U root mail

will kill all the processes owned by root with mail in the name.

               

================================                    

kill:

 

                /usr/bin/kill -s signal  pid ...

 

                /usr/bin/kill -l  [ exit_status ]

 

                /usr/bin/kill [ -signal ]  pid ...

 

                kill -9 100 -165

                kill -s kill 100 -165

                kill -s KILL 100 -165

 

# kill -INT 2345

will send the interrupt (terminate) signal to process 2345

# kill -HUP 179

will send the hangup (reread init state) signal to process 179

 

================================

ps:

 

 ps - report process status

 

                -e    Lists information about every process now running.

 

                -f    Generates a full listing. (See below for  significance

              of columns in a full listing.)

 

                 -A    Lists information for all processes. Identical to  -e,

               below.

 

 

# ps -ef  -- output description

 

bash-2.03# ps -ef|more

     UID   PID  PPID  C    STIME TTY      TIME CMD

    root     0     0  0 18:30:08 ?        0:04 sched

    root     1     0  0 18:30:09 ?        0:00 /etc/init -

    root     2     0  0 18:30:09 ?        0:00 pageout

    root     3     0  0 18:30:09 ?        0:02 fsflush

    root   313     1  0 18:30:31 ?        0:00 /usr/lib/saf/sac -t 300

    nobody   316   294  0 18:30:32 ?        0:00 /usr/apache/bin/httpd

 

 

GUI based tool for process listing is /usr/dt/bin/sdtprocess

 

Process Manager is a GUI based tool to monitor and control processes.

# /usr/dt/bin/sdtprocess &

 

just click the process on GUI and press CTRL + C to terminate that process

 

===================================================

find:

 

# find /home/export -name \*oman\* -print  --> always use by me ..

 

 find path ...  expression

 

expression

           The first argument that starts with a -, or is a !  or a  (, and all subsequent arguments will be interpreted

           as an expression made up of  the  following  primaries and  operators.   In  the  descriptions, wherever n is

           used as a primary argument, it will be interpreted  as a decimal integer optionally preceded by a plus (+) or

           minus (-) sign, as follows:

 

           +n    more than n

 

           n     exactly n

 

           -n    less than n

 

 

Valid expressions are:

 

     -atime n

           True if the file was accessed n days ago.  The  access time of directories in path is changed by find itself.

 

     -cpio device

           Always true; write the current file on device in  cpio format (5120-byte records).

 

     -ctime n

           True if the file's status was changed n days ago.

 

===============================================

mount:

 

Only super user can do mount and unmount command

 

If just run mount command it shows the all mounted file system found on

/etc/mnttab

 

                -F to specify file system 

 

Default remote file type identified by /etc/dfs/fstypes or /etc/vfstab

By default is ufs file type solaris. It can be assigned at /etc/default/fs file

 

                -f forcibly unmount the file system.

 

# mount –F pcfs /dev/floppy /mnt ( here /mnt is the mount point)

 

# mount /dev/disk/c0t0d0s7 /mnt  (Mount use block device)

 

What about umount to a busy file system????? may be some -k option but doesn't work

 

=========================================

cp:

 

 /usr/bin/cp [ -fip ]  source_file  target_file

 

     -i    Interactive. cp will prompt for confirmation  whenever the  copy  would  overwrite  an  existing target.  A y

           answer means that the copy should proceed.  Any  other  answer prevents cp from overwriting target.

 

     -r    Recursive. cp will copy  the  directory  and  all  its  files, including any subdirectories and their files to

           target.

 

     -R    Same as -r, except  pipes  are  replicated,  not  read

           from.

 

 

If in your direcotry ls -l shows as follows:

 

./ ../ .tst dir1/ file1   then to copy .tst in the direcotry of dir1/ run command as:

 

# cp .tst dir1/

 

====================================

mkdir:

 

 mkdir - make directories

 

 mkdir [ -m mode ]  [ -p ]  dir ...

               

The following options are supported:

 

          -m mode

                This option allows users to specify the  mode  to be  used  for  new directories. Choices for modes

                can be found in chmod(1).

 

          -p    With this option, mkdir creates dir  by  creating all  the  non-existing  parent directories first.

                The mode given to intermediate  directories  will be the difference between 777 and the bits set in

                the file mode creation mask. The difference, how-ever,  must  be  at  least 300 (write and execute

                permission for the user).

 

 

# mkdir -p dir1/dir2/dir3 

 

                creates 3 dir -->  dir1 dir1/dir2/ dir1/dir2/dir3

 

=======================

rmdir:

 

/usr/bin/rmdir [ -ps ]  dirname ...

 

rm, rmdir - remove directory entries

 

rmdir only remove the dir if the dir is empty.

 

rm support the following switch. it is also can remove file.

 

                -i --> Interactively

                -f --> forcively

                -r --> Recursively

 

================================

mv:

 

 /usr/bin/mv [ -fi ]  source  target_file

 

  The following options are supported:

 

     -f    mv will move the file(s) without prompting even if  it is  writing over an existing target. Note that this is

           the default if the standard input is not a terminal.

 

     -i    mv will prompt  for  confirmation  whenever  the  move would  overwrite  an  existing  target. An affirmative

           answer means that the move should proceed.  Any  other answer prevents mv from overwriting the target.

               

 

=========================================

Carlo

carlo_reyes71@yahoo.com