<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[鍵盤語言 (Keyboard Languag)]]></title> 
<link>http://www.xspace.idv.tw/bo_blog/index.php</link> 
<description><![CDATA[網路語言是時代變遷的記錄，更是社會文化的載體，它彰顯出網路時代青年人的思維習慣與言語方式，是當代青年人以網路生活為主題，尤其在網聊、「網路社區」中使用的「鍵盤語言」。沒有規則，自成方圓的網路語言以其快捷性、豐富性、自由性、互通性的鮮明特徵，迅速地成為了虛擬時代青少年的新寵。當然,這些網路「新語言」撇開了語言規範，只能用在網路世界中，現實生活裏，我們還得「老老實實」說話。]]></description> 
<language>zh-tw</language> 
<copyright><![CDATA[鍵盤語言 (Keyboard Languag)]]></copyright>
<item>
<link>http://www.xspace.idv.tw/bo_blog/read.php?234</link>
<title><![CDATA[查詢 Linux 的系統版本方式]]></title> 
<author>bruce_wu &lt;bruce@xspace.idv.tw&gt;</author>
<category><![CDATA[Linux 指令]]></category>
<pubDate>Tue, 02 Sep 2008 03:06:37 +0000</pubDate> 
<guid>http://www.xspace.idv.tw/bo_blog/read.php?234</guid> 
<description>
<![CDATA[ 
	由於目前管理的 Linux 伺服器主機有15 部，常常哪一部主機的系統是安裝了什麼都會搞不清楚<br/>有一個方式可以查得目前的系統版本，<br/><br/><div class="code"><br/>#cat /etc/*-release<br/></div><br/><br/>察看會得到<br/><div class="code"><br/>CentOS release 4.4 (Final)<br/></div><br/><br/>另一版本<br/><br/><div class="code"><br/>CentOS release 5 (Final)<br/></div><br/><br/>等的資訊，這就是目前的系統版本了。<br/><br/>在 RedHat 的系統下為檔案為 /etc/redhat-release ，為了通用於其他系統所以使用 cat /etc/*-release 來察看<br/>此方式在 Fedora Core 和 CentOS 都可以適用，其他的系統因為我沒用過所以不得而知了。<br/><br/>Tags - <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=linux" rel="tag">linux</a> , <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=release" rel="tag">release</a>
]]>
</description>
</item><item>
<link>http://www.xspace.idv.tw/bo_blog/read.php?159</link>
<title><![CDATA[Linux 下停用按下 [Ctrl]-[Alt]-[Delete] 重新啟動系統]]></title> 
<author>bruce_wu &lt;bruce@xspace.idv.tw&gt;</author>
<category><![CDATA[Linux 指令]]></category>
<pubDate>Fri, 29 Jun 2007 06:17:07 +0000</pubDate> 
<guid>http://www.xspace.idv.tw/bo_blog/read.php?159</guid> 
<description>
<![CDATA[ 
	<div class="post-content"><p>要停用 Linux 按下 [Ctrl]-[Alt]-[Delete] 重新啟動系統，可以修改 <span style="color: #0000ff">/etc/inittab</span> 設定檔實現。<br /><br />設定方式如下：<br />1. 開啟 /etc/inittab&nbsp;&nbsp; ( <span style="color: #0000ff">$ vi /etc/inittab</span> )</p><p>2. 找出 <span style="color: #0000ff">ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now</span></p><p>3. 將這一行刪除，或者在這一行最前端加上 # 符號註解。</p><p>4. 儲存檔案後重新啟動系統即會生效，如果不想重新啟動可以執行以下指令:</p><p><div class="code">$ init q</div></p></div><br/>Tags - <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=linux" rel="tag">linux</a> , <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=init" rel="tag">init</a> , <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=%255Bctrl%255D-%255Balt%255D-%255Bdelete%255D" rel="tag">[ctrl]-[alt]-[delete]</a> , <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=shutdown" rel="tag">shutdown</a>
]]>
</description>
</item><item>
<link>http://www.xspace.idv.tw/bo_blog/read.php?158</link>
<title><![CDATA[使用Shell Script於Linux系統下載YouTube影片]]></title> 
<author>bruce_wu &lt;bruce@xspace.idv.tw&gt;</author>
<category><![CDATA[Linux 指令]]></category>
<pubDate>Fri, 29 Jun 2007 02:55:01 +0000</pubDate> 
<guid>http://www.xspace.idv.tw/bo_blog/read.php?158</guid> 
<description>
<![CDATA[ 
	當我看到這個Shell Script的時候，我在想 YouTube 的下載方式又多了一種<br/>而寫這一個 Shell Script 的作者對 Script 及 YouTube 也很熟悉<br/><br/>我看了他的 Shell Script 原碼後，是利用 Linux 的 wget 下載 YouTube 的影片<br/><br/>其原始 Shell Script &nbsp;碼如下：<br/><div class="code"><br/>#!/bin/sh<br/># $Id: youtube.sh 496 2006-06-05 23:37:35Z berto $<br/><br/>if &#91; &quot;$#&quot; != &quot;1&quot; &#93;; then<br/> &nbsp; echo &quot;YouTube Video Downloader&quot;<br/> &nbsp; echo &quot;Written by Alberto Garcia &lt;agarcia-at-igalia-com&gt;&quot;<br/> &nbsp; echo &quot;Homepage: http://people.igalia.com/berto/&quot;<br/> &nbsp; echo<br/> &nbsp; echo &quot;Usage:&quot;<br/> &nbsp; echo &quot; &nbsp; youtube.sh http://www.youtube.com/watch?v=&lt;video_ID&gt;&quot;<br/> &nbsp; echo &quot; or&quot;<br/> &nbsp; echo &quot; &nbsp; youtube.sh &lt;video_ID&gt;&quot;<br/> &nbsp; echo<br/> &nbsp; exit 64<br/>fi<br/><br/>VID=$(echo &quot;$1&quot;&#124;sed &quot;s/.*v=&#92;(&#91;^&amp;&#93;*&#92;).*/&#92;1/&quot;)<br/>URL1=&quot;http://www.youtube.com/watch?v=$VID&quot;<br/>echo -n &quot;Getting $URL1 ...&quot;<br/>PARAM=&quot;$(wget -q -O - &quot;$URL1&quot;&#124;grep watch_fullscreen&#124;cut -d &#039;&amp;&#039; -f 3)&quot;<br/>echo &quot; done.&quot;<br/>URL2=&quot;http://www.youtube.com/get_video?video_id=$VID&amp;$PARAM&quot;<br/>echo -n &quot;Getting $URL2 ...&quot;<br/>URL3=&quot;$(wget -S &quot;$URL2&quot; 2&gt;&amp;1&#124;sed -n /Location:/s/.*http:/http:/p)&quot;<br/>echo &quot; done.&quot;<br/><br/>echo &quot;Video address is $URL3&quot;<br/>exec wget -O &quot;$VID.flv&quot; &quot;$URL3&quot;<br/></div><br/><br/>將上面的原始碼複製然後儲存為 youtube.sh <br/>或由此下載 <a href="./attachment/200706/youtube.sh">點擊這裡下載檔案</a><br/>上傳到 Linux 系統上，並將檔案屬性改成 755<br/><div class="code"><br/>chmod 755 youtube.sh<br/></div><br/><br/>用法也相當的簡單有下面三種方式<br/><div class="code"><br/> &nbsp; $ youtube.sh &quot;http://www.youtube.com/watch?v=LVFQI35EpSE&amp;search=inhuman&quot;<br/> &nbsp; $ youtube.sh http://www.youtube.com/watch?v=LVFQI35EpSE<br/> &nbsp; $ youtube.sh LVFQI35EpSE<br/></div><br/><br/><span style="color: #FF0000;">以上面這三個例子，下載後會存成 LVFQI35EpSE.flv ，這樣就可以下載到 YouTube 的影片囉</span><br/><br/>如果想要手動使用 wget 抓取 也可以，就使用如下的方式<br/>如果想要下載這一個 http://www.youtube.com/watch?v=vVge3CiE5uU 的影片<br/>使用下面的方式也可以下載<br/><div class="code"><br/>$ wget -q -O - http://www.youtube.com/watch?v=vVge3CiE5uU &#124; &#92;<br/>grep watch_fullscreen &#124; awk -F &#039;&amp;&#039; &#039;&#123;print $3&#125;&#039; &#124; grep -v &quot;^$&quot;<br/></div><br/><br/>會得到一個 t 的值，如右 <span style="color: #0000FF;">t=OEgsToPDskJQ2NnnGoACoOqdSt1Yj9My</span> 每一次取得都會不同<br/><br/>再來就要運用該 t 的值，套入如下命令<br/><div class="code"><br/>$ wget -O youtube.flv &#92;<br/>&quot;http://www.youtube.com/get_video?video_id=vVge3CiE5uU&amp;t=OEgsToPDskJQ2NnnGoACoOqdSt1Yj9My&quot;<br/></div><br/><span style="color: #0000FF;">-O 後面放 下在下來後要儲存的檔案名稱 </span><br/><br/><span style="color: #FF0000;">經由上面這兩個步驟也可以將 YouTube 上的影片下載下來</span><br/><br/>如果想要將下載下來的 flv 影片檔轉成 mpg 格式，可以再透過 ffmgep 來轉換<br/>將下面加了兩行加入 youtube.sh &nbsp;最後面內，使它下載後自動把flv轉成mpg：<br/><span style="color: #FF0000;">(當然您的系統要先安裝有 ffmpeg )</span><div class="code"><br/>exec ffmpeg -i &quot;$VID.flv&quot; -ab 56 -ar 22050 -b 500 -s 320x240 &quot;$VID.mpg&quot;<br/>exec rm &quot;$VID.flv&quot;<br/></div><br/><span style="color: #FF0000;">這樣檔案就會轉成 .mpg 的格式了</span><br/><br/>Tags - <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=youtube" rel="tag">youtube</a> , <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=downloader" rel="tag">downloader</a> , <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=linux" rel="tag">linux</a> , <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=shell" rel="tag">shell</a> , <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=script" rel="tag">script</a> , <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=ffmpeg" rel="tag">ffmpeg</a> , <a href="http://www.xspace.idv.tw/bo_blog/tag.php?tag=wget" rel="tag">wget</a>
]]>
</description>
</item><item>
<link>http://www.xspace.idv.tw/bo_blog/read.php?128</link>
<title><![CDATA[設定 vimrc 讓vim可以編輯 UTF8/BIG5 等編碼文件]]></title> 
<author>bruce_wu &lt;bruce@xspace.idv.tw&gt;</author>
<category><![CDATA[Linux 指令]]></category>
<pubDate>Wed, 06 Jun 2007 07:57:48 +0000</pubDate> 
<guid>http://www.xspace.idv.tw/bo_blog/read.php?128</guid> 
<description>
<![CDATA[ 
	設定 vimrc 讓vim可以編輯 UTF8/BIG5 等編碼文件<br/><div class="code"><br/>$ vim /etc/vimrc<br/></div><br/>加入以下<br/><div class="code"><br/>if has(&quot;multi_byte&quot;)<br/>set encoding=utf-8<br/>setglobal fileencoding=big5<br/>set fileencoding=big5<br/>set bomb<br/>set termencoding=big5<br/>set fileencodings=ucs-bom,big5,utf-8,latin1<br/>set guifont=-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1<br/>set guifontwide=-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1<br/>else<br/>echoerr &quot;Sorry, this version of (g)vim was not compiled with multi_byte&quot;<br/>endif<br/></div><br/><br/>has("multi_byte")測試在 compile vim 時有沒有加入 multibyte 支援。如果沒有，就不能用 Unicode 了。 "encoding"設定 vim 內部如何表示字元。如果要用 Unicode 的話，Utf-8 是個不錯的選擇。 "fileencoding" sets the encoding for a particular file (local to buffer); :setglobal sets the default value. An empty value can also be used: it defaults to same as "encoding". Or you may want to set one of the ucs encodings, It might make the same disk file bigger or smaller depending on your particular mix of characters. Also, IIUC, utf-8 is always big-endian (high bit first) while ucs can be big-endian or little-endian, so if you use it, you will probably need to set "bomb" (see below). "bomb" (boolean)如果設定的話，vim 會在 ucs 的檔案開頭放個 "byte order mark"。這個和大多數不是 ucs 的檔案無關(utf-8, iso-8859, etc.) 有興趣想瞭解的人可以看看 http://www.unicode.org/faq/utf_bom.html 。 "termencoding"defines how your keyboard encodes what you type. The value you put there will depend on your locale: iso-8859-15 is Latin1 + Euro currency sign, but you may want something else for, say, an Eastern European keyboard. "fileencodings" defines the heuristic to set "fileencoding" (local to buffer) when reading an existing file. The first one that matches will be used (and, IIUC, if there is no match, Vim falls back on Latin1). Ucs-bom is "ucs with byte-order-mark"; it must not come after utf-8 if you want it to be used.
]]>
</description>
</item><item>
<link>http://www.xspace.idv.tw/bo_blog/read.php?123</link>
<title><![CDATA[修改vim設定使用 vim 時顯示出行數]]></title> 
<author>bruce_wu &lt;bruce@xspace.idv.tw&gt;</author>
<category><![CDATA[Linux 指令]]></category>
<pubDate>Wed, 06 Jun 2007 07:26:26 +0000</pubDate> 
<guid>http://www.xspace.idv.tw/bo_blog/read.php?123</guid> 
<description>
<![CDATA[ 
	一般情狀下，進入vim 後是不會顯示出行數<br/>如要此功能需要在 vim command 內下 :set nu! 方可<br/>但這樣使用有點麻煩，如要讓每次都顯示則需修改 /etc/vimrc 設定檔<br/><div class="code"><br/>vim /etc/vimrc<br/></div><br/>在最底下加入<br/><div class="code"><br/>set nu<br/></div><br/><br/>存檔離開，這樣及可以每次使用 vim 時都會列出行數了<br/>
]]>
</description>
</item><item>
<link>http://www.xspace.idv.tw/bo_blog/read.php?118</link>
<title><![CDATA[用 Sed 做 Search and replace]]></title> 
<author>bruce_wu &lt;bruce@xspace.idv.tw&gt;</author>
<category><![CDATA[Linux 指令]]></category>
<pubDate>Tue, 01 May 2007 19:37:22 +0000</pubDate> 
<guid>http://www.xspace.idv.tw/bo_blog/read.php?118</guid> 
<description>
<![CDATA[ 
	<div class="post-content"><p>另一篇<a href="http://192.168.3.168/lifetype/index.php?op=ViewArticle&amp;articleId=105&amp;blogId=1" title="用 Perl 做 Search and replace"><span style="color: #2f637a">文章</span></a>介紹了用 Perl 來做 search and replace，而用 sed 也可以做到相同效果，語法為:</p><p><div class="code">sed -i &#039;s/src_str/new_str/g&#039; filename</div></p><p>以上指令會將 filename 檔案內的 src_str 替換成 new_str。</p></div>
]]>
</description>
</item><item>
<link>http://www.xspace.idv.tw/bo_blog/read.php?115</link>
<title><![CDATA[如何刪除7天前的資料]]></title> 
<author>bruce_wu &lt;bruce@xspace.idv.tw&gt;</author>
<category><![CDATA[Linux 指令]]></category>
<pubDate>Mon, 30 Apr 2007 00:00:13 +0000</pubDate> 
<guid>http://www.xspace.idv.tw/bo_blog/read.php?115</guid> 
<description>
<![CDATA[ 
	<span style="font-size: small">刪除 7 天前檔案 ( 7天 * 86400 秒 = 604800) <br />注意空格, 注意大小寫, 最好直接在 Linux 上撰寫 <br /><br /></span><table border="0" cellspacing="1" cellpadding="3" width="90%" align="center"><tbody><tr><td><strong><span style="font-size: small">代碼:</span></strong></td></tr><tr><td class="code"><br /><span style="font-size: small">D=`date +%s`; <br />for i in `ls -1 *.tar.gz`; do <br />A=`stat -c %Y $i`; <br />[ &quot;x$A&quot; != &quot;x&quot; ] &amp;&amp; [ $((D - A)) -gt 604800 ] &amp;&amp; echo $i &amp;&amp; rm -fr $i ; <br />done <br /></span></td></tr></tbody></table><span style="font-size: small"><hr />假設要從 /xyz 這個目錄開始往下找所有檔案 <br /></span><table border="0" cellspacing="1" cellpadding="3" width="90%" align="center"><tbody><tr><td><strong><span style="font-size: small">代碼:</span></strong></td></tr><tr><td class="code"><br /><span style="font-size: small">find /xyz -name '*.tar.gz' -mtime +7 -exec rm &#123;&#125; ';' <br /></span></td></tr></tbody></table><br /><span style="font-size: small">find 第一個參數是開始找的目錄，會遞迴把所有子目錄都找過。 <br />-name '*.tar.gz' 找符合 tar.gz 檔案 <br />-mtime +7 最後修改日已超過 7 天 <br />-exec rm &#123;&#125; ';' 執行後面指令，直到 ; 為止，並把 filename 代入 &#123;&#125; <br />因 ; 對 shell 有意義，需加引號或 <br />如果用 -atime 則為最後存取日</span>
]]>
</description>
</item><item>
<link>http://www.xspace.idv.tw/bo_blog/read.php?105</link>
<title><![CDATA[linux下常用壓縮格式的壓縮與解壓方法]]></title> 
<author>bruce_wu &lt;bruce@xspace.idv.tw&gt;</author>
<category><![CDATA[Linux 指令]]></category>
<pubDate>Sun, 29 Apr 2007 16:17:17 +0000</pubDate> 
<guid>http://www.xspace.idv.tw/bo_blog/read.php?105</guid> 
<description>
<![CDATA[ 
	tar<br />解包： tar xvf FileName.tar<br />打包：tar cvf FileName.tar DirName<br />（註：tar是打包，不是壓縮！）<br />---------------------------------------------<br />.gz<br />解壓1：gunzip FileName.gz<br />解壓2：gzip -d FileName.gz<br />壓縮：gzip FileName<br /><br />例如：將/bin目錄打包到bin.tar.bz2但是<span style="color: #000099">排除</span>/bin/bash與/bin/tcsh不打包進來<br /><span style="color: #000099">tar -jcf bin.tar.bz2 --exclude /bin/bash --exclude /bin/tcsh /bin</span><br /><br />.tar.gz<br />解壓：tar zxvf FileName.tar.gz<br />壓縮：tar zcvf FileName.tar.gz DirName<br />---------------------------------------------<br />.bz2<br />解壓1：bzip2 -d FileName.bz2<br />解壓2：bunzip2 FileName.bz2<br />壓縮： bzip2 -z FileName<br />壓縮： bzip2 FileName<br /><br />.tar.bz2<br />解壓：tar jxvf FileName.tar.bz2<br />或<br />解壓：bzip2 -cd FileName.tar.bz2 &#124; tar xvf -<br /><br />壓縮：tar jcvf FileName.tar.bz2 DirName<br /><br />bzip2 a.bz2 file1 file2 file3 /etc<br />把文件file1,file2,file3及/etc下的內容壓縮起來，放入a.bz2文件中。<br /><br />---------------------------------------------<br />.bz<br />解壓1：bzip2 -d FileName.bz<br />解壓2：bunzip2 FileName.bz<br />壓縮：未知<br />.tar.bz<br />解壓：tar jxvf FileName.tar.bz<br />壓縮：未知<br />---------------------------------------------<br />.Z<br />解壓：uncompress FileName.Z<br />壓縮：compress FileName<br />.tar.Z<br />解壓：tar Zxvf FileName.tar.Z<br />壓縮：tar Zcvf FileName.tar.Z DirName<br />---------------------------------------------<br />.tgz<br />解壓：tar zxvf FileName.tgz<br />壓縮：未知<br />.tar.tgz<br />解壓：tar zxvf FileName.tar.tgz<br />壓縮：tar zcvf FileName.tar.tgz FileName<br />---------------------------------------------<br />.zip<br />解壓：unzip FileName.zip<br />壓縮：zip FileName.zip DirName<br />---------------------------------------------<br />.rar<br />解壓：rar e FileName.rar<br />壓縮：rar a FileName.rar<br /><br /><br />rar請到：http://www.rarsoft.com/download.htm 下載！<br />解壓後請將cp rar /usr/bin<br />---------------------------------------------<br />.lha<br />解壓：lha -e FileName.lha<br />壓縮：lha -a FileName.lha FileName<br /><br />lha請到：http://www.infor.kanazawa-it.ac.jp/.../lhaunix/下載！<br />&gt;解壓後請將lha拷貝到/usr/bin目錄（其他由$PATH環境變量指定的目錄也可以）：<br />[root@www2 tmp]# cp lha /usr/bin/<br />---------------------------------------------<br />.rpm<br />解包：rpm2cpio FileName.rpm &#124; cpio -div<br />---------------------------------------------<br />.tar .tgz .tar.gz .tar.Z .tar.bz .tar.bz2 .zip .cpio .rpm .deb .slp .arj .rar .ace .lha .lzh .lzx .lzs .arc .sda .sfx .lnx .zoo .cab .kar .cpt .pit .sit .sea<br />解壓：sEx x FileName.*<br />壓縮：sEx a FileName.* FileName<br /><br />sEx只是調用相關程序，本身並無壓縮、解壓功能，請注意！<br />sEx請到： <a href="http://sourceforge.net/projects/sex下载！" target="_blank">http://sourceforge.net/projects/sex下載！</a><br />解壓後請將sEx拷貝到/usr/bin目錄（其他由$PATH環境變量指定的目錄也可以）：<br />[root@www2 tmp]# cp sEx /usr/bin/
]]>
</description>
</item><item>
<link>http://www.xspace.idv.tw/bo_blog/read.php?97</link>
<title><![CDATA[Linux下patch的製作和應用]]></title> 
<author>bruce_wu &lt;bruce@xspace.idv.tw&gt;</author>
<category><![CDATA[Linux 指令]]></category>
<pubDate>Tue, 24 Apr 2007 00:25:25 +0000</pubDate> 
<guid>http://www.xspace.idv.tw/bo_blog/read.php?97</guid> 
<description>
<![CDATA[ 
	<span style="font-family: Times New Roman">1</span><span style="font-size: small">、</span><span style="font-size: small; font-family: Times New Roman">diff</span> <div><span style="font-size: small"><br /></span></div><div><span style="font-size: small; font-family: Times New Roman">diff</span><span style="font-size: small">的功能就是用來比較兩個文件的不同，然後記錄下來，生成補丁文件patch包。</span></div><div><span style="font-size: small">語法格式：</span></div><div><span style="font-size: small; font-family: Times New Roman">diff </span><span style="font-size: small">【選項】</span><span style="font-size: small; font-family: Times New Roman"> </span><span style="font-size: small">源文件（夾）</span><span style="font-size: small; font-family: Times New Roman"> </span><span style="font-size: small">目的文件（夾）</span></div><div><span style="font-size: small">三個最為常用選項：</span></div><div><span style="font-size: small; font-family: Times New Roman">-r &nbsp; </span><span style="font-size: small">是一個遞歸選項，設置了這個選項，</span><span style="font-size: small; font-family: Times New Roman">diff</span><span style="font-size: small">會將兩個不同版本源代碼目錄中的所有對應文件全部都&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 進行一次比較，包括子目錄文件。</span><span style="font-size: small; font-family: Times New Roman"> </span></div><div><span style="font-size: small; font-family: Times New Roman">-N&nbsp; </span><span style="font-size: small">選項確保補丁文件將正確地處理已經創建或刪除文件的情況。</span></div><div><span style="font-size: small; font-family: Times New Roman">-u&nbsp; </span><span style="font-size: small">選項以統一格式創建補丁文件，這種格式比缺省格式更緊湊些。</span></div><div><span style="font-size: small; font-family: Times New Roman"><br />2</span><span style="font-size: small">、</span><span style="font-size: small; font-family: Times New Roman">patch</span><span style="font-size: small"><br /></span></div><div><span style="font-size: small; font-family: Times New Roman">patch</span><span style="font-size: small">就是利用</span><span style="font-size: small; font-family: Times New Roman">diff</span><span style="font-size: small">製作的補丁來實現源文件（夾）和目的文件（夾）的轉換。你可以從源文件（夾）升級到目的文件（夾），也可以從目的文件（夾）恢復到源文件（夾）。<br />下面是幾個最常用選項：</span></div><div><span style="font-size: small; font-family: Times New Roman">-p0 </span><span style="font-size: small">選項要從當前目錄查找目的文件（夾）</span></div><div><span style="font-size: small; font-family: Times New Roman">-p1 </span><span style="font-size: small">選項要忽略掉第一層目錄，從當前目錄開始查找。</span></div><div><span style="font-size: small">-----------------------------------------------------------------------------------<br />舉例說明：</span></div><div align="left"><span style="font-size: small">--- old/test/a.c &nbsp;&nbsp;&nbsp;&nbsp; <br />+++ new/test/a.c</span></div><div align="left"><span style="font-size: small">&nbsp;&nbsp;&nbsp; 如果使用參數-p0，那就表示從當前目錄找一個叫做old的文件夾，在它下面尋找test下的a.c文件來執行patch操作。</span></div><p align="left"><span style="font-size: small">&nbsp;&nbsp;&nbsp; 如果使用參數-p1，那就表示忽略第一層目錄（即不管old），從當前目錄尋找test的文件夾，在它下面找a.c。這樣的前提是當前目錄必須為test所在的目錄。而diff補丁文件則可以在任意位置，只要指明了diff補丁文件的路徑就可以了。當然，可以用相對路徑，也可以用絕對路徑。</span></p><div><span style="font-size: small; font-family: Times New Roman">-------------------------------------------------------------------------------------------------------------------------------------------------<br />-E&nbsp; </span><span style="font-size: small">選項說明如果發現了空文件，那麼就刪除它</span></div><div><span style="font-size: small; font-family: Times New Roman">-R&nbsp; </span><span style="font-size: small">選項說明在補丁文件中的</span><span style="font-size: small; font-family: Times New Roman">「</span><span style="font-size: small">新</span><span style="font-size: small; font-family: Times New Roman">」</span><span style="font-size: small">文件和</span><span style="font-size: small; font-family: Times New Roman">「</span><span style="font-size: small">舊</span><span style="font-size: small; font-family: Times New Roman">」</span><span style="font-size: small">文件現在要調換過來了（實際上就是給新版本打補丁，讓它變成老版本）</span></div><div><span style="font-size: small"><br /><img src="http://www.cublog.cn/images/face/002.gif" border="0" width="19" height="19" />下面就來操練一下。<br /><br /><br /></span></div><div><span style="font-size: small">一、為單個文件進行補丁操作</span></div><div><span style="font-size: small; font-family: Times New Roman">1</span><span style="font-size: small">、建立測試文件</span><span style="font-size: small; font-family: Times New Roman">test0</span><span style="font-size: small">、</span><span style="font-size: small; font-family: Times New Roman">test1<br /></span><span style="font-size: small">[root@localhost a]# mkdir test<br /></span></div><span style="font-size: small">[root@localhost a]# ls<br />backup&nbsp; Desktop&nbsp; linux-source&nbsp; mydrv&nbsp; test<br />[root@localhost a]# cd test<br />[root@localhost test]# cat &gt;&gt;test0&lt;&lt;EOF<br />&gt; 111111<br />&gt; 111111<br />&gt; 111111<br />&gt; EOF<br />[root@localhost test]# cat &gt;&gt;test1&lt;&lt;EOF<br />&gt; 666666<br />&gt; 666666<br />&gt; 666666<br />&gt; EOF<br />[root@localhost test]# more test0<br />111111<br />111111<br />111111<br />[root@localhost test]# more test1<br />666666<br />666666<br />666666<br /></span><span style="font-size: small; font-family: Times New Roman">2</span><span style="font-size: small">、使用</span><span style="font-size: small; font-family: Times New Roman">diff</span><span style="font-size: small">創建補丁</span><span style="font-size: small; font-family: Times New Roman">test1.patch</span><span style="font-size: small"><br />[root@localhost test]# diff -uN test0 test1 &gt; test1.patch<br />因為單個文件，所以不需要</span><span style="font-size: small; font-family: Times New Roman">-r</span><span style="font-size: small">選項。選項順序沒有關係，即可以是</span><span style="font-size: small; font-family: Times New Roman">-uN</span><span style="font-size: small">，也可以是</span><span style="font-size: small; font-family: Times New Roman">-Nu</span><span style="font-size: small">。<br />[root@localhost test]# ls<br />test0&nbsp; test1&nbsp; test1.patch<br />[root@localhost test]# more test1.patch <br />--- test0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2007-04-24 08:33:25.000000000 +0800<br />+++ test1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2007-04-24 08:33:57.000000000 +0800<br />@@ -1,3 +1,3 @@<br />-111111<br />-111111<br />-111111<br />+666666<br />+666666<br />+666666<br /><br /><br /></span><div><span style="font-size: small; font-family: Times New Roman">************************************************************</span></div><div><span style="font-size: small; font-family: Times New Roman">patch</span><span style="font-size: small">文件的結構</span></div><div><span style="font-size: small">補丁頭</span></div><div><span style="font-size: small">補丁頭是分別由</span><span style="font-size: small; font-family: Times New Roman">---/+++</span><span style="font-size: small">開頭的兩行，用來表示要打補丁的文件。</span><span style="font-size: small; font-family: Times New Roman">---</span><span style="font-size: small">開頭表示舊文件，</span><span style="font-size: small; font-family: Times New Roman">+++</span><span style="font-size: small">開頭表示新文件。</span></div><div><span style="font-size: small">一個補丁文件中的多個補丁</span></div><div><span style="font-size: small">一個補丁文件中可能包含以</span><span style="font-size: small; font-family: Times New Roman">---/+++</span><span style="font-size: small">開頭的很多節，每一節用來打一個補丁。所以在一個補丁文件中可以包含好多個補丁。</span></div><div><span style="font-size: small">塊</span></div><div><span style="font-size: small">塊是補丁中要修改的地方。它通常由一部分不用修改的東西開始和結束。他們只是用來表示要修改的位置。他們通常以</span><span style="font-size: small; font-family: Times New Roman">@@</span><span style="font-size: small">開始，結束於另一個塊的開始或者一個新的補丁頭。</span></div><div><span style="font-size: small">塊的縮進</span></div><div><span style="font-size: small">塊會縮進一列，而這一列是用來表示這一行是要增加還是要刪除的。</span></div><div><span style="font-size: small">塊的第一列</span></div><div><span style="font-size: small; font-family: Times New Roman">+</span><span style="font-size: small">號表示這一行是要加上的。</span></div><div><span style="font-size: small; font-family: Times New Roman">-</span><span style="font-size: small">號表示這一行是要刪除的。</span></div><div><span style="font-size: small">沒有加號也沒有減號表示這裡只是引用的而不需要修改。</span></div><div><span style="font-size: small">************************************************************</span></div><div><span style="font-size: small; font-family: Times New Roman">***diff</span><span style="font-size: small">命令會在補丁文件中記錄這兩個文件的首次創建時間，如下</span><span style="font-size: small; font-family: Times New Roman">***<br /><br />--- test0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2007-04-24 08:33:25.000000000 +0800<br />+++ test1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2007-04-24 08:33:57.000000000 +0800<br />@@ -1,3 +1,3 @@<br /><br />3、打補丁<br /><br />[root@localhost test]# patch -p0 &lt;test1.patch <br />patching file test0<br />[root@localhost test]# ls<br />test0&nbsp; test1&nbsp; test1.patch<br />[root@localhost test]# more test0<br />666666<br />666666<br />666666<br />[root@localhost test]# more test1<br />666666<br />666666<br />666666<br />[root@localhost test]# ls<br />test0&nbsp; test1&nbsp; test1.patch<br /><br /><br /></span><span style="font-size: small; font-family: Times New Roman">4、可以去除補丁，恢復舊版本<br /><br />[root@localhost test]# patch -RE -p0 &lt;test1.patch <br />patching file test0<br />[root@localhost test]# ls<br />test0&nbsp; test1&nbsp; test1.patch<br />[root@localhost test]# more test0<br />111111<br />111111<br />111111<br />[root@localhost test]# more test1<br />666666<br />666666<br />666666<br />[root@localhost test]# ls<br />test0&nbsp; test1&nbsp; test1.patch<br /><br /><br /></span></div><div><span style="font-size: small">二、為多個文件進行補丁操作</span></div><div><span style="font-size: small; font-family: Times New Roman">1</span><span style="font-size: small">、創建測試文件夾</span></div><span style="font-size: small">[root@localhost test]# mkdir prj0 <br />[root@localhost test]# cp test0 prj0/<br />[root@localhost test]# ls<br />prj0&nbsp; test0&nbsp; test1&nbsp; test1.patch<br />[root@localhost test]# cd prj0/<br />[root@localhost prj0]# ls<br />test0<br />[root@localhost prj0]# cat&gt;&gt;prj0name&lt;&lt;EOF<br />&gt; ********<br />&gt; prj0/prj0name<br />&gt; EOF<br />[root@localhost prj0]# ls<br />prj0name&nbsp; test0<br />[root@localhost prj0]# more prj0name <br />********<br />prj0/prj0name<br />[root@localhost prj0]# cd ..<br />[root@localhost test]# ls<br />prj0&nbsp; test0&nbsp; test1&nbsp; test1.patch<br />[root@localhost test]# mkdir prj1<br />[root@localhost test]# cp test1 prj1<br />[root@localhost test]# cd prj1<br />[root@localhost prj1]# ls<br />test1<br />[root@localhost prj1]# vim prj1name<br />[root@localhost prj1]# more prj1name <br />-------------<br />prj1/prj1name<br />[root@localhost prj1]# cd ..<br />[root@localhost test]# ls<br />prj0&nbsp; prj1&nbsp; test0&nbsp; test1&nbsp; test1.patch<br /><br /></span><div><span style="font-size: small; font-family: Times New Roman">2</span><span style="font-size: small">、創建補丁<br /><br /></span></div><span style="font-size: small">[root@localhost test]# diff -uNr prj0 prj1 &gt; prj1.patch<br />[root@localhost test]# more prj1.patch <br />diff -uNr prj0/prj0name prj1/prj0name<br />--- prj0/prj0name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2007-04-24 08:48:30.000000000 +0800<br />+++ prj1/prj0name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1970-01-01 08:00:00.000000000 +0800<br />@@ -1,2 +0,0 @@<br />-********<br />-prj0/prj0name<br />diff -uNr prj0/prj1name prj1/prj1name<br />--- prj0/prj1name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1970-01-01 08:00:00.000000000 +0800<br />+++ prj1/prj1name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2007-04-24 08:50:24.000000000 +0800<br />@@ -0,0 +1,2 @@<br />+-------------<br />+prj1/prj1name<br />diff -uNr prj0/test0 prj1/test0<br />--- prj0/test0&nbsp; 2007-04-24 08:43:03.000000000 +0800<br />+++ prj1/test0&nbsp; 1970-01-01 08:00:00.000000000 +0800<br />@@ -1,3 +0,0 @@<br />-111111<br />-111111<br />-111111<br />diff -uNr prj0/test1 prj1/test1<br />--- prj0/test1&nbsp; 1970-01-01 08:00:00.000000000 +0800<br />+++ prj1/test1&nbsp; 2007-04-24 08:49:27.000000000 +0800<br />@@ -0,0 +1,3 @@<br />+666666<br />+666666<br />+666666<br />3.打補丁<br />[root@localhost test]# ls<br />prj0&nbsp; prj1&nbsp; prj1.patch&nbsp; test0&nbsp; test1&nbsp; test1.patch<br />[root@localhost test]# cp prj1.patch prj0<br />[root@localhost test]# cd prj0<br />[root@localhost prj0]# ls<br />prj0name&nbsp; prj1.patch&nbsp; test0<br />[root@localhost prj0]# patch -p1 &lt;prj1.patch <br />patching file prj0name<br />patching file prj1name<br />patching file test0<br />patching file test1<br />[root@localhost prj0]# ls<br />prj1name&nbsp; prj1.patch&nbsp; test1<br />[root@localhost prj0]# more test1<br />666666<br />666666<br />666666<br />[root@localhost prj0]# patch -R -p1 &lt;prj1.patch<br />patching file prj0name<br />patching file prj1name<br />patching file test0<br />patching file test1<br />[root@localhost prj0]# ls<br />prj0name&nbsp; prj1.patch&nbsp; test0<br />[root@localhost prj0]# more test0 <br />111111<br />111111<br />111111<br />[root@localhost prj0]# <br /><br /><br /></span><div><span style="font-size: small; font-family: Times New Roman"><span style="font-family: Times New Roman">－－－－－－－－－－－－－－－－－－－</span></span></div><div><span style="font-size: small">總結一下：</span></div><div><span style="font-size: small">單個文件</span></div><div><span style="font-size: small; font-family: Times New Roman">生成補丁：diff &ndash;uN &nbsp;from-file &nbsp;to-file &nbsp;&gt;to-file.patch</span></div><div><span style="font-size: small; font-family: Times New Roman">升級：patch &ndash;p0 &lt; to-file.patch</span></div><div><span style="font-size: small; font-family: Times New Roman">恢復：patch &ndash;RE &ndash;p0 &lt; to-file.patch</span></div><div><span style="font-size: small">多個文件</span></div><div><span style="font-size: small; font-family: Times New Roman">diff &ndash;uNr &nbsp;from-docu &nbsp;to-docu&nbsp; &gt;to-docu.patch</span></div><div><span style="font-size: small; font-family: Times New Roman">patch &ndash;p1 &lt; to-docu.patch</span></div><div><span style="font-size: small; font-family: Times New Roman">patch &ndash;R &ndash;p1 &lt;to-docu.patch</span></div><div><span style="font-size: small; font-family: Times New Roman">－－－－－－－－－－－－－－－－－－－</span></div><span style="font-size: small"><br /></span><div></div><div><span style="font-size: small">參考文章：<a href="http://www.cpqlinux.com/patch.html"><span style="color: #800080; font-family: Times New Roman"><u>http://www.cpqlinux.com/patch.html</u></span></a></span><span style="font-size: small; font-family: Times New Roman">&nbsp; </span><span style="font-size: small">《</span><span style="font-size: small; font-family: Times New Roman">How to create and use a patch in Linux</span><span style="font-size: small">》</span></div>
]]>
</description>
</item><item>
<link>http://www.xspace.idv.tw/bo_blog/read.php?88</link>
<title><![CDATA[egrep 指令]]></title> 
<author>bruce_wu &lt;bruce@xspace.idv.tw&gt;</author>
<category><![CDATA[Linux 指令]]></category>
<pubDate>Wed, 11 Apr 2007 18:18:14 +0000</pubDate> 
<guid>http://www.xspace.idv.tw/bo_blog/read.php?88</guid> 
<description>
<![CDATA[ 
	<p><div class="code">egrep &#039;(warning&#124;error&#124;fatal&#124;panic):&#039; /var/log/maillog &#124; more</div></p><p>用來察看 /var/log/maillog 記錄內含有 <br />*********** warning: ***********<br />*********** error: ***********<br />*********** fatal: ***********<br />*********** panic: ***********<br />等內容<br />*********** 代表，所有字</p>
]]>
</description>
</item>
</channel>
</rss>