|
Locating
files
in
UNIX
To
find
the
location
of
code
that
will
be
executed,
the
“which”
command
is
used.
The
which
command
will
search
the
path
for
the
program
name
it
is
given.
For
example,
to
find
the
location
of
the
SQL*Plus
executable:
root>
which
sqlplus
/u01/home/oracle/product/9.1.2/bin/sqlplus
To
find
other
files,
the
UNIX
find
command
is
commonly
used.
In
chapter
8,
this
command
will
be
extended
to
search
for
all
files
that
contain
specific
strings:
root>
cd /
/
root>
find
. -print|grep
–i
dbmspool.sql
./oracle/product/9.1.2/rdbms/admin/dbmspool.sql
In
the
example
above,
cd
to
the
root
directory
(/)
and
issue
a
UNIX
find
command
to
display
every
file
on
the
Oracle
server.
Next,
pipe
the
output
of
the
find
command
to
grep,
which
searches
for
the
dbmspool.sql
file.
For
more
details
on
file
management
commands,
see
Chapter
8.
Some
common
UNIX
utility
commands
will
be
covered
next.
Using
grep
in
UNIX
The
grep
utility
is
the
most
common
method
used
to
find
UNIX
files
that
contain
specific
strings.
Experienced
users
quickly
learn
to
use
the
–i
option
to
do a
case
insensitive
string
search.
In
the
example
below,
the
goal
is
to
find
an
SQL
script
that
recompiles
invalid
objects.
root>
grep
-i
invalid
*.sql
MKSTDROL.sql:/*
create
role
for
'invalid'
users
*/
RUNTHEM.sql:
4
WHERE
STATUS
=
'INVALID'
add_view.sql:
'IV',
'Library
Cache
Invalidation',
invalid.sql:Spool
run_invalid.sql
invalid.sql:
status
=
'INVALID'
invalid.sql:@run_invalid.sql
locks.sql:
'IV',
'Library
Cache
Invalidation',
Using
awk
in
UNIX
The
awk
utility
is
used
often
extract
a
specific
column
of
data
from
output
or a
file.
For
example,
to
create
a
list
of
UNIX
process
IDs
for
all
Oracle
processes
on
the
server.
root> ps -ef|grep -i oracle|awk '{ print $2 }'
23308
25167
12193
25163
12155
24065
24073
First,
issue
the
ps –ef
command
to
get
a
list
of
all
UNIX
processes,
and
then
use
grep
to
filter
out
all
processes
except
this
that
contain
the
string
“oracle.
The
awk
utility
is
used
to
extract
the
second
column
of
output.
root>
ps -ef|grep
-i
oracle
oracle
23308
1
0
May
14 ?
0:06
ora_lgwr_prodb1
oracle
25167
1
0
Apr
30 ?
0:26
ora_smon_prodc1
oracle
25163
1
0
Apr
30 ?
41:27
ora_lgwr_prodc1
oracle
12155
1
0
11:30:43
?
0:01
oracleprodcars
(LOCAL=NO)
oracle
24065
1
0
Apr
30 ?
0:02
ora_pmon_rman
oracle
24073
1
0
Apr
30 ?
10:39
ora_ckpt_rman
oracle
24846
1
0
May
11 ?
0:48
oracleprodc1
(LOCAL=NO)
root> ps -ef|grep -i oracle|awk '{ print $2 }'
23308
25167
12193
25163
12155
24065
24073
|