rasti.hil@hilandco.com +41 79 367-9677

Tuesday, 27 October 2009

Linux commands


Terminal - ps with parent/child process tree

ps auxf

10 files/dirs using disk
du -chs * | sort -rn | head

Find the largest file in a directory

find . -type f -iname "*.TMP" -printf '%s %p\n'| sort -nr | head -10

Calculate the directory contained number of files:

find . -maxdepth 1 -type f |wc -l

Using a loop with rm command to delete lot of files

 for i in *.py; do rm -f $i; done

cd $ORACLE_HOME
du -ak | sort -k1,1n
export folder=$ORACLE_HOME/Apache/Apache/logs
find $folder -name '*log*' -type f -mtime +2 | xargs ls -l
find $folder -name '*log*' -type f -mtime +2 | xargs rm

export folder=$ORACLE_HOME/j2ee/*/log/*/*
find $folder -type f -mtime +2 | xargs ls -l
find $folder -type f -mtime +2 | xargs rm

export folder=$ORACLE_HOME/discoverer/logs
find $folder -type f -mtime +2 | xargs ls -l
find $folder -type f -mtime +2 | xargs rm

export folder=$ORACLE_HOME/ldap/odi/log
find $folder -type f -mtime +2 | xargs ls -l
find $folder -type f -mtime +2 | xargs rm

export folder=$ORACLE_HOME/ldap/log
find $folder -type f -mtime +2 | xargs ls -l
find $folder -type f -mtime +2 | xargs rm


find . -type f -size +1000k | xargs ls -l

ps -ef | grep oracle | grep -v root | awk '{print $2}' | xargs kill

lsof -i -n -P | grep 1810

grep -i 'word' filename
grep 'string1 string2' filename
cat otherfile | grep 'something'
grep -r "word" /etc/

grep -c 'word' /path/to/file
grep -v bar /path/to/file
grep -l '192' *.log

putty login failed "No supported authentication methods left to try"

vi /etc/ssh/sshd_config

set PasswordAuthentication to yes

ARP cache contents arp -an

Track ARP traffic
tcpdump -n -i eth0 arp
tcpdump -c 3 -nni eth0:1 arp

Send ARP Reponse (gratuitous ARP response ) arping -q -c 3 -A -I eth0 192.168.1.11

kill -9 `pgrep -of soaMNGSRV_02`

vi -O foo.txt bat.txt


  • ctrl+z
  • bg
  • disown -h 
  • exit


  • Ctrl-z
  • jobs
  • bg %jobnum ( job %1 & )


DATE=$(date +%Y%m%d-%H%M%S)

list the process specific file
lsof /var/log/syslog

list the processes under a specified directory
lsof +D /var/log/

list the process with a string
lsof -c java

list the process with specific users ( exclude ^oracle )
lsof -u oracle

list by a specific process
lsof -p 1753

list pid
lsof -t java

list specific user and command string
lsof -u oracle -c java

list specific user and command string and belongs to user
lsof -u oracle -c java -a

list specific user ,command string and belongs to user, repeat
lsof -u oracle -c java -a -r5

list all the network (-i4 or -i6)
lsof -i

list particular port
lsof -i :7001

list all the TCP or UDP
lsof -i tcp; lsof -i udp;


Single port:
nc -zv 127.0.0.1 80

Multiple ports:
nc -zv 127.0.0.1 22 80 8080