Useful Oracle DBA Linux Commands

Posted By Sagar Patil

Find files older than 5 days:    find . -mtime +5 -print | xargs ls -l | more
Remove files older than 5 days :  find . -mtime +5 -print | xargs rm

List files named “trust.p12” with their attributes

$ find . -name “*trust.p12” -type f -ls
738579    4 -rw-rw-r–   1 was61    was61        1586 Oct 23 04:36 ./dmgr/etc/trust.p12
738623    4 -rw-rw-r–   1 was61    was61        2730 Oct 23 02:02 ./dmgr/config/cells/Cell/trust.p12
738625    4 -rw-rw-r–   1 was61    was61        2730 Oct 23 02:02 ./dmgr/config/cells/Cell/nodes/Node01/trust.p12
1098642    4 -rw-rw-r–   1 was61    was61         850 Jul 13  2010 ./Node/etc/trust.p12
1098644    4 -rw-rw-r–   1 was61    was61        2730 Oct  7  2010 ./Node/config/cells/Cell/trust.p12
1098647    4 -rw-rw-r–   1 was61    was61        2730 Oct  7  2010 ./Node/config/cells/Cell/nodes/Node01/trust.p12

Print the number of blocks used by each directory

find . -type d -exec du -s {} \;

Find directory size recursively

$du -h –max-depth=10

8.1G    ./current/ABLXPORA01
153M    ./current/BAK/ABMWPSQL01/BDY_TVP_P

$ du -a | sort -rn | head
9646324 .
8532176 ./IBM
4008132 ./IBM/WebSphere
3753856 ./IBM/WebSphere/AppServer
3321980 ./IBM/HTTPServer
3003896 ./IBM/HTTPServer/Plugins

$ du -sk * | sort -nk 1
228     cdump
2468    stage
3924    metadata
5328    alert
286480  trace
6757680 incident

Print names of all files over 5,000 blocks (2,560,000) bytes.

du -sk * | sort -nk 1 | pg

List and sort out the files per their size

find $ORACLE_BASE -size +2000 -exec ls -s {} \; | sort -nr | more

Look for which big files have filled up a filesystem recently

find . -size +20000 -mtime -10 -ls  (10 here is days)

Find files which were modified either (<)  less than 1 week ago but more (>) than 2 weeks ago

find . \( -mtime +14 -o -mtime -7 \) -ls

Find and delete files older than 5 days

-rw-r—– 1 oracle oracle 2620416 Aug 30 23:16 1_2114_692896370.arc
-rw-r—– 1 oracle oracle 2620416 Sep  1 23:28 1_2161_692896370.arc
-rw-r—– 1 oracle oracle 2624512 Feb 14 00:18 1_21301_700768645.arc

find . -type f -mtime +15 -exec rm -f {} \;

-rw-r—– 1 oracle oracle 2624512 Feb 14 00:18 1_21301_700768645.arc

Find all files modified in last 10 days and  print them as <Size> <Filename>, I have used grep again to list only log files

$ find /opt -size +20000 -mtime -10 -ls |  awk ‘{print $7 ” ”  $11}’ | grep log
104857600 /opt/filestores/com.ibm.ws.sib/localhost_Node01.dev_server_member1-PRPC_Bus-1A01E8290042E159/log/Log
104857600 /opt/filestores/com.ibm.ws.sib/localhost_Node01.dev_server_member2-PRPC_Bus-DF5E2FA284B7341C/log/Log
147066880 /opt/logs/dev_server_member2/native_stderr.log

Find all files containing a string in filename only

$du -a | grep “string”

Find all files recursively with a “hostName” string:

grep -H -r “hostName=” /opt |  cut -d: -f1
/opt/IBM/WebSphere/localhost_Cell/nodes/localhost_Node01/serverindex.xml
/opt/IBM/WebSphere/localhost_Cell/nodes/localhost_Manager/serverindex.xml

Look for word 500 and print lines on screen  :

egrep -in “500” $HOME/today_access.log

Search for word “500” in files at /opt directory

find /opt | xargs grep -l 500

find . | xargs grep 'string'

I need to return only name of file from “ls -l”

-rwxr-xr-x 1 was61 web  4970 Jun 30  2009 startManager.sh
-rwxr-xr-x 1 was61 web  5026 Jun 30  2009 startNode.sh
ls -la | awk ‘{print $9}’
startManager.sh
startNode.sh

Get kill PID of sessions  : ps -ef | grep java | grep dev_server_member2 | awk ‘{print $2}’

This command will backup trace files and then delete them

tar -czvf /mnt/backup/Traces_`date +%Y%m%d_%H%M`.tgz   /opt/app/oracle/diag/rdbms/prod/trace/*.tr*   &&  find *.tr* -delete

Shell script to Find Files Recursively with a “string”

#!/bin/bash
#
# Author: Sagar PATIL
echo "Enter the FullPackage DIR path[/opt/IBM/WebSphere/AppServer/profiles/Profile01/Dmgr/config/cells......] "
read PKG_DIR
echo "Enter the Source Pattern to be replaced "
read SS
grep -H -r ${SS} ${PKG_DIR} |  cut -d: -f1

Shell script to Find & Replace a “string” Recursively

#!/bin/bash
# Author: Sagar PATIL

echo "Enter the FullPackage DIR path[/opt/IBM/WebSphere/AppServer/profiles/Profile01/Dmgr/config/cells......] "
read PKG_DIR
echo "Enter the Source Pattern to be replaced "
read SS
echo "Enter the Target Pattern "
read TS
list=`find $PKG_DIR -type f -name '*.xml'`  # I am only searching for files with extn xml, to search all files please remove name '*.xml'
for file in ${list}
do
#in the below command colon is a separator
sed "s:"${SS}":"${TS}":g" ${file} > /tmp/temp.txt
echo "File " ${file}
echo "Source Pattern " ${SS}
echo "Target Pattern " ${TS}
mv /tmp/temp.txt ${file}
done

Leave a Reply

You must be logged in to post a comment.

Top of Page

Top menu