Saturday, 7 September 2013

Useful Unix Commands / Utilities

Utility name
Purpose
Command
Grep
Fetch Unix group &  userid
grep dba /etc/group
grep oracle /etc/passwd
chown
Changing ownership recursively & change ownership of a folder
chown -R oracle:oracle oracle
chown -h oracle:dba ias10220_<envname>
Awk
Fetch length of Unix Variable
env | grep ORACLE_HOME | awk '{print length($ORACLE_HOME)}'
find
Find by size and age of file
find . -type f -size +100000c -mtime 7 –print
find . -size +100000 -exec ls -l {} \;
find
Check and Find files of zero bytes and remove them
find . -size 0 -ctime  2 -ls  ### to check
find . -size 0 -ctime  2 -exec rm {} \; -print
find
Search for string dvp in $APPL_TOP
find $APPL_TOP/* -type f -exec grep -il 'dvp' {} \;
Lsof
Lsof
lsof processid
Pstree
Display a tree of processes
pstree -p 7051
sar
Cpu usage
sar –r 5 5
sed
Change same file name using sed
ls -l *.xml | awk '{print "sed -f env.sed " $9 " > ./new/" $9}' | sh -x
ftp
Ftpying a file via a script
ftp -n << FTP_CMDS
open $2
user
username passwd
put $1
rename $1 ready/$3/$1
bye
FTP_CMDS
kill
Kill processes with string dvp from  command line
ps -wwef | grep dvp | awk '{print "kill -9 " $2}' |  sh -x

How to check if the running distribution is OL or RedHat

$ cat /etc/issue.net | head -1
Oracle Linux Server release 5.9

$ rpm -qf /etc/redhat-release
enterprise-release-5-9.0.6

  
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.9 (Tikanga)