Unix Commands for DBA
Unix Commands |
|
#hostname -? |
To find out the
options |
#hostnaeme
-i |
IP address |
#hostname
-f |
Full domain
Name |
#df -k |
Free space |
#df -h |
Human readable space
(interns of MB and GB) |
#rm -R
filename |
To remove directory
with contents |
#netstat -? |
Will give ports
details (Listening Ports and Establish ports) |
#ls -F |
To differentiate
files and directories( with / means directory , others are files |
#cat -n
filename |
to see the file with
numbers |
#cp -i sourcefile
destinationfile |
to avoid over
writing the existing file |
# mv -i
originalfilename newfilename |
to avoid overwriting
theexisting file |
# rm -r
filesname |
remove the files in
interactive |
# ls directory1
directory2 |
list out files in
directory1 |
# ls -d
dierctory |
to show only
directory name without |
# mkdir
directory1 directory2 |
we can create many |
# mkdir -p
/tmp/ch04/test1 |
The mkdir command
checks whether |
# cp -r source
destination |
To copy the
directory |
# cp -r source1
source2 source3 destination |
to copy many |
#ls -A
directory |
to determine the
empty directory( if |
# file filename |
to know about file (
whether a |
# chown |
to chage the user
and droup of the file |
# ps -f |
to see the full detail(
PID and PPID ) of the |
# kill % job
number |
to kill the
particular job number |
# kill PID |
To kill the
particular process Id |
# kill -9 %jobnumber
od PID |
to kill the process
forcebaly |
# kill -KILL
%jobnumber od PID |
to kill the process
forcebaly |
vi COMMANDS |
|
vi filename |
start editing
filename, create it if necessary |
:wq |
write the file to
disk and quit(save and quit) |
:q! |
quit without saving
any changes |
:w! newfile |
write all lines from
the entire current file into the file 'newfile', overwriting any existing
newfile |
:n,m w! newfile |
write the lines from
n to m, inclusive, into the file newfile, overwriting any existing newfile |
Moving the Cursor |
|
h |
one space to the
left (also try left arrow) |
j |
one line down (also
try down arrow) |
k |
one line up (also
try up arrow) |
l |
one space to the
right (also try right arrow) |
$ |
end of current line |
^ |
beginning of current
line |
Enter |
beginning first word
on the next line |
G |
end of file |
:n |
line n;
use :0 to move the beginning of the file |
w |
beginning of next
word; 5w moves to the beginning of the 5th word to the right |
e |
end of next word |
b |
beginning of
previous word |
Ctrl-b |
one page up |
Ctrl-f |
one page down |
% |
the matching (, ),
[, ], {, or } |
Searching for Text |
|
/string |
search down
for string |
?string |
search up
for string |
n |
repeat last search
from present position |
Inserting Text |
|
a |
append starting
right of cursor |
A |
append at the end of
the current line |
i |
insert starting left
of cursor |
I |
insert at beginning
of the current line |
o |
open line below
cursor, then enter insert mode |
O |
open line above cursor,
then enter insert mode |
:r newfile |
add the contents of
the file newfile starting below the current line |
Deleting Text |
|
x |
delete single
character; 5x deletes 5 characters |
dw |
delete
word; 5dw deletes 5 words |
dd |
delete
line; 5dd deletes ... well you get the idea! |
cw |
delete word, leaves
you in insert mode (i.e. change word) |
cc |
change line --
delete line and start insert mode |
s |
change character --
delete character and start insert mode |
D |
delete from cursor
to end of line |
C |
change from cursor
to end of line -- delete and start insert mode |
u |
undo last change |
U |
undo all changes to
current line |
J |
join current line
with line that follows (press Enter in insert mode to split line) |
Navigating
Directories and files |
|
pwd |
'print working
directory' displays the name of the current directory |
cd |
change directory'
command will change the current directory to the directory specified as the
argument to the command, as in 'cd /home/WWW-pages/username'. ('cd' without
specified parameter will return to your home directory.) |
ls |
'list files' command
displays the files in a directory. |
ls -l |
long list option'
for listing files displays permissions, links, owner,group, file size,
modification date, file name. |
rm |
'remove' command
deletes ordinary files in a directory. |
mv |
move' command moves
a file from one location to another. It is also used to rename files, as in
'mv thisfile.txt thatfile.txt' |
cp |
'copy' command
creates a copy of a file. |
chmod |
change mode' command
is used to control access rights to a file or files. |
mkdir |
make directory'
command creates a directory or subdirectory within the current directory. |
rmdir |
remove directory'
command removes a directory or subdirectory. The specified directory must be
empty before it can be removed. |
find |
'find' command is
used to locate files. |
file |
file' command is
used to determine the type of information in the file listed as the argument
to the command, i.e. text or binary. |
cat |
cat' command
displays the contents of files. It is also used to concatenate files as in
"cat file1.txt file2.txt file3.txt > allfiles.txt". |
wc |
wc' command displays
a count of characters, words, and lines in a text file. |
sort |
'sort' command is
used to sort and/or merge text files. |
grep |
'grep' command
searches for text strings in files. |
Unix for the DBA
How to kill all similar processes with single
command (in this case opmn)
ps -ef | grep opmn |grep -v grep | awk ‘{print $2}’ |xargs -i kill -9 {}
Locating Files under a particular directory
find . -print |grep -i
test.sql
Using AWK in UNIX
To remove a specific column of output from a
UNIX command – for example to determine the UNIX process Ids for all Oracle
processes on server (second column)
ps -ef |grep -i oracle
|awk '{ print $2 }'
Changing the standard prompt for Oracle Users
Edit the .profile for the oracle user
PS1="`hostname`*$ORACLE_SID:$PWD>"
Display top 10 CPU consumers using the
ps command
/usr/ucb/ps auxgw | head
-11
Show number of active Oracle dedicated
connection users for a particular ORACLE_SID
ps -ef | grep $ORACLE_SID|grep
-v grep|grep -v ora_|wc -l
Display the number of CPU’s in Solaris
psrinfo -v | grep
"Status of processor"|wc -l
Display the number of CPU’s in AIX
lsdev -C | grep
Process|wc -l
Display RAM Memory size on Solaris
prtconf |grep -i mem
Display RAM memory size on AIX
First determine name of memory device
lsdev -C |grep mem
then assuming the name of the memory device is
‘mem0’
lsattr -El mem0
Swap space allocation and usage
Solaris : swap -s or
swap -l
Aix : lsps -a
Total number of semaphores held by all
instances on server
ipcs -as | awk '{sum +=
$9} END {print sum}'
View allocated RAM memory segments
ipcs -pmb
Manually deallocate shared memeory segments
ipcrm -m '<ID>'
Show mount points for a disk in AIX
lspv -l hdisk13
Display amount of occupied space (in KB)
for a file or collection of files in a directory or sub-directory
du -ks * | sort -n| tail
Display total file space in a directory
du -ks .
Cleanup any unwanted trace files more
than seven days old
find . *.trc -mtime +7
-exec rm {} \;
Locate Oracle files that contain certain
strings
find . -print | xargs
grep rollback
Locate recently created UNIX files
(in the past one day)
find . -mtime -1 -print
Finding large files on the server (more
than 100MB in size)
find . -size +102400
-print
Crontab :
To submit a task every Tuesday (day 2) at 2:45PM
45 14 2 * *
/opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1
To submit a task to run every 15 minutes on
weekdays (days 1-5)
15,30,45 * 1-5 * *
/opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1
To submit a task to run every hour at 15 minutes
past the hour on weekends (days 6 and 0)
15 * 0,6 * *
opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home