<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title>meisw's blog</title>
		<link>http://meisw.wdlinux.cn//</link>
		<description>工作,学习,生活,这里将会有一些记录.     备用域名:http://meisw.wdlinux.cn</description>
		<copyright>Copyright (C) 2004 Security Angel Team [S4T] All Rights Reserved.</copyright>
		<generator>SaBlog-X Version 1.6 Build 20080806</generator>
		<lastBuildDate>Sun, 20 Sep 2026 23:57:19 +0000</lastBuildDate>
		<ttl>30</ttl>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1076-1.html</guid>
			<title>避免同一shell运行多次</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;#!/bin/bash</p>
<div>LOCK_NAME=&quot;/tmp/checkft.lock&quot;</div>
<div>if ( set -o noclobber; echo &quot;$$&quot; &gt; &quot;$LOCK_NAME&quot;) 2&gt; /dev/null;</div>
<div>then</div>
<div>trap 'rm -f &quot;$LOCK_NAME&quot;; exit $?' INT TERM EXIT</div>
<div>&nbsp;</div>
<div>----</div>
<div>处理执行部分</div>
<div>----</div>
<div>rm -f $LOCK_NAME</div>
<div>trap - INT TERM EXIT</div>
<div>fi</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1076-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2019-08-08 22:58</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-750-1.html</guid>
			<title>sed的一些总结</title>
			<author>admin</author>
			<description><![CDATA[<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">在写一些常用的脚本中，经常会用到sed，但是这东西，不经常用，就会忘掉，现在记在这里，以后想找sed了就来这里看看。<br />
＊替换<br />
sed &lsquo;s/word1/word2/2&prime; file 将第2行中的word1替换为word2<br />
sed &lsquo;s/word1/word2/g&rsquo; file word1全局替换为word2<br />
sed -n &lsquo;s/word1/word2/p&rsquo; file 全局替换并打印<br />
sed &lsquo;s/word1/word2/w test&rsquo; file 全局替换并写入文件test<br />
sed &lsquo;s/\/bin\/bash/\/bin\/sh/&rsquo;	/etc/passwd 路径替换 特殊字符需要转义<br />
sed &lsquo;s!/bin/bash!/bin/sh!&rsquo;	 /etc/passwd 同上 感叹号被用作定界符<br />
sed &lsquo;ns/word1/word2/&rsquo;	 file 指定替换file文件中的第n行<br />
sed &lsquo;m,ns/word1/word2&prime;	 file 指定替换file文件中的第m到n行<br />
sed &lsquo;n,$s/word1/word2&prime;	 file 指定替换file文件中的第n到最后一行<br />
sed &lsquo;/word1/s/bash/sh/&rsquo;	 file 指定替换出现word1行的bash替换为sh<br />
sed &lsquo;n{<br />
&gt;s/word1/word2<br />
&gt;s/word3/word4<br />
}&rsquo; file	 指定替换第n行中的word1为word2 word3为word4<br />
sed &lsquo;s/word1/word2/;s/word3/word4/&rsquo;	file 同上<br />
sed &lsquo;n,${<br />
&gt;s/word1/word2<br />
&gt;s/word3/word4<br />
}&rsquo; file	 指定替换从第n开始到最后一行结束的word1为word2 word3为word4<br />
sed -e &lsquo;n,$s/word1/word2/;s/word3/word4/&rsquo; file 同上<br />
＊删除<br />
sed &lsquo;d&rsquo; file	 清空所有数据流（不是清空file文件内容）<br />
sed &lsquo;nd&rsquo;	file	 删除第n行<br />
sed &lsquo;m,nd&rsquo; file	删除第m到n行<br />
sed &lsquo;n,$d&rsquo; file	删除从n到最后一行<br />
sed &lsquo;/word1/d&rsquo; file 删除匹配word1的行</p>
<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">＊插入<br />
sed &lsquo;nirhel007&prime; file 将rhel007插入到第n行之前<br />
sed &lsquo;nathis is a test&rsquo;	file 将this is a test 插入到第n行之后<br />
sed &lsquo;$irhel007&prime; file	 插入到最后一行之前<br />
sed &lsquo;$arhel007&prime; file	 插入到最后一行之后</p>
<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">＊更改<br />
sed &lsquo;ncthis is a test&rsquo; file	将第n行更改为this is a test<br />
sed &lsquo;/this is a test/cthat is a test&rsquo; file 匹配更改</p>
<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">＊变换<br />
sed &lsquo;y/123/456/&rsquo; test<br />
匹配修改 1－4，2－5，3－6 单个字符进行全局匹配</p>
<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">＊打印<br />
sed -n &lsquo;/word/p&rsquo; file 全局匹配打印<br />
sed -n &lsquo;m,np&rsquo; file 打印m到n行<br />
sed &lsquo;=&rsquo; file	 打印行号<br />
sed -n &lsquo;l&rsquo;	file 打印不可打印的ANSIC字符<br />
sed -n &lsquo;np&rsquo;	file	 打印第n行<br />
sed -n &lsquo;$p&rsquo;	file	 打印最后一行</p>
<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">＊文件操作<br />
sed &lsquo;m,nw test&rsquo; file	 将file的m到n行写入到test中<br />
sed -n &lsquo;/word/w test&rsquo; file 匹配将包含word字符的写入test文件<br />
sed &lsquo;nr test&rsquo; file 将test文件中的内容写入file文件的第n行之后<br />
sed &lsquo;/word/r test&rsquo; file	 将test文件中的内容匹配到word内容之后<br />
sed &lsquo;$r test&rsquo;	 file	 将test文件中的内容追加到file的最后<br />
sed -n &lsquo;{<br />
1!G<br />
h<br />
$p<br />
}&rsquo; file	 行逆序<br />
sed -n &lsquo;s/cat/&rdquo;cat&rdquo;/&rsquo; file 给文本中的cat增加双引号<br />
sed -n &lsquo;s/.at/&rdquo;&amp;&rdquo;/g&rsquo; file	给文本中的.at的原单词上增加双引号<br />
sed &lsquo;G&rsquo;	file 增加一行空行<br />
sed &lsquo;$!G&rsquo; file	 在文本的最后一行不再增加空行<br />
sed &lsquo;/^$/d;$!G&rsquo;	file	文本中的空行不增加行距<br />
sed &lsquo;=&rsquo; file	行计数<br />
sed &lsquo;=&rsquo; file | sed &lsquo;N;s/\n/ /&rsquo; 计数和行在同一行上<br />
sed -n &lsquo;s/&lt;[^&gt;]*&gt;//g；/^$/d&rsquo; file	去除html中的标签和空行</p>
<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">＊sed正则表达式<br />
1. .*{}[]^$\+?|	 这些特殊的字符需要用\转义<br />
2.	定位符<br />
sed -n &lsquo;/^test/p&rsquo; file 匹配test开头的行<br />
sed -n &lsquo;/test$/p&rsquo;	file	 匹配test结尾的行<br />
sed -n &lsquo;/^this is a test$/p&rsquo; 匹配以test开头和结尾的行<br />
sed -n &lsquo;/^$/d&rsquo;	 file	 去掉空行<br />
3 点字符<br />
sed -n &lsquo;/.li/p&rsquo; file 匹配除了换行之外的所有字符<br />
4 字符类<br />
［］代表或者的意思<br />
sed -n &lsquo;/[ch]at/p&rsquo; file 匹配hat或者cat的单词<br />
sed -n &lsquo;/[Yy][Ee][Ss]/p&rsquo; 匹配任何形式的yes<br />
sed -n &lsquo;/[c-h]at/p&rsquo;	file<br />
sed -n &lsquo;/[a-ch-m]/p&rsquo;	file	匹配a-c,h-m开头的单词<br />
sed -n &lsquo;/^[0-9][0-9][0-9][0-9][0-9][0-9]$/p&rsquo;	匹配邮编,电话<br />
5 否定字符类<br />
sed -n &lsquo;/[^ch]at/p&rsquo;	 不匹配以cat和hat开头的单词<br />
sed -n &lsquo;/cat/!p&rsquo;	 不匹配匹配cat的行<br />
6 *	前面的字符不出现或者出现多次</p>
<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">&nbsp;</p>
<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">-------------------------------</p>
<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">搜索并替换</p>
<p style="border-width: 0px; font: 13px/20px Arial, Helvetica, sans-serif; margin: 6px 0px 10px; padding: 0px; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical-align: baseline; white-space: normal; outline-width: 0px; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); border-image: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">sed -i '/memory_limit/s/128/64/' /www/wdlinux/etc/php.ini</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-750-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2012-10-25 12:28</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-720-1.html</guid>
			<title>awk e1</title>
			<author>admin</author>
			<description><![CDATA[<p>awk '$2~/url/{a+=$3}END{print $a}' filename</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-720-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2012-08-01 11:35</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-604-1.html</guid>
			<title>shell awk 去除空格</title>
			<author>admin</author>
			<description><![CDATA[<p>awk -F ':' '{gsub(/^[ \t]+/,&quot;&quot;,$2);print $2}' | tr &quot;\n&quot; &quot;|&quot;</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-604-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2011-09-01 15:30</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-422-1.html</guid>
			<title>shell简单的对字符串进行加解密(转)</title>
			<author>admin</author>
			<description><![CDATA[<table style="width: 100%; table-layout: fixed">
    <tbody>
        <tr>
            <td>
            <div id="blog_text" class="cnt">
            <p>好久没来了,为了表示我还活着,贴一段自己写的一段代码:</p>
            <p>#!/bin/sh<br />
            ###################################################################<br />
            # 程序名称:SecuEncrypt.sh<br />
            # 功能简述:对字符串进行加解密<br />
            # 数据流向:<br />
            # 传输方式:<br />
            # 配置文件:<br />
            # 配置说明:<br />
            # 编 写 人:jlwang<br />
            # 编写日期:2010-12-09<br />
            # 修改记录:<br />
            ###################################################################</p>
            <p>SPLIT_CHAR='&amp;'</p>
            <p>USAGE()<br />
            {<br />
            echo &quot;Usage:&quot;<br />
            echo &quot;加密:SecuEncrypt.sh 0 [message]&quot;<br />
            echo &quot;解密:SecuEncrypt.sh 1 [message]&quot;<br />
            }</p>
            <p>#加密<br />
            Encrypt()<br />
            {<br />
            &nbsp;Message=$1<br />
            &nbsp;#echo $Message<br />
            &nbsp;MessageLen=`echo $Message|awk '{print length($0)}'`<br />
            &nbsp;AscMessage=&quot;&quot;<br />
            &nbsp;i=1<br />
            &nbsp;while [ $i -le $MessageLen ]<br />
            &nbsp;do<br />
            &nbsp;&nbsp;iChar=`expr substr &quot;$Message&quot; $i 1`<br />
            &nbsp;&nbsp;let iChar=`printf &quot;%d&quot; &quot;'$iChar&quot;`+100<br />
            &nbsp;&nbsp;AscMessage=$AscMessage$iChar<br />
            &nbsp;&nbsp;let i=$i+1<br />
            &nbsp;done<br />
            &nbsp;#echo $AscMessage</p>
            <p>&nbsp;MessageLen=`echo $AscMessage|awk '{print length($0)}'`<br />
            &nbsp;let iCount=$MessageLen/10<br />
            &nbsp;i=0<br />
            &nbsp;while [ $i -le $iCount ]<br />
            &nbsp;do<br />
            &nbsp;&nbsp;let j=$i*10+1<br />
            &nbsp;&nbsp;MTEMP=`expr substr &quot;$AscMessage&quot; $j 10`<br />
            &nbsp;&nbsp;#echo $MTEMP<br />
            &nbsp;&nbsp;if [[ -n $MTEMP ]]; then</p>
            <p>&nbsp;&nbsp;&nbsp;MTEMP=&quot;1&quot;$MTEMP<br />
            &nbsp;&nbsp;&nbsp;MTEMP=`echo $MTEMP|awk '{printf &quot;%x&quot;,$0}'`<br />
            &nbsp;&nbsp;&nbsp;if [ $i -ne 0 ]; then<br />
            &nbsp;&nbsp;&nbsp;&nbsp;HexMessage=$HexMessage$SPLIT_CHAR$MTEMP<br />
            &nbsp;&nbsp;&nbsp;else<br />
            &nbsp;&nbsp;&nbsp;&nbsp;HexMessage=$HexMessage$MTEMP<br />
            &nbsp;&nbsp;&nbsp;fi<br />
            &nbsp;&nbsp;fi<br />
            &nbsp;&nbsp;let i=$i+1<br />
            &nbsp;done</p>
            <p>&nbsp;echo $HexMessage<br />
            }</p>
            <p>#解密<br />
            NonEncrypt()<br />
            {<br />
            &nbsp;Message=$1<br />
            &nbsp;AscMessage=&quot;&quot;<br />
            &nbsp;ResultMsg=&quot;&quot;<br />
            &nbsp;Message=`echo $Message | awk -F $SPLIT_CHAR '{print $0}' | sed &quot;s/$SPLIT_CHAR/ /g&quot;`<br />
            &nbsp;for list in $Message<br />
            &nbsp;do<br />
            &nbsp;&nbsp;TMP=`echo $((16#$list))`<br />
            &nbsp;&nbsp;TMP=`echo $TMP|awk '{print substr($0,2,length($0))}'`<br />
            &nbsp;&nbsp;AscMessage=$AscMessage$TMP<br />
            &nbsp;done<br />
            &nbsp;#echo $AscMessage<br />
            &nbsp;MessageLen=`echo $AscMessage|awk '{print length($0)}'`<br />
            &nbsp;let iCount=$MessageLen/3<br />
            &nbsp;i=0<br />
            &nbsp;while [ $i -lt $iCount ]<br />
            &nbsp;do<br />
            &nbsp;&nbsp;let j=$i*3+1<br />
            &nbsp;&nbsp;MTEMP=`expr substr &quot;$AscMessage&quot; $j 3`<br />
            &nbsp;&nbsp;let MTEMP=$MTEMP-100<br />
            &nbsp;&nbsp;MTEMP=`echo $MTEMP|awk '{printf &quot;%c&quot;,$0}'`<br />
            &nbsp;&nbsp;ResultMsg=$ResultMsg$MTEMP<br />
            &nbsp;&nbsp;let i=$i+1<br />
            &nbsp;done</p>
            <p>&nbsp;echo $ResultMsg<br />
            }</p>
            <p>if [ $# -ne 2 ]; then<br />
            &nbsp;USAGE<br />
            &nbsp;exit -1<br />
            fi</p>
            <p>WORKTYPE=$1<br />
            MESSAGE=$2<br />
            if [ $WORKTYPE -eq 0 ]; then<br />
            &nbsp;ReturnMessage=`Encrypt $MESSAGE`<br />
            &nbsp;echo $ReturnMessage<br />
            else if [ $WORKTYPE -eq 1 ]; then<br />
            &nbsp;ReturnMessage=`NonEncrypt $MESSAGE`<br />
            &nbsp;echo $ReturnMessage<br />
            else<br />
            &nbsp;USAGE<br />
            &nbsp;exit -1<br />
            &nbsp;&nbsp;&nbsp;&nbsp; fi<br />
            fi</p>
            <p>运行结果：</p>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<p><img src="http://hiphotos.baidu.com/wangjingliu/pic/item/86b9b54474efe002510ffe95.jpg" alt="" /></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-422-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2011-06-10 20:48</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-421-1.html</guid>
			<title>用shell将时间字符串与时间戳互转</title>
			<author>admin</author>
			<description><![CDATA[<p><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">在shell中，字符串转换为时间戳可以这样做：</span></span></p>
<p>&nbsp;</p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="color: #00f"><span style="font-size: 14px">date -d &quot;2010-10-18 00:00:00&quot; +%s</span><br />
</span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">输出形如：</span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="color: #00f"><span style="font-size: 14px">1287331200</span></span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">其中，-d参数表示显示指定的字符串所表示的时间，+%s表示输出时间戳。</span></span></p>
<p><font class="Apple-style-span" color="#ffffff" face="arial, helvetica, sans-serif"><span style="line-height: 20px; font-size: 14px" class="Apple-style-span"><br />
</span></font></p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px" class="Apple-style-span">而时间戳转换为字符串可以这样做：</span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="color: rgb(0,0,255)"><span style="font-size: 14px">date -d @1287331200</span><br />
</span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">输出形如：</span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="color: rgb(0,0,255)"><span style="font-size: 14px">Mon Oct 18 00:00:00 CST 2010</span></span></span></p>
<p style="font-family: Simsun; color: rgb(0,0,0); font-size: medium"><span style="font-family: arial, helvetica, sans-serif"><span style="line-height: 20px; color: rgb(255,255,255); font-size: 14px" class="Apple-style-span"><font face="">文章来源：http://www.codelast.com/</font></span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">如果要转换成&ldquo;<span style="color: #00f">2010-10-18 00:00:00</span>&rdquo;这种形式的时间戳，则这样做：</span></span></p>
<p><span style="color: #00f"><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">date -d &quot;1970-01-01 UTC 1287331200 seconds&quot; &quot;+%F %T&quot;</span></span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">输出形如：</span></span></p>
<p><span style="color: #00f"><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">2010-10-18 00:00:10</span></span></span></p>
<p>&nbsp;</p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">再多废话一句，如果只要输出日期，不要时间，则去掉 %T 就可以了：</span></span></p>
<p style="font-family: Simsun; color: rgb(0,0,0); font-size: medium"><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px"><span style="color: rgb(0,0,255)"><font face="">date -d &quot;1970-01-01 UTC 1287331200 seconds&quot; +%F</font></span></span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">输出形如：</span></span></p>
<p><span style="color: rgb(0,0,255)"><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 14px">2010-10-18</span></span></span></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-421-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2011-06-10 20:47</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-416-1.html</guid>
			<title>linux bash shell中获取本机ip地址的方法</title>
			<author>admin</author>
			<description><![CDATA[<p><font face="Verdana"><strong>方法一：</strong></font></p>
<p><font face="Verdana">/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d &quot;addr:&quot; </font></p>
<p>or</p>
<p><font face="Verdana"><font face="Verdana">/sbin/ifconfig</font>|sed -n '/inet addr/s/^[^:]*:\([0-9.]\{7,15\}\) .*/\1/p'</font></p>
<p>&nbsp;</p>
<p><strong>方法二：</strong>&nbsp;</p>
<p align="left">local_host=&quot;`hostname --fqdn`&quot;</p>
<p align="left">local_ip=`host $local_host <font face="Verdana">2&gt;/dev/null</font>&nbsp;| awk '{print $NF}'`</p>
<p align="left">&nbsp;</p>
<p align="left"><strong>方法三：</strong></p>
<p align="left">local_host=&quot;`hostname --fqdn`&quot;</p>
<p align="left"><font face="Verdana">nslookup -sil $local_host <font face="Verdana">2&gt;/dev/null</font>&nbsp;| grep Address: | sed '1d' | sed 's/Address://g'</font></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-416-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2011-06-02 23:39</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-395-1.html</guid>
			<title>判断是否为数字</title>
			<author>admin</author>
			<description><![CDATA[<p>if [[ &quot;$1&quot; =~ &quot;^[0-9]+$&quot; ]] ;then</p>
<p>&nbsp;</p>
<p>TEST=`echo $num|sed 's/[0-9]//g'`<br />
if [ &quot;$TEST&quot; ！= &quot;&quot; ]</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-395-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2011-04-03 21:35</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-393-1.html</guid>
			<title>常用shell命令</title>
			<author>admin</author>
			<description><![CDATA[<p>1 # 替换标识符下一行的内容&nbsp;</p>
<p><br />
2 sed -e '/zone &quot;hexun.com&quot; IN {/,+1s/slave/master/' *.conf&nbsp;</p>
<p>3 # 删除标识行的下5行&nbsp;</p>
<p>4 sed -i -e '/also-notify {/,+5d' *.conf&nbsp;</p>
<p>5 # 在文件开头添加内容&nbsp;</p>
<p>6&nbsp; perl -i -pe 's&lt;^&gt;&lt;ZONE };\n};\n none; { named.60.28.251?;\n\tallow-update ?data master;\n\tfile \{\n\ttype IN ?251.28.60.in-addr.arpa? named.root?;\n}\nzone hint;\n\tfile {\n\ttype in ?.?&gt;g if $.==1' $i</p>
<p>2.awk 分析apache日志<br />
总流量</p>
<p>&nbsp;<br />
1 awk -F '&quot;' '{print $3}' /opt/lampp/logs/access_log | awk '{sum+=$2};END {print sum}'</p>
<p>访问次数前十的ip</p>
<p>&nbsp;<br />
1 awk '{++S[$1]} END {for(a in S) print a,S[a]}' /opt/lampp/logs/access_log | sort -k2 -n -r | head</p>
<p>访问次数前十的连接</p>
<p>&nbsp;<br />
1 awk&nbsp; -F '&quot;'&nbsp; '{print $2}' /opt/lampp/logs/access_log | sort | uniq -c | sort -k1 -n -r | head -20</p>
<p>1.</p>
<p>&nbsp;<br />
01 netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'</p>
<p>02 发现系统存在大量TIME_WAIT状态的连接，通过调整内核参数解决，&nbsp;</p>
<p>03 vi /etc/sysctl.conf&nbsp;</p>
<p>04 编辑文件，加入以下内容：&nbsp;</p>
<p>05 net.ipv4.tcp_syncookies = 1&nbsp;</p>
<p>06 net.ipv4.tcp_tw_reuse = 1&nbsp;</p>
<p>07 net.ipv4.tcp_tw_recycle = 1&nbsp;</p>
<p>08 net.ipv4.tcp_fin_timeout = 30&nbsp;</p>
<p>09&nbsp;&nbsp;&nbsp;</p>
<p>10 然后执行 /sbin/sysctl -p 让参数生效。&nbsp;</p>
<p>11 net.ipv4.tcp_syncookies = 1 表示开启SYN Cookies。当出现SYN等待队列溢出时，启用cookies来处理，可防范少量SYN攻击，默认为0，表示关闭；&nbsp;</p>
<p>12 net.ipv4.tcp_tw_reuse = 1 表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接，默认为0，表示关闭；&nbsp;</p>
<p>13 net.ipv4.tcp_tw_recycle = 1 表示开启TCP连接中TIME-WAIT sockets的快速回收，默认为0，表示关闭。&nbsp;</p>
<p>14 net.ipv4.tcp_fin_timeout 修改系統默认的 TIMEOUT 时间</p>
<p>1.按内存从大到小排列进程:<br />
ps -eo &ldquo;%C : %p : %z : %a&rdquo;|sort -k5 -nr</p>
<p>2.查看当前有哪些进程；查看进程打开的文件:<br />
ps -A ；lsof -p PID</p>
<p>3.获取当前IP地址（从中学习grep,awk,cut的作用）<br />
ifconfig eth0 |grep &ldquo;inet addr:&rdquo; |awk &lsquo;{print $2}&rsquo;|cut -c 6-</p>
<p>4.统计每个单词出现的频率，并排序<br />
awk &lsquo;{arr[$1]+=1 }END{for(i in arr){print arr&rdquo;\t&rdquo;i}}&rsquo; 文件名 | sort -rn</p>
<p>5.显示10条最常用的命令<br />
sed -e &ldquo;s/| /\n/g&rdquo; ~/.bash_history | cut -d &lsquo; &lsquo; -f 1 | sort | uniq -c | sort -nr | head</p>
<p>6.杀死Nginx进程(杀死某一进程)<br />
ps -ef|grep -v grep |grep nginx|awk &lsquo;{print $2}&rsquo; 或<br />
for i in `ps aux | grep nginx | grep -v grep | awk {&lsquo;print $2&prime;}` ; do kill $i; done</p>
<p>7.列出当前文件夹目录大小，以G，M，K显示。<br />
du -b &ndash;max-depth 1 | sort -nr | perl -pe &lsquo;s{([0-9]+)}{sprintf&rdquo;%.1f%s&rdquo;, $1&gt;=2**30? ($1/2**30, &ldquo;G&rdquo;): $1&gt;=2**20? ($1/2**20, &ldquo;M&rdquo;):$1&gt;=2**10? ($1/2**10, &ldquo;K&rdquo;): ($1, &ldquo;&rdquo;)}e&rsquo;</p>
<p>shaw答案 ：du -hs $(du -sk ./`ls -F |grep /` |sort -nr |awk &lsquo;{print $NF}&rsquo;)<br />
也可 以实现，不过不是特别完美。但好记。</p>
<p>8.清空linux buffer cache<br />
sync &amp;&amp; echo 3 &gt; /proc/sys/vm/drop_caches</p>
<p>9.将当前目录文件名全部转换成小写<br />
for i in *; do mv &ldquo;$i&rdquo; &ldquo;$(echo $i|tr A-Z a-z)&rdquo;; done</p>
<p>10.消除vim中的^M的几种方法<br />
1)dos2uninx filename<br />
2)sed -e &lsquo;s/^M//&rsquo; filename<br />
3)vim中 :s/^M//gc<br />
4)col -bx &lt; dosfile &gt; newfile<br />
5)tr -s &ldquo;&rdquo; &ldquo;\n&rdquo; &lt; file &gt; newfile</p>
<p>11. 清除所有arp缓存<br />
arp -n|awk &lsquo;/^[1-9]/ {print &ldquo;arp -d &ldquo;$1}&rsquo;|sh</p>
<p>12. 绑定已知机器的arp地址<br />
cat /proc/net/arp | awk &lsquo;{print $1 &rdquo; &rdquo; $4}&rsquo; |sort -t. -n +3 -4 &gt; /etc/ethers</p>
<p>用killall能够杀死同一个可执行文件的所有进程，但是我要杀死用php执行的php文件进程中的某些，就不好做了，在网上搜了下发现了这个，挺好用：</p>
<p>killprog=`ps -ef|grep -E &ldquo;XXXXXXX&rdquo; | grep -v grep | awk &lsquo;{print $2} &lsquo;` kill $killprog</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-393-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2011-03-31 15:09</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-257-1.html</guid>
			<title>shell</title>
			<author>admin</author>
			<description><![CDATA[<p>shell 特殊的变量<br />
$!&nbsp; 代表最后执行的后台命令的PID<br />
$?&nbsp; 记录着最后退出的状态<br />
$#&nbsp; 记录着传入的参数个数<br />
$@&nbsp; 为所有参数列表，不受IFS控掉<br />
$*&nbsp; 所有参数列表 受IFS控制<br />
$$&nbsp; 进程标识号<br />
$-&nbsp; 使用set及执行时传递给shell的标志位<br />
$_ 之前命令的最后一个参数 <br />
$0&nbsp; 为程序名称<br />
$1&nbsp; 为第一个参数 位置参数 #1<br />
$2&nbsp; 为第二个参数，以下类推<br />
PS1 为提示符，可进行设置 PS1=&quot;[\u@\h \W]\$&quot;<br />
PS2 为换行时的那个符号如 aa '换行后默认会出现&gt;我们可以进行修改 PS2=''换成你喜欢的<br />
IFS 为变量的分隔符，默认是空格<br />
${10} 位置参数 #10 <br />
${#*} 传递到脚本中的命令行参数的个数 <br />
${#@} 传递到脚本中的命令行参数的个数</p>
<p><br />
文件状态测试<br />
-b filename : 当filename 存在并且是块文件时返回真(返回0)<br />
-c filename : 当filename 存在并且是字符文件时返回真<br />
-d pathname : 当pathname 存在并且是一个目录时返回真<br />
-e pathname : 当由pathname 指定的文件或目录存在时返回真<br />
-f filename : 当filename 存在并且是正规文件时返回真<br />
-g pathname : 当由pathname 指定的文件或目录存在并且设置了SGID 位时返回真<br />
-h filename : 当filename 存在并且是符号链接文件时返回真 (或 -L filename)<br />
-k pathname : 当由pathname 指定的文件或目录存在并且设置了&quot;粘滞&quot;位时返回真<br />
-p filename : 当filename 存在并且是命名管道时返回真<br />
-r pathname : 当由pathname 指定的文件或目录存在并且可读时返回真<br />
-s filename : 当filename 存在并且文件大小大于0 时返回真<br />
-S filename : 当filename 存在并且是socket 时返回真<br />
-t fd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 当fd 是与终端设备相关联的文件描述符时返回真<br />
-u pathname : 当由pathname 指定的文件或目录存在并且设置了SUID 位时返回真<br />
-w pathname : 当由pathname 指定的文件或目录存在并且可写时返回真<br />
-x pathname : 当由pathname 指定的文件或目录存在并且可执行时返回真<br />
-O pathname : 当由pathname 存在并且被当前进程的有效用户id 的用户拥有时返回真(字母O 大写)<br />
-G pathname : 当由pathname 存在并且属于当前进程的有效用户id 的用户的用户组时返回真<br />
file1 -nt file2 : file1 比file2 新时返回真<br />
file1 -ot file2 : file1 比file2 旧时返回真<br />
举例: if [ -b /dev/hda ] ;then echo &quot;yes&quot; ;else echo &quot;no&quot;;fi // 将打印 yes<br />
test -c /dev/hda ; echo $? // 将打印 1 表示test 命令的返回值为1，/dev/hda 不是字符设备<br />
[ -w /etc/passwd ]; echo $? // 查看对当前用户而言，passwd 文件是否可写</p>
<p><br />
测试时逻辑操作符<br />
-a 逻辑与，操作符两边均为真，结果为真，否则为假。<br />
-o 逻辑或，操作符两边一边为真，结果为真，否则为假。<br />
!&nbsp; 逻辑否，条件为假，结果为真。<br />
举例: [ -w result.txt -a -w score.txt ] ;echo $? // 测试两个文件是否均可写<br />
&nbsp;<br />
常见字符串测试<br />
-z string&nbsp;&nbsp;&nbsp; : 字符串string 为空串(长度为0)时返回真<br />
-n string&nbsp;&nbsp;&nbsp; : 字符串string 为非空串时返回真<br />
str1 = str2&nbsp; : 字符串str1 和字符串str2 相等时返回真<br />
str1 != str2 : 字符串str1 和字符串str2 不相等时返回真<br />
str1 &lt; str2&nbsp; : 按字典顺序排序，字符串str1 在字符串str2 之前<br />
str1 &gt; str2&nbsp; : 按字典顺序排序，字符串str1 在字符串str2 之后<br />
举例: name=&quot;zqf&quot;; [ $name = &quot;zqf&quot; ];echo $? // 打印 0 表示变量name 的值和字符串&quot;zqf&quot;相等<br />
&nbsp;<br />
常见数值测试<br />
int1 -eq int2 : 如果int1 等于int2，则返回真<br />
int1 -ne int2 : 如果int1 不等于int2，则返回真<br />
int1 -lt int2 : 如果int1 小于int2，则返回真<br />
int1 -le int2 : 如果int1 小于等于int2，则返回真<br />
int1 -gt int2 : 如果int1 大于int2，则返回真<br />
int1 -ge int2 : 如果int1 大于等于int2，则返回真<br />
举例: x=1 ; [ $x -eq 1 ] ; echo $? // 将打印 0 表示变量x 的值等于数字1<br />
x=a ; [ $x -eq &quot;1&quot; ] // shell 打印错误信息 [: a: integer expression expected</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-257-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2010-06-02 22:34</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-226-1.html</guid>
			<title>SHELL参数介绍</title>
			<author>admin</author>
			<description><![CDATA[<p>如同ls 命令可以接受目录等作为它的参数一样，在shell编程时同样可以使用参数。Shell有位置参数和内部参数。<br />
　　1、 位置参数<br />
　　由系统提供的参数称为位置参数。位置参数的值可以用$N得到，N是一个数字，如果为1，即$1.类似C语言中的数组，Linux会把输入的命令字符串分段并给每段进行标号，标号从0开始。第0号为程序名字，从1开始就表示传递给程序的参数。如$0表示程序的名字，$1表示传递给程序的第一个参数，以此类推。<br />
　　2、 内部参数<br />
　　上述过程中的$0是一个内部变量，它是必须的，而$1则可有可无。和$0一样的内部变量还有以下几个。<br />
　　$# ----传递给程序的总的参数数目<br />
　　$? ----上一个代码或者shell程序在shell中退出的情况，如果正常退出则返回0，反之为非0值。<br />
　　$* ----传递给程序的所有参数组成的字符串。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$n ----表示第几个参数，$1 表示第一个参数，$2 表示第二个参数 ...&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $0 ----当前程序的名称<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $@----以&quot;参数1&quot; &quot;参数2&quot; ... 形式保存所有参数<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $$ ----本程序的(进程ID号)PID<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $! &nbsp;----上一个命令的PID</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-226-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-27-1.html">shell</category>
			<pubDate>2009-09-01 13:28</pubDate>
		</item>
	</channel>
</rss>
