Monday 21 March 2011

Useful UNIX Commands For DBA's

Most often than not you would find yourself looking for System specs like RAM, Disk, etc while troubleshooting certain issues or for that matter general maintenance. Here's a list of commands I find useful.

Physical Ram on Linux:. cat /proc/meminfo or free -m

Physical RAM on Solaris: /usr/sbin/prtconf | grep Memory or sar -r 5 10

Physical RAM on AIX: svmon -G

Check Swap Space: swap -l

CPU : cat /proc/cpuinfo

Check Disk: du -sk, df -hk

Checking I/O: iostat -c 2 10

Check system Resource Usage: vmstat 2 10

General system Performance: top or uptime

Unzip cpio or tar files: cpio -idmvc < filename , tar -xvf filenmae

Killing a Unix Process:
kill -9 or
kill -9 `ps -ef|grep -v ksh|grep |awk '{ print $2}'`


Find a file Cointaing the search word in Current Dir:

find . -exec grep "serach word" '{}' \; -print

Ports currently used:
 netstat -na|grep 

Delete files older than a timestamp:
find . -type f -mtime +15 -print -exec rm -f {} \  -> Could replace rm with ls
Based on access time:
find . -type f –atime +20 –print -exec rm -f {} \;

Script to find files greater than a Size threshold:

for i  in `find . -name "*.log*" -exec ls -1tr {} \;`
do
  #echo "Checking the size in current directory"
  size=`ls -ltr $i  | awk '{print $5}'`
  if [ $size -gt $THRESHOLD ];
    then
     echo "File \" $i \" is greater than the Treshold"
     ls -ltr $i
  fi
done

Some vi string commands:

:g/$/s//hello   -----append end of each line

:1,$ s/^/hello/ ----- start of each line

:g/ok/s//hi/gc-----replace ok with hi globally, c is optional that requires you to enter y or n to replace or not.

Refer: http://www.cs.colostate.edu/helpdocs/vi.html for additional help

Install a Linux Package:
rpm -ivh

To check if a Package is installed:
rpm -qa|grep

Check Hostname:
hostname -a

To configure Hostname :
Hostname

Check following for N/W Config:
/etc/hosts, /etc/sysconfig/network, /etc/sysconfig/network-scripts/ifcfg-eth0, /etc/resolv.conf

Start and Stop services in Linux: service network start/stop/restart -->network here is Service name




No comments:

Post a Comment