<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post/5146/</link>
<title><![CDATA[分享平时工作中那些给力的shell命令]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Sat, 21 Apr 2012 07:11:25 +0000</pubDate> 
<guid>http://jackxiang.com/post/5146/</guid> 
<description>
<![CDATA[ 
	<br/>分享平时工作中那些给力的shell命令－－－（Notice: 蓝色部分为在网友孤风颠影基础上新增加内容）<br/> <br/>原帖地址为：http://yunhaozou.org/perl-shell/162.html<br/> <br/>1.显示消耗内存/CPU最多的10个进程<br/>ps aux &#124; sort -nk +4 &#124; tail<br/>ps aux &#124; sort -nk +3 &#124; tail<br/>——————————————————————————————————————————<br/>2.查看Apache的并发请求数及其TCP连接状态<br/>netstat -n &#124; awk ‘/^tcp/ &#123;++S[$NF]&#125; END &#123;for(a in S) print a, S[a]&#125;’<br/> <br/>——————————————————————————————————————————<br/>3.找出自己最常用的10条命令及使用次数（或求访问最多的ip数）<br/>sed -e ‘s/&#124; /&#92;n/g’ ~/.bash_history &#124;cut -d ‘ ‘ -f 1 &#124; sort &#124; uniq -c &#124; sort -nr &#124; head<br/>——————————————————————————————————————————<br/>4.日志中第10个字段表示连接时间，求平均连接时间<br/>cat access_log &#124;grep “connect cbp” &#124;awk ‘BEGIN&#123;sum=0;count=0;&#125;&#123;sum+=$10;count++;&#125;END&#123;printf(“sum=%d,count=%d,avg=%f&#92;n”,sum,count,<br/>sum/count)&#125;’<br/>——————————————————————————————————————————<br/>5.lsof命令<br/>lsof abc.txt 显示开启文件abc.txt的进程<br/>lsof -i :22 知道22端口现在运行什么程序<br/>lsof -c abc 显示abc进程现在打开的文件<br/>lsof -p 12 看进程号为12的进程打开了哪些文件<br/>——————————————————————————————————————————<br/>6.杀掉一个程序的所有进程<br/>pkill -9 httpd<br/>killall -9 httpd<br/>注意尽量不用-9，数据库服务器上更不能轻易用kill，否则造成重要数据丢失后果将不堪设想。<br/>——————————————————————————————————————————<br/>7.rsync命令（要求只同步某天的压缩文件，而且远程目录保持与本地目录一致）<br/>/usr/bin/rsync -azvR –password-file=/etc/rsync.secrets `find . -name “*$yesterday.gz” -type f ` storage@192.168.2.23::logbackup/13.21/<br/>——————————————————————————————————————————<br/>8.把目录下*.sh文件改名为*.SH<br/>find . -name “*.sh” &#124; sed ’s/&#92;(.*&#92;)&#92;.sh/mv &#92;0 &#92;1.SH/’ &#124;sh<br/>find . -name “*.sh” &#124; sed ’s/&#92;(.*&#92;)&#92;.sh/mv &amp; &#92;1.SH/’&#124;sh （跟上面那个效果一样）<br/>——————————————————————————————————————————<br/>9.ssh执行远程的程序，并在本地显示<br/>ssh -n -l zouyunhao 192.168.2.14 “ls -al /home/zouyunhao”<br/>——————————————————————————————————————————<br/>10. 直接用命令行修改密码<br/>echo “zouyunhaoPassword” &#124;passwd –stdin zouyunhao<br/>——————————————————————————————————————————<br/>ssh-keygen<br/>ssh-copy-id -i ~/.ssh/id_rsa.pub user@remoteServer<br/>——————————————————————————————————————————<br/>12.以http方式共享当前文件夹的文件<br/>$ python -m SimpleHTTPServer<br/>在浏览器访问http://IP:8000/即可下载当前目录的文件。<br/>——————————————————————————————————————————<br/>13.shell段注释<br/>:&lt;&lt;’echo hello,world!’<br/>——————————————————————————————————————————<br/>14.查看服务器序列号<br/>dmidecode &#124;grep “Serial Number” （查看机器其他硬件信息也可用这个命令）<br/>——————————————————————————————————————————<br/>15.查看网卡是否有网线物理连接<br/>/sbin/mii-tool<br/>——————————————————————————————————————————<br/>16.查看linux系统或者mysql错误码表示的意思，如查看13错误码表示的意思：<br/>perror 13<br/>——————————————————————————————————————————<br/>17.关于cpu个数<br/>查看逻辑cpu个数：cat /proc/cpuinfo &#124; grep “processor” &#124; wc -l<br/>查看物理cpu个数：cat /proc/cpuinfo &#124; grep “physical id” &#124; sort &#124; uniq &#124; wc -l<br/>查看每个物理cpu的核数cores：cat /proc/cpuinfo &#124; grep “cpu cores”<br/>如果所有物理cpu的cores个数加起来小于逻辑cpu的个数，则该cpu使用了超线程技术。查看每个物理cpu中逻辑cpu的个数：cat /proc/cpuinfo &#124; grep “siblings”<br/> <br/>——————————————————————————————————————————<br/>18.从格式不规范的日志中截取字符串<br/>perl -ne ’print “$1&#92;n” if /servletPath=(&#92;S+)/g’ test.log<br/>——————————————————————————————————————————<br/>19. 把所有的文件名含有空格的，把空格去掉<br/>find ./ -type f &#124; while read line;do echo $line&#124;grep -q &quot; &quot; &amp;&amp; &#92;mv &quot;$line&quot; $(echo $line&#124;sed &#039;s/ //g&#039;);done<br/>－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br/>20.把所有的文件夹的文件名含有空格的，把空格去掉<br/>find ./ -type d -name &#039;*&#039;&#124;while read file; do echo $file&#124;grep -q &quot; &quot; &amp;&amp; mv &quot;$file&quot; $(echo $file&#124;tr -d &#039; &#039;); done<br/> <br/>当文件名的末尾以空格结束时，就不能用命令行来实现，需要使用脚本：<br/> <br/>#!/bin/bash<br/>IFS=$&#039;&#92;n&#039;<br/>find ./ -type f &#124; while read line;do echo $line&#124;grep -q &quot; &quot; &amp;&amp; &#92;mv &quot;$line&quot; $(echo $line&#124;sed &#039;s/ //g&#039;);done<br/> <br/>－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br/> <br/>21.生成随机字符串：<br/> <br/># tr -dc _A-Z-a-z#$%^*-0-9 &lt;/dev/urandom &#124;head -c8<br/>chgSh^eJ<br/>或者<br/># mkpasswd -l 8 -d 1 -c 3 -C 2 -s 2<br/>G_ze3Hto<br/> <br/>－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br/> <br/>22.linux统计PCI插槽数量：<br/> <br/>[root@vcdog ~]# dmidecode &#124;grep -1 PCI<br/>ISA is supported<br/>PCI is supported<br/>PC Card (PCMCIA) is supported<br/>--<br/>System Slot Information<br/>Designation: PCI Slot J11<br/>Type: 32-bit PCI<br/>Current Usage: In Use<br/>--<br/>System Slot Information<br/>Designation: PCI Slot J12<br/>Type: 32-bit PCI<br/>Current Usage: In Use<br/>--<br/>System Slot Information<br/>Designation: PCI Slot J13<br/>Type: 32-bit PCI<br/>Current Usage: In Use<br/>--<br/>System Slot Information<br/>Designation: PCI Slot J14<br/>Type: 32-bit PCI<br/>Current Usage: Available<br/> <br/>－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br/> <br/> <br/>23. nmap探测远程主机的开放端口及操作系统:<br/># nmap -A -T4 192.168.1.28 //此处可以为主机名，域名，或主机IP地址<br/>Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2010-12-28 09:46 CST<br/>Interesting ports on bogon (192.168.1.29):<br/>Not shown: 1677 closed ports<br/>PORT STATE SERVICE VERSION<br/>135/tcp open msrpc Microsoft Windows RPC<br/>139/tcp open netbios-ssn<br/>445/tcp open microsoft-ds Microsoft Windows XP microsoft-ds<br/>MAC Address: 70:5A:B6:09:45:FA (Unknown)<br/>Device type: general purpose<br/>Running: Microsoft Windows NT/2K/XP<br/>OS details: Microsoft Widows XP SP2<br/>Service Info: OS: Windows<br/> <br/>－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br/>24.　linux下的文件去掉^M硬回车的方法：<br/><br/>（1）# cat test.txt &#124;tr -d &#039;^M&#039; &gt;test.new<br/>（2）.# sed -i &#039;s/^M//g&#039; test.txt <br/>（3）# dos2unix test.txt <br/>（4）在vi中用:%s/^M//g<br/>注意：这里的“^M”要使用“CTRL-V CTRL-M”生成，而不是直接键入“^M”。<br/> <br/>－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br/>25.删除文件中的所有空行：<br/>1.使用awk方法如下：<br/>[root@dg ~]# cat t.txt &#124; awk -F &#039;&#039; &#039;&#123;if($1!=null) print $0&#125;&#039;<br/>203.208.46.146 www.google.com<br/>223.208.46.146 www.google.com<br/>203.208.46.147 www.google.com.hk<br/>203.208.46.132 clients1.google.com<br/>203.208.46.149 mail.google.com<br/> <br/>2.sed方法如下：<br/>[root@dg ~]# sed &#039;/^$/d&#039; t.txt <br/>203.208.46.146 www.google.com<br/>223.208.46.146 www.google.com<br/>203.208.46.147 www.google.com.hk<br/>203.208.46.132 clients1.google.com<br/>203.208.46.149 mail.google.com<br/>203.208.46.161 chatenabled.mail.google.com<br/> <br/>3.awk方法如下：<br/>[root@dg ~]# awk &#039;NF&#039; t.txt <br/>203.208.46.146 www.google.com<br/>223.208.46.146 www.google.com<br/>203.208.46.147 www.google.com.hk<br/>203.208.46.132 clients1.google.com<br/>203.208.46.149 mail.google.com<br/>203.208.46.161 chatenabled.mail.google.com<br/> <br/>4.vim中删除空行如下：<br/>:g/^$/d<br/>203.208.46.146 www.google.com<br/>223.208.46.146 www.google.com<br/>203.208.46.147 www.google.com.hk<br/>203.208.46.132 clients1.google.com<br/>203.208.46.149 mail.google.com<br/>203.208.46.161 chatenabled.mail.google.com<br/>－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br/>26.获取内存条TYPE和SPEED的信息：<br/> <br/>#&nbsp;&nbsp;dmidecode &#124;grep -A 16 &quot;Memory Device&quot;&#124;grep -E &quot;Speed&#124;Type&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type: DDR2 FB-DIMM<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Speed: 667 MHz (1.5 ns)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type: DDR2 FB-DIMM<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Speed: 667 MHz (1.5 ns)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type: DDR2 FB-DIMM<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Speed: 667 MHz (1.5 ns)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type: DDR2 FB-DIMM<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Speed: 667 MHz (1.5 ns)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type: DDR2 FB-DIMM<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type: DDR2 FB-DIMM<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type: DDR2 FB-DIMM<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type: DDR2 FB-DIMM<br/>=================================================================<br/>（不断更新中...）<br/>本文出自 “vcdog&#039;s blog” 博客，请务必保留此出处http://255361.blog.51cto.com/245361/836976
]]>
</description>
</item><item>
<link>http://jackxiang.com/post/5146/#blogcomment63739</link>
<title><![CDATA[[评论] 分享平时工作中那些给力的shell命令]]></title> 
<author>hxngb8ef &lt;hvcm588@domozmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 15 May 2012 16:33:37 +0000</pubDate> 
<guid>http://jackxiang.com/post/5146/#blogcomment63739</guid> 
<description>
<![CDATA[ 
	楼主说得好，支持一下
]]>
</description>
</item>
</channel>
</rss>