You are on page 1of 41

Ref : B32068-01 (B15697-01), Oracle on Solaris Cheat Sheet (by James L.

Colestock),
Sun Documentation

***Very helpful to know how to edit configure files vi terminal session


using vi commands - see Appendix 1***

Step 1 - Verify OS

Step 2 - verify exectables are present

--> /usr/ccs/bin: make, ar, ld, nm

Step 3

Logging In to the System as root


Check 1 - Checking the Hardware Requirements - Memory Requirements

At least 1 GB of RAM

--> /usr/sbin/prtconf | grep "Memory size" or

Step 4 - relationship between installed RAM and the configured swap space
requirement

RAM Swap Space


Between 1024 MB and 2048 1.5 times the
MB size of RAM
Between 2049 MB and 8192 Equal to the
MB size of RAM
More than 8192 MB 0.75 times the
size of RAM

To determine the size of the configured swap space

--> /usr/sbin/swap -s

The following examples shows how to create a 24 Mbyte swap file called
/files/swapfiles.
# mkdir /files
# mkfile 24m /files/swapfile (***wait - time delay***)
# swap -a /files/swapfile
# vi /etc/vfstab
(An entry is added for the swap file):
/files/swapfile - - swap - no -
# swap -l
swapfile dev swaplo blocks free
/dev/dsk/c0t2d0s1 32,17 8 205624 192704
/files/swapfile - 8 40952 40952
The following examples shows how to delete the /files/swapfile swap file.
# swap -d /files/swapfile
# (Remove the deleted swap entry from the /etc/vfstab file)
# rm /files/swapfile
# swap -l
swapfile dev swaplo blocks free
/dev/dsk/c0t2d0s1 32,17 8 205624 192720

Adding a Swap File on Solaris


Use mkfile to create a file suitable for a local swap area. For example, to create a 1GB
swap file:
/usr/sbin/mkfile 1024m /swap
where /swap is the name of the file to be used as swap space. Units for the size can be
kilobytes (k), blocks (b), or megabytes (m).
Tell the system to start using the file as swap:
/usr/sbin/swap -a /swap
Use swap -l to verify that the swap file has been activated

Step 4 - Disk space requirements - 225-275 mb space / tmp dir

Between 225 and 275 MB of disk space in the /tmp directory

To determine the amount of disk space available in the /tmp directory, enter the
following command:
On Solaris 10:
# df -h /tmp
Other Solaris operating systems:
# df -k /tmp

Size Used Avail Capacity Mounted On

Swap 2.0G 52K 2.00G 1% /tmp

Step 5 - Disk space requirements - free space


To determine the amount of free disk space on the system, enter the following
command:
On Solaris 10:
# df -h
Other Solaris operating systems:
# df -k

The following table shows the approximate disk space requirements for software files
for each installation type:

Installation Type Requirement


for Software
Files (GB)
Enterprise Edition 4.68
Standard Edition 4.62
Custom (maximum) 4.71

Between 1.5 GB and 2 GB of disk space is required for preconfigured database that
uses file system storage (optional)

Step 6 - Insufficent space..need to create additional space via new disk.

Steps Involved

- Create a VM Virtual Disk (IDx)


- Create a partition

format
disk
Disk 0

Disk 1

Disk 2

should appear, if not try ...touch /reconfigure; init 6 or devfsadm -v


reboot

create partition --> p (run fdisk first) (be extra careful - with regard cylinders !!!)
(configuration below, not best pratice)

save --> within partition>label


Disk 0

Disk 1
Disk 2

quit

- Create a file system.

# newfs /dev/dsk/cod1s0

(*** note 0 - root, 1 - swap)

- Create a mount point (, if it does not already exist) (need be called /u0X - X=1,2,3..)

mkdir /oracle (empty dir)

mount /dev/dsk/cod1s0 /oracle

enter path in /etc/vfstab


reboot

/oracle

Step 7 - Software Requirements - OS


The following are the operating sytem requirements for Oracle Database 11g
Release1:
■ Solaris 9 Update 7
■ Solaris 10
To determine the distribution and version of Solaris installed, enter the following
command:

# uname -r

5.10

Step 8 - Software Requirements - Package Requirements

Item Requirement
Packages The following packages (or
later versions) must be
installed:
SUNWarc
SUNWbtool
SUNWhea
SUNWlibC
SUNWlibm
SUNWlibms
SUNWsprot
SUNWtoo
SUNWi1of
SUNWi1cs
SUNWi15cs
SUNWxwfnt
SUNWsprox
Note: The SUNWsprox
package is not supported
on Solaris 10.
You may also require
additional font packages
for Java, depending on
your locale. Refer to the
following Web site for more
information:
http://java.sun.com/j2se/1.
4.2/font-requirements.html
To determine whether the required packages are installed, enter commands similar to
the following:
# pkginfo -i SUNWarc SUNWbtool SUNWhea SUNWlibm SUNWlibms SUNWsprot \
SUNWsprox SUNWtoo SUNWi1of SUNWi1cs SUNWi15cs SUNWxwfnt
If a package is not installed, then install it. (All packages are on Solaris CD which you
can buy £20+)

# pkgadd -d /cdrom/name_of_disk/solaris_10/product SUNWi1cs

NB Configure VW Ware CD point to correct CD ! ***

Step 9 - Software Requirements - Compiler Requirements

Step 9A
gcc 3.4.2 (Solaris package name is SUNWgcc)
Sun ONE Studio 8 (C and C++ 5.5)

--both not on web

--> gcc 3.4.6

gcc already installed, part of Solaris 10 !!! (learnt hard way(dont ask....))

appears in directory

--> /usr/sfw/bin
Thus, need to add to $PATH (add it..)

-------------------------------------------------------------------------------

Quick Notes on Packages in Solaris


--> Don't create any target directory.

--> The pkgadd command will do it for you.

--> And don't create temporary directories in locations that belong to the OS, like /usr.

--> Use /tmp, /var/tmp, your home directory or top level non standard directories (eg: /software) for your temporary

files.

Create folder/subfolders -->/usr/local/bin & /usr/ccs/bin (if they don't exist)

Unzip file and copy to /tmp or burn to cd (VM Ware)

After that I installed the libiconv package first, since that is a requirement.
pkgadd -d /(location)/libiconv-1.9.2-sol10-sparc-local
if it asks to overwrite any files - n (y most times), then continue

Then I installed gcc (already installed)


pkgadd -d /(location)/gcc-346-sol10-x86-local

To remove the installed package SMCgcc from a system, run this command as root:
pkgrm SMCgcc
Need to update $PATH
I do "echo $PATH" and get the following:
/usr/sbin:/usr/bin:/usrdt/bin:/usr/opwnwin/bin/usr/ucb
There's an existing file /etc/.profile on my Solaris 10 system, so I
added the following to that file:
(ref : http://www.mydatabasesupport.com/forums/solaris/360271-how-revise-path-when-
logged-root-solaris-10-a.html)
PATH=$PATH:/usr/local/bin:/usr/ccs/bin/:/usr/local/bin/gcc; export PATH
Save and restart
(terminal) gcc - version (cannot execute)
------------------------------------------------------------------------------

using gcc from os (plus set $PATH to executable) --> gcc : no input file
ignore
------------------------------------------------------------------------------

Quick Notes on Compressed Applications in Solaris

unzip using gzip -d lsof-4.77-sol10-sparc-local.gz


in the same dir you unzzipped it, then execute pkgadd -d . pkg name
or
gunzip package-file.gz # equivalent to "gzip -d"
pkgadd -d package-file
or
download bunzip2 from web and use
or
use file roller application (already installed) to extract file manually, not terminal session
------------------------------------------------------------------------------

Step 9B

--> Install Sun Studio 12


Copy file to /tmp (when you restart file disappears !)
So, copied file to /Oracle/downloads/SunStudio12 (make sure plenty space > .5gb size)
use file roller to unzip
or
# /usr/local/bin/bunzip2 studio11 -sol-sparc.tar.bz2
# tar -xvf studio11-sol-sparc.tar

Then, terminal , root


/(location)/Installer (it worked for me, without changing anything in environment)
Location install --> /opt (changed to /oracle/opt plus created sub-folder opt)
Selected pre-requirements, install patches & fixes.
but
You will have to make sure your environment has all the appropriate references to java
in it; here is my
environment before launching the installer:
# env
CLASSPATH=/usr/j2se/jre/lib:/usr/j2se/lib
DISPLAY=192.168.1.2:0.0
HOME=/
JAVA_HOME=/usr/j2se/jre
LOGNAME=root
PATH=/usr/j2se/jre/bin:/usr/bin:/bin:/usr/sbin:/sbin
SHELL=/sbin/sh
SSH_CLIENT=192.168.1.2 2746 22
SSH_TTY=/dev/pts/1
TERM=vt100
TZ=US/Pacific
USER=root
# ./installer
Aug 11, 2006 1:52:58 PM java.util.prefs.FileSystemPreferences$2 run
INFO: Created user preferences directory.

but I add after install complete


# PATH=/oracle/opt/SUNWspro/bin:$PATH; export PATH (/etc/profile)

restart

Afterwards, I check to see if sunstudio launches without fail via:


# sunstudio

Step 10 - Patch Requirements - Compiler Requirements

Orginial Requirements

127111-02 SunOS 5.10: libc patch

For Solaris 10:

117837-05: C++ compiler optimizer patch

117846-08: C++ compiler Optimization patch

118682-01

Patch Site

127111-02 Obsolete Latest 127127-11

117837-05 Obsolete Latest 117837-08

117846-08 Obsolete Latest 117846-19

118682-01 Latest 118682-01

Copy Patch to required location (if using CD burn using Nero)

/oracle/downloads/patches/
terminal

cd /oracle/downloads/patches/patch_number

unzip patch_number.zip

reload

rm patch_number.zip

patchadd patch_number

patchadd -p

patchadd -p | grep 111713 (without rev no) --> /usr/sbin/patchadd....

showrev -p | grep 111713

reboot ********* (after each patch...............)

Step 11 - Checking the Network Setup - Configuring Name Resolution

Laptop

10.10.10.10 GWWPCP200156 GWWPCP200156.WORKGROUP


VMWare server - Solaris

Name gwwpcSOLARIS

IP Address 10.10.10.20

192.168.0.20
The following command should yield an entry for ‘files’:
# cat /etc/nsswitch.conf | grep hosts
# "hosts:" and "services:" in this file are used only if the
hosts: files
Oracle recommends that the following command return a fully-qualified hostname,
however, mine does
not:
# hostname
gwwpcSOLARIS
Oracle recommends that the following command return nothing:
# domainname
Here is the contents of my /etc/hosts file:
# more /etc/hosts
#
# Internet host table
#
192.168.1.20 gwwpcSOLARIS
127.0.0.1 localhost

-----------------------------------------------------------------------

Future Reference

Virtual Network

IP Address of Host
Virtual Network - Summary
Vmnet1
Vmnet8
-----------------------------------------------------------------------
Step 12 - Creating Required Operating System Groups and Users

--Create OSDBA group (dba)

groupadd dba (or /usr/sbin/groupadd dba)

--Create Oracle Inventory Group

Check if exists

#more /var/opt/oracle/oraInst.loc

groupadd oinstall

--Create OSOPER group (optional)

groupadd oper (or /usr/sbin/groupadd oper)

--Create Directory

mkdir /home/oracle (assume u have space)


mkdir /oracle/home/oracle
--Check Oracle software owner user exists

Check if exists

id -a oracle
--Create Oracle software owner user

useradd -g oinstall -G dba,oper oracle

usermod -g oinstall -G dba,oper -d /oracle/home/oracle -s /bin/bash -c


"Oracle Software Owner" oracle

usermod -g dba -G oinstall,oper -d /oracle/home/oracle -s /bin/bash -c


"Oracle Software Owner" oracle

id -a oracle

chown oracle:dba /oracle/home/oracle

passwd -r files oracle (change pwd)

Modify is the similar command...usermod -g oinstall -G dba,oper oracle


--Check User nobody exists

id -a nobody

if not, create

useradd -g nobody

Step 13 - Configuring Kernel Parameters on Solaris 10

10g

Parameter Replaced by Recom


Resource mende
Control d Value
noexec_user_stack NA 1
semsys:seminfo_semmni 2. 100
project.max-
sem-ids
semsys:seminfo_semmn NA 1024
s
semsys:seminfo_semmsl project.max- 256
sem-nsems
semsys:seminfo_semvm NA 32767
x
shmsys:shminfo_shmma 1. project.max- 429496
x shm-memory 7296
shmsys:shminfo_shmmn project.max- 100
i shm-ids

Note:
When you use the prctl command (Resource
Control) to change system parameters, you do
not need to restart the system for these
parameter changes to take effect. However, the
changed parameters do not persist after a
system restart.

To view current values

Resource Control
Temp
1. (assume ram 2g - half that)

Before

After

2.
Before
After

Perm
1.

Example
purgatorio# projadd -p 10000 -c 'test project' -U jqpublic test
purgatorio# grep ^test: /etc/project
test:10000:test project:jqpublic::
(Note that projadd and projmod won't let you change the resource-control field.)
This project is named "test" and has a project ID of "10000". Membership is restricted to
the user "jqpublic," and any project running in the test project will not be allowed to
create a file greater than 16MB (16MB = 16,777,216 bytes).
projadd -p 100 -c "Oracle default" -g dba

By default, Oracle instances are run as the oracle user of the dba group. A project
with the name group.dba is created to serve as the default project for the oracle user.
Run the command id to verify the default project for the oracle user:

su - oracle
id -p

# projmod -sK "project.max-shm-memory=(privileged,4g,deny)" group.dba


Parameter Replaced by Resource Control Recommended Projmod Command
Value
noexec_user_stack NA 1
semsys:seminfo_semmni project.max-sem-ids 100 projmod -sK "project.max-sem-ids=(privileged,100,deny)"
group.dba
semsys:seminfo_semmns NA 1024
semsys:seminfo_semmsl project.max-sem-nsems 256 projmod -sK "project.max-sem-nsems=(privileged,256,deny)"
group.dba
semsys:seminfo_semvmx NA 32767
shmsys:shminfo_shmmax project.max-shm-memory 4294967296 projmod -sK "project.max-shm-memory=(privileged,4g,deny)"
group.dba
shmsys:shminfo_shmmni project.max-shm-ids 100 projmod -sK "project.max-shm-ids=(privileged,100,deny)"
group.dba

Check the values

or
su - oracle
id -p
prctl -n project.max-shm-memory -i process $$ (run command su - oracle)

set semsys:seminfo_semmni=100
set semsys:seminfo_semmsl=256
set shmsys:shminfo_shmmax=4294967295
set shmsys:shminfo_shmmni=100
The Oracle installer recognizes kernel parameters set using this method, but it is now
deprecated in favour of resource control projects, explained below.

As the root user, issue the following command.


projadd oracle
Append the following line to the "/etc/user_attr" file.
oracle::::project=oracle
If you've performed a default installation, it is likely that the only kernel parameter you
need to alter is "max-shm-memory". To check the current value issue the following
command.
# prctl -n project.max-shm-memory -i project oracle
project: 100: oracle
NAME PRIVILEGE VALUE FLAG ACTION
RECIPIENT
project.max-shm-memory
privileged 254MB - deny
-
system 16.0EB max deny
-
#
To reset this value, make sure at least one session is logged in as the oracle user, then
from the root user issue the following commands.
# prctl -n project.max-shm-memory -v 4gb -r -i project oracle
# projmod -s -K "project.max-shm-memory=(priv,4gb,deny)" oracle
The first dynamically resets the value, while the second makes changes to the
"/etc/project" file so the value is persistent between reboots.
# cat /etc/project
system:0::::
user.root:1::::
noproject:2::::
default:3::::
group.staff:10::::
oracle:100::::project.max-shm-memory=(priv,4294967296,deny)
#
The Oracle installer seems incapable of recognising kernel parameter set using resource
control projects, but if you ignore the warnings the installation completes successfully.

Step 14 - Identifying Required Software Directories

--> Oracle Base Directory

--> Oracle Inventory Directory

--> Oracle Home Directory

Oracle Base Directory (ORACLE_BASE)


top-level
c:\oracle e.g.
/mount_point/app/oracle_sw_owner

- mount_point - Oracle
- oracle_sw_owner - Oracle

Oracle Inventory Directory


ORACLE_BASE/oraInventory (installer creates it..)

Oracle Home Directory


ORACLE_BASE/product/11.1.0/db_1 (installer creates it..)

Creating an Oracle Base Directory

From Scrath
Check free disk space
# df -h /tmp or # df -k /tmp
# df -h /oracle

1.
# mkdir -p /mount_point/app/oracle_sw+owner
# mkdir -p /oracle/app/oracle

2.
# chown -R oracle:oinstall /mount_point/app/oracle_sw+owner
# chown -R oracle:oinstall /oracle/app/oracle

3.
# chmod -R 775 /mount_point/app/oracle_sw_owner
# chmod -R 775 /oracle/app/oracle

Existing
Identify Oracle Inventory Directory

# more /var/opt/oracle/oraInst.loc

Identify Oracle Home Directory

# more /var/opt/oracle/oratab

Creating Directories for Oracle Database or Recovery File

Check free disk space


# df -h /tmp or # df -k /tmp
# df -h /oracle

File System Requirements for 11g

Datafile Files > 1.2 GB of free disk space


Recovery Files > 2.4 GB of free disk space

ORACLE_BASE --> /oracle/app/oracle (/mount_point/app/oracle_sw_owner)


(windows d:\app\Ackers)

4.
Database File &
# mkdir -p /mount_point/app/oracle_sw_owner/oradata
# mkdir -p /oracle/app/oracle/oradata

5.
# chown -R oracle:oinstall /mount_point/app/oracle_sw_owner/oradata
# chown -R oracle:oinstall /oracle/app/oracle/oradata

6.
# cdmod -R 775 /mount_point/app/oracle_sw_owner/oradata
# chmod -R 775 /oracle/app/oracle/oradata

7.
Recovery File Directory
# mkdir -p /mount_point/flash_recovery_area
# mkdir -p /oracle/app/oracle/flash_recovery_area

8.
# chown -R oracle:oinstall /mount_point/flash_recovery_area
# chown -R oracle:oinstall /oracle/app/oracle/flash_recovery_area

9.
# chmod -R 775 /mount_point/flash_recovery_area
# chmod -R 775 /oracle/app/oracle/flash_recovery_area

10. (oracle 1g)


# mkdir /var/opt/oracle
# chown oracle:oinstall /var/opt/oracle
# chmod 755 /var/opt/orac;e

Step 15 - Configuring Oracle User's environment

Clear as mud !!!!!

SUMMARY --> su - oracle

Set default file mode creation mask (unmask) to 022 in shell startup file.

Set DISPLAY environment variable


$ su - oracle

$ echo $SHELL (default shell)

$ vi .bash_profile

unmask 022

remove any environment variables for ORACLE.

save and exit

. ./.bash_profile (run shell startup script)

# df -h /tmp or df -k /tmp

(optional)

$ sudo mkdir /mount_point/tmp

$ sudo chmod a+wr /mount_point/tmp

$ exit

next,

$ TMP=/mount_point/tmp

$ TMPDIR=/mount_point/tmp

$ export TMP TMPDIR

next,

$ ORACLE_BASE=/Oracle/app/oracle

$ ORACLE_SID=VWS01

$ export ORACLE_BASE ORACLE_SID

next,

$ unset ORACLE_HOME

$ unset TNS_ADMIN

verify

$ umask

$ env | more

If you get DISPLAY errors,

check root *****

DISPLAY=192.168.0.20:0.0

export DISPLAY

xhost +192.168.0.20

Result
su - oracle

cd ..

. /runInstaller

Custom

No database created

Need to run root.sh script as root. Install installs cluster services daemon.

Step 16 - Install Latest Patch Set

If 64 bit, sparc.

The root.sh script that you ran as root during the installation process started a cluster
services daemon that runs as the root user. We will need to stop this daemon before we
can apply the Oracle patch set. Oracle only needs the cluster services daemon on database
servers that use Oracle’s Automatic Storage Management (ASM) or Real Application
Clusters (RAC). Since we will not be using either of these facilities, there will be no need
to have this daemon run at all. We cannot simply kill the daemon, because the root.sh
script added a “respawn” entry to the inittab. (If we kill the daemon, the operating system
will restart it.)
To stop the cluster services daemon and prevent it from restarting immediately or when
the server is rebooted in the future, we will need to restore the inittab to is previous state.
Luckily, the root.sh script preserved a backup copy before editing the inittab. First,
doublecheck that the backup copy of inittab is identical to the real inittab except for the
one entry added by the root.sh script:
$ diff /etc/inittab.orig /etc/inittab
Next, run the following commands very carefully as root:
$ mv /etc/inittab.orig /etc/inittab
$ /etc/init.d/init.cssd stop
$ mv /etc/rc3.d/S96init.cssd /etc/rc3.d/_S96init.cssd
$ mv /etc/rc3.d/K96init.cssd /etc/rc3.d/_K96init.cssd
But, 32 bit
Generates cannot execute - 64bit, not 32 bit.

Step 17 - Update oraenv script

ORACLE_BASE=/Oracle/app/oracle

ORACLE_HOME=/Oracle/app/oracle/product/10.2.0/db_1

Where are oraenv and coraenv found and how do they get created on various
Unix platforms?
These scripts are used to allow the DBA to set a common environment
for all users and make it easier for users to move between databases.

By setting the variable "ORAENV_ASK" to yes, the user will be


prompted to enter the <SID> value of the database they would like to
access. If "ORAENV_ASK" is set to no, the current value of "ORACLE_SID"
will be used.

Next, the script 'dbhome' is called to determine the "$ORACLE_HOME"


for that SID and set "$ORACLE_HOME" to the corresponding value.
'dbhome' will also add "$ORACLE_HOME/bin" to the user's PATH and
on some platforms (such as Digital UNIX), it will run "ULIMIT".

These scripts can usually be found in:

/usr/local/bin, $ORACLE_HOME/bin HP-UX


/usr/bin, $ORACLE_HOME/bin Solaris, AIX

Both oraenv and coraenv are created during install and copied to
your "/usr/local/bin" when "root.sh" is run during post installation
steps.
Use oraenv when you are using the Bourne and Korne Shells.
Use coraenv when you are using the C shell.
These scripts perform the same functions, but are designed
for the different shells.
Step 18 - Create Database

root

DISPLAY=192.168.0.20:0.0

export DISPLAY

xhost +192.168.0.20

su - oracle

check variables

ORACLE_BASE, ORACLE_HOME, ORACLE_SID

cd $ORACLE_HOME/bin

./dbca

create database....

ORACLE_SID not picked up but ORACLE_BASE, ORACLE_HOME is.


Configure Database
Listener --> lsnrctl start, status
NetManager --> netmgr
SQLPlus
create pfile from spfile;

Check Oracle environment

ORACLE_SID

ORAENV_ASK=NO

export ORAENV_ASK

Check --> /var/opt/oracle/oratab

e.g

/u01/app/oracle/product/10.1.0/db_1:Y
Step 18 - Startup and shutdown

To make the database and listeners start up automatically when the server reboots and
shut down automatically when the server shuts down, you’ll need to create a dbora file in
/etc/init.d and link it to /etc/rc2.d and /etc/rc0.d.
You’ll need to do this as the root user.
First create a file called dbora in /etc/init.d as follows:
#!/bin/sh
ORA_HOME=/u01/app/oracle/product/10.1.0/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start') # Start the Oracle databases and listeners
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start
dbconsole"
su - $ORA_OWNER -c "$ORA_HOME/bin/isqlplusctl start"
;;
'stop') # Stop the Oracle databases and listeners
su - $ORA_OWNER -c "$ORA_HOME/bin/isqlplusctl stop"
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop
dbconsole"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut"
;;
esac

rc2.d means the directory which contains scripts which will be executed in run-level 2
and so on.
S99dbora means S-start script 99-unique number
K10dbora means K-kill (stop) script 10-unique number
After creating the dbora file, you need to link it to /etc/rc2.d and /etc/rc0.d:
ln -s /etc/init.d/dbora /etc/rc2.d/S99dbora
ln -s /etc/init.d/dbora /etc/rc0.d/K10dbora
l -- l (next 2 k)

Appendix - 1 Summary of Basic vi Commands


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

Table 6-1 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
Back Space Move left one character
Space Bar 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
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

Appendix - 2 Commands

1.Copy file

cp /location/orig_file /location/new_file

2.Changing File Ownership


chown user:group /location

3.
. --> means hidden

4.
# --> root

5.
$ --> user

http://www.experts-exchange.com/Database/Oracle/Q_20156385.html
http://www.iselfschooling.com/FREE_Oracle_Training/04_Advanced/03_Articles/lesson
29.html
http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+12209
56472554+28353475&threadId=32769

You might also like