Unix for the Oracle DBA

Unix commands for oracle dba

List of Oracle instances running on the server:

ps -ef | grep smon | grep -v grep

List the listeners running on the server:

ps -ef | grep lsn | grep -v grep

get free memory:

on linux:

free

on solaris :
on all unix platform :

vmstat
pagesize=`pagesize`
kb_pagesize=`echo "scale=2; $pagesize/1024" | bc -l`
sar_freemem=`sar -r 1 1 | tail -1 | awk 'BEGIN {FS=" "} {print $2}'`
gb_freemem=`echo "scale=2; $kb_pagesize*$sar_freemem/1024/1024" | bc -l`
echo "Free Mem: $gb_freemem GB"

List files larger than 50M in a directory:

find . -type f -size +50000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

List top 10 larger files in a directory:

du -sk * | sort -nr | head -10

List directory structure ordered by size (perl needed):

du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s  %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}'

Delete files older than 30 days:

find . -mtime +30 -exec rm {} \;

Get directory or file size:

du -hs <file_or_directory>

List mount points:

df -k

Find files containing searched string:

find . -print | xargs grep mystring

Compare the content of two files:

this will compare the two files and return lines that are in file2 but not in file1.

grep -vf file1 file2

you can also use :

diff file1 file2

This will list all lines with differences.

Keep jobs active when disconnecting:

The screen command allow you to detach you terminal like a process, disconnect from server and then restore you terminal like you left it when you disconnected.
Once logged on server type command:

cyrille@server1$ screen

Do your actions, maybe run a long sqlplus script and then press Ctrl-A followed by Ctrl-d
This will detach your terminal, from there you can leave the server, you terminal persist.
When you comeback to the server, just type:

cyrille@server1$ screen -r

This will restore your terminal like you left it.

5 thoughts on “Unix for the Oracle DBA

  1. Hi Cyrille, you can also display the free memory with the column “free memory” of vmstat 😉

  2. You’r welcome Cyrille. vmstat free memory column validated on Solaris and Linux. On Linux you can also find the free memory with “top”. Have a nice day!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.