Saturday, September 15, 2012

Few commands that can save your time

Here i am listing few commands that i am using. I am sure it will be helpful.

1. Create UML from PHP code. ( annoying and little bit hacky but works well :P) 

  • sudo phpuml ~/shiksha/trunk/LDB/controller/LDB_Server.php -f htmlnew -o ~/Desktop/ -x 1 -n ldb -m *.php6 -i .svn
  • sudo phpuml ~/shiksha/trunk/CodeIgniter/ -o ~/Desktop/ -x 1 -n Foo -m *.php6 -i .svn

2. VIM coomands
  • zz save and exit
  • ? search backword
  • p command for paste
  • ma mark then can use "d'a" to delte entire
  • y for copy [can do same y'a or yy ]
  • :split to open other file
  • CTRL ww to jump file
  • > move to right
  • ZZ save and exit
  • ZQ exit without save
  • :tabs - View a list of tabs that are open with the file names. Use the command ':tabs' and Vim will display a list of all the files in the tabs. The current window is shown by a ">" and a "+" is shown for any modifiable buffers.
  • :tabc - Close the current tab.
  • :tabnew - Open a new file for editing in a separate tab.
  • :tab split - Open the file in the current buffer in a new tab page.
  • :tabn - Switching to the next tab page.
  • :tabp - Switch to the previous tab page.
  • :tabr[ewind] - Go to the first tab page. You get the same effect when you use the :tabf[irst] command.
  • :tabo - Close all other tab pages.

3. PHP Codebase Reports

phploc --count-tests /usr/local/src/ezcomponents/trunk/Workflow
phpmd /path/to/source text codesize,unusedcode,naming
sudo php_beautifier -l "Pear()" svrSearch.php svrSearch_n.php
php_beautifier -l "Pear(add_header=apache) ArrayNested() ListClassFunction()" index.php index_new.php

4. SYSTEM INFO

  • netstat -antp | awk '{print $6}' | sort | uniq -c | sort -rn
  • netstat -antp | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | > sort -rn
  • ps -e -o vsz | awk '{size += $1}END{print(size)}'
  • iostat -x -d
  • vmstat 5
  • top -bn1
  • ps -auxf | sort -nr -k 4 | head -10
  • ps -auxf | sort -nr -k 3 | head -10
  • kill $(ps aux | grep 'MailQueueRecordsMass' | awk '{print $2}')
  • echo stats | nc 127.0.0.1 11211
  • watch "echo stats | nc 127.0.0.1 11211"
  • watch 'php -r '"'"'$m=new Memcache;$m->connect("127.0.0.1", 11211);print_r($m->getstats());'"'"
  • netstat -antp 
  • top -bn1 
  • free -m 
  • ps -e -o vsz | awk '{size += $1}END{print(size)}' 
  • mpstat -P ALL 5 
  • find /home/tmp/ -name '*.html' -print0 | xargs -0 rm -f
  • free -mto
  • top
While the output of the top command displayed, press F, which will display the following message and show all fields available for sorting, press n (which is for sorting the processes by Memory) and press enter. This will display the processes in the top output sorted by memory usage.
Current Sort Field: K for window 1:Def
Select sort field via field letter, type any other key to return

  • ps aux | more
  • ps axuf
  • ps U $USER
function psgrep ()
{
     ps aux | grep "$1" | grep -v 'grep'
}
function psterm ()
{
     [ ${#} -eq 0 ] && echo "usage: $FUNCNAME STRING" && return 0
     local pid
     pid=$(ps ax | grep "$1" | grep -v grep | awk '{ print $1 }')
     echo -e "terminating '$1' / process(es):\n$pid"
     kill -SIGTERM $pid
}

  • find ./ -type f -name \*.php -exec php -l {} \;
  • # how many mysql connections
  • netstat -n -a |grep 3306
  • ps ax | grep sshd
  • netstat -ln | grep 22
  • grep -ril john /root
  • find /etc -name "*mail*" [name start mail]
  • find / -type f -size +100M [ size more than 100 MB]
  • find . -mtime +60 [ more than 60 days]
  • find . –mtime -2 [ last 2 days]
  • cat file.txt > /dev/null [only error]
  • cat invalid-file-name.txt 2> /dev/null [only output no error]
  • find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
  • cat url-list.txt | xargs wget –c
  • /sbin/ifconfig -a
  • df -h
  • df -Tha
  • du -sh ~ 
  • find /var/log -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

4. SVN REPORT
java -jar statsvn.jar searchAgents/logfile.log searchAgents/ -output-dir svnreport/

5. SQL to get database table size 

SELECT TABLE_SCHEMA AS 'Database', TABLE_NAME AS 'Table', CONCAT(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2)," MB") AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like '%mailer%';
6. SVN
  • svn delete $( svn status | sed -e '/^!/!d' -e 's/^!//' ) 
  • svn add $( svn status | sed -e '/^?/!d' -e 's/^?//' ) 
  • svn resolve $( svn st | grep "^C" | awk '{print $2}' ) 
  • svn add * --force find ./ -type f -name \*.php -exec php -l {} \; 
  • find ./ -type f -name \*.php -exec php -l {} \; | grep "Errors parsing "; //-not -regex '.*/.svn/*.*' 
  • find . -name .svn -print0 | xargs -0 rm -rf find -type d -name '.svn' -exec rm -rfv {} \;
  • svn log | sed -n '/raviraj/,/-----$/ p' svn log -v --use-merge-history URL/branches/Branch01

No comments:

Post a Comment