Wednesday 26 August 2009

My ~]# ./Shell One Liners

This is going to be a long list of some of the shell one liners that I have used at one time in my *nix life.

1. ps axho args | awk /ssh/'{print $1}'
2. for i in AIX*; do mv $i BSD${i:3}; done ## or u can use {i#AIX}
3. sed -i s/AIX/BSD/ BSD*
4. kill `ps aux | awk /$1/'{if ($3+0>'"$limit"') {print $2} }'`
5. for i in *.frm; do touch ${i%.frm}.{MYD,MYI}; done
6. awk '/^iface bar/,/^$/ {print}'
7. find /home/ -name '*:*' -exec rename s/:/-/ {} \;
8. sed '/^$/d' /path/to/currentfile | sed '1,8d' | sed 'N;$!P;$!D;$d' > /path/to/newfile
9. find /mytopdir -depth -type d -empty -exec rmdir {} \;
10. find . -type f -newermt 2007-06-07 ! -newermt 2007-06-08
11. find ./ -type f -ls |grep '19 Jun'
12. find . -type f -mtime $(( ( $(date +%s) - $(date -d '2010-06-25' +%s) ) / 60 / 60 / 24 - 1 ))
13. ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2}'
14. sed -i 's/StringA/StringB/g' ` grep -ril 'StringA' /homes/myhome/* ` 
15. find / -cmin -1440 -size +5000000c -print
16. for i in `ls /homes/`; do find /homes/$i/ -name "*R3D*" -mtime +730 -exec rm {} \;; done
17. cd /home/user && rename : _ *:*
18. for i in `find /home/user/ -name '*:*' -print`; do mv $i ${i//:/_}; done

Wednesday 19 August 2009

Handy reference to Linux process status codes

D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct ("zombie") process, terminated but not reaped by its parent.

For BSD formats and when the stat keyword is used, additional characters may
be displayed:
< high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ is in the foreground process group