Linux Performance & Troubleshooting
For Linux Performance & Troubeshooting, please refer to another post - Linux tips – Performance and Troubleshooting
Linux system tips
ls -lu(access time, like cat file) -lt(modification time, like vi, ls -l defaults to use this) -lc(change time, chmod), stat ./aa.txt <UTC>ctrl +z #bg and stopped%1 & #bg and running%1 #fgpgrep -flu oracle # processes owned by the user oraclewatch free -m #refresh every 2 secondspmap -x 30420 #memory mapping.ipcs -m #shared memorylsof –u oracle | grep <shmid> #shmid is from output of ipcs -m. lists the processes under the oracle user attached to the shared memory segmentstrace [-p <pid>] -s 200 <program>#attach to a process. -s 200 to make the maximum string size to print (the default is 32) to 200. Note that filenames are not considered strings and are always printed in full.openssl s_client -connect localhost:636 -showcerts #verify ssl certificates, or 443openssl x509 -in cacert.pem -noout -textopenssl x509 -in cacert.pem -noout -datesopenssl x509 -in cacert.pem -noout -purposeopenssl req -in robots.req.pem -text -verify -nooutlinux accouting #http://www.cyberciti.biz/tips/howto-log-user-activity-using-process-accounting.htmliptables tips #http://www.doxer.org/learn-linux/iptables-tips/wget and curl tips #http://www.doxer.org/learn-linux/wget-and-curl-tips/tipdump tips #http://www.doxer.org/learn-linux/tcpdump-tips/
Strings
ovm svr ls|sort -rn -k 4 #sort by column 4cat a1|sort|uniq -c |sort #SUSovm svr ls|uniq -f3 #skip the first three columns, this will list only 1 server per poolfor i in <all OVMs>;do (test.sh $i &);done #instead of using nohup &ovm vm ls|egrep “`echo testhost{0\|,1\|,2\|,3\|,4}|tr -d ‘[:space:]‘`”cat a|awk ‘{print $5}’|tr ‘\n’ ‘ ‘getopt #getopts is builtin, more on http://wuliangxx.iteye.com/blog/750940date -d ’1970-1-1 1276059000 sec utc’date -d ’2010-09-11 23:20′ +%sfind . -name ‘*txt’|xargs tar cvvf a.tarfind . -maxdepth 1for i in `find /usr/sbin/ -type f ! -perm -u+x`;do chmod +x $i;done #files that has no execute permisson for ownerfind ./* -prune -print #-prune,do not cascadefind . -fprint file #put result to filetar tvf a.tar –wildcards “*ipp*” #globbing patternstar xvf bfiles.tar –wildcards –no-anchored ‘b*’tar –show-defaultstar cvf a.tar –totals *.txt #show speedtar –append –file=collection.tar rock #add rock to collection.tartar –update -v -f collection.tar blues folk rock classical #only append new or updated ones, not replacetar –delete –file=collection.tar blues #not on tapestar -c -f archive.tar –mode=’a+rw’tar -C sourcedir -cf – . | tar -C targetdir -xf – #copy directoriestar -c -f jams.tar grape prune -C food cherry #-C,change dir, foot file cherry under foot directoryfind . -size -400 -print > small-filestar -c -v -z -T small-files -f little.tgztar -cf src.tar –exclude=’*.o’ src #multiple –exclude can be specifiedexpr 5 – 1rpm2cpio ./ash-1.0.1-1.x86_64.rpm |cpio -ivdeval $cmdexec menu.viewcards #same to .ls . | xargs -0 -i cp ./{} /etc #-i,use \n as separator, just like find -exec. -0 for space in filename. find -print0 use space to separate, not enter.(-i or -I {} for revoking filenames in the middle)ls | xargs -t -i mv {} {}.old #mv source should exclude /,or unexpected errors may occurmv –strip-trailing-slashes source destination
ls |xargs file /dev/fd/0 #replace -ls -l -I “*out*” #not include outfind . -type d |xargs -i du -sh {} |awk ‘$1 ~ /G/’find . -type f -name “*20120606″ -exec rm {} \; #do not need rm -rf. find . -type f -exec bash -c “ls -l ‘{}’” \;ps -ef|grep init|sed -n ’1p’cut -d ‘ ‘ -f1,3 /etc/mtab #first and third
seq 15 21 #print 15 to 21, or echo {15..21}seq -s” ” 15 21 #use space as separatorbash & expect tips #http://www.doxer.org/learn-linux/bash-expect-tips/general expect tips #http://www.doxer.org/learn-linux/general-expect-tips/general bash tips #http://www.doxer.org/learn-linux/general-bash-tips/