Tuesday, April 2, 2013

Unix know hows

As a DBA you are expected to know quite a few things about OS . This post intends to note down few things that every DBA comes across in day-day work.



$lsvg ---> on AIX to list out all the volume groups on server
$ vgdisplay --> on RHEL to list out all the volume groups
$lsvg -l vgname --> will list out the file systems part of the Volume group.

AIX
Total memory allocated --> lsattr -El sys0 | grep realmem (memory in KB)
or
prtconf -m

On linux
cat /proc/meminfo | grep MemTotal

Memory used of the total allocated-->
vmstat command will give the output
svmon -G
 svmon -GO unit=auto

find blocksize of a file system

$ dumpe2fs /dev/sda1 | grep 'Block size' ---> on RHEL


Finding network configuration--> lists all nic's, associated ip's & their status
/sbin/ifconfig -a

for finding the cpu usage
sar -u

for reading a file using vi but size of file is larger than default size of VI Editor.
vi -y newsize filename
example
vi -y 20000000 aler*g

find which files have been modified in the last few days
find location -mtime no_of_days
example--> lists the files that have been updated in last 2 days at the location /u01/app/oracle/product
find /u01/app/oracle/product -mtime 2

Comment all lines in a file
Open the file using 'vi' editor
Press Escape and type :1,$s/^/##/g
Hit return key

1,$s/^/##/g can be broken down as <------------ this can be understood as follows
1: To start from 1st line 
$s :To end at the last line
/^ : Search for the start of the line
/##:Replace with ##
/g: Replace all occurrences in this file (globally)


*** This happens quite a bit during house-keeping, to find out the largest files in a directory, specially where you have hundreds if not thousands of trace files.

du -ak | sort -n
or 
du -am | sort -n

In reverse order ( largest files to smallest.. )
du - ak | sort -nr

This one is handy to find old audit dumps & remove them>> go to audit dump location & run this below command
find . -name "*.aud" -mtime +600 -exec rm -rf {} \;


tar command
to create a tar file
tar cvf tar_file_name.tar dirname
above c --> create archive 
           v --> Verbose
           f --> following is the archive file name

To extract a tar file
tar xvf  tar_file_name.tar

To find sum of filesize of a particular pattern
SUM=0
for i in `ls -ls |grep FULL | nawk '{print $6}'`; do SUM=`expr $SUM + $i`; done
echo $SUM


To find the type of file system on linux
$ df -T 

Check the number of processors/cpu's in linux
$ grep processor /proc/cpuinfo

** to grep for a pattern involving spaces
for example you want to grep a line with Feb  6 in date
ls -ltr | grep "Feb  6"
please note that there are 2 spaces between "Feb" and "6"
for Feb 10
ls -ltr | grep "Feb 10"
only one single space

No comments:

Post a Comment