<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>zrong&#039;s Blog &#187; linux</title>
	<atom:link href="http://zengrong.net/post/tag/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://zengrong.net</link>
	<description>Flash、Flex、RIA、web、Linux和我的生活</description>
	<lastBuildDate>Thu, 09 Feb 2012 15:09:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Bash数组操作教程</title>
		<link>http://zengrong.net/post/1518.htm</link>
		<comments>http://zengrong.net/post/1518.htm#comments</comments>
		<pubDate>Thu, 09 Feb 2012 15:01:33 +0000</pubDate>
		<dc:creator>zrong</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://zengrong.net/?p=1518</guid>
		<description><![CDATA[<a href="http://zengrong.net/post/1518.htm" title="Bash数组操作教程"></a>source on github 一、定义数组 1. 使用[]操作符 ?View Code BASHnames&#91;0&#93;='zrong' names&#91;1&#93;='jacky' 2. 使用()直接赋值 ?View Code BASHnames=&#40;'zrong' 'jacky'&#41; # 或 names=&#40;&#91;0&#93;='zrong' &#91;1&#93;='jacky'&#41; 3. 使用declare -a定义数组。这种方法可以将一个空的变量定义成数组类型。 ?View Code BASHdeclare -a names 4. 从文件中读取数组 ?View Code BASHcat&#62;names.txt zrong jacky sweet Ctrl+C # 将每一行读取为数组的一个元素 names=&#40;`cat &#8230;<p class="read-more"><a href="http://zengrong.net/post/1518.htm">继续阅读 &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://zengrong.net/post/1518.htm" title="Bash数组操作教程"></a><p><a href="https://github.com/zrong/blog/blob/master/bash_array.md">source on github</a></p>
<h2>一、定义数组</h2>
<h3>1. 使用[]操作符</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code14'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151814"><td class="code" id="p1518code14"><pre class="bash" style="font-family:monospace;">names<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">'zrong'</span>
names<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">'jacky'</span></pre></td></tr></table></div>

<h3>2. 使用()直接赋值</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code15'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151815"><td class="code" id="p1518code15"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">names</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'zrong'</span> <span style="color: #ff0000;">'jacky'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #666666; font-style: italic;"># 或</span>
<span style="color: #007800;">names</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">'zrong'</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">'jacky'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<h3>3. 使用declare -a定义数组。这种方法可以将一个空的变量定义成数组类型。</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code16'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151816"><td class="code" id="p1518code16"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">declare</span> <span style="color: #660033;">-a</span> names</pre></td></tr></table></div>

<h3>4. 从文件中读取数组<span id="more-1518"></span></h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code17'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151817"><td class="code" id="p1518code17"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span><span style="color: #000000; font-weight: bold;">&gt;</span>names.txt
zrong
jacky
sweet
Ctrl+C
<span style="color: #666666; font-style: italic;"># 将每一行读取为数组的一个元素</span>
<span style="color: #007800;">names</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">'names.txt'</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<h2>二、读取数组</h2>
<h3>1. 数组取值</h3>
<p>和ActionScript一样，Bash也使用[]操作符和基于0的下标来取值：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code18'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151818"><td class="code" id="p1518code18"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'Flash'</span> <span style="color: #ff0000;">'Flex'</span> <span style="color: #ff0000;">'Photoshop'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${adobe[0]}</span>
<span style="color: #666666; font-style: italic;"># 打印</span>
<span style="color: #666666; font-style: italic;"># Flash</span></pre></td></tr></table></div>

<h3>2. 数组长度（元素个数）</h3>
<p>使用“@”这个特殊的下标，可以将数组扩展成列表，然后就可以使用bash中的获取变量长度的操作符“#”来获取数组中元素的个数了：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code19'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151819"><td class="code" id="p1518code19"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'Flash'</span> <span style="color: #ff0000;">'Flex'</span> <span style="color: #ff0000;">'Photoshop'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${#adobe[@]}</span>
<span style="color: #666666; font-style: italic;"># 打印</span>
<span style="color: #666666; font-style: italic;"># 3</span></pre></td></tr></table></div>

<p>有趣的是，没有定义的数组下标，并不会占用数组中元素的个数：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code20'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151820"><td class="code" id="p1518code20"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">'Flash'</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">'Flex'</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">'Photoshop'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${#adobe[@]}</span>
<span style="color: #666666; font-style: italic;"># 打印</span>
<span style="color: #666666; font-style: italic;"># 3</span></pre></td></tr></table></div>

<h3>3. 获取数组的一部分</h3>
<p>命令替换对数组也是有效的，可以使用偏移操作符来取得数组的一部分：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code21'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151821"><td class="code" id="p1518code21"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'Flash'</span> <span style="color: #ff0000;">'Flex'</span> <span style="color: #ff0000;">'Photoshop'</span> <span style="color: #ff0000;">'Dreamweaver'</span> <span style="color: #ff0000;">'Premiere'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${adobe[@]:1:3}</span>
<span style="color: #666666; font-style: italic;"># 打印</span>
<span style="color: #666666; font-style: italic;"># Flex Photoshop Dreamweaver</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${adobe[@]:3}</span>
<span style="color: #666666; font-style: italic;"># 打印</span>
<span style="color: #666666; font-style: italic;"># Dreamweaver Premiere</span></pre></td></tr></table></div>

<h3>4. 连接两个数组</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code22'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151822"><td class="code" id="p1518code22"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'Flash'</span> <span style="color: #ff0000;">'Flex'</span> <span style="color: #ff0000;">'Photoshop'</span> <span style="color: #ff0000;">'Dreamweaver'</span> <span style="color: #ff0000;">'Premiere'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">adobe2</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'Fireworks'</span> <span style="color: #ff0000;">'Illustrator'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">adobe3</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #800000;">${adobe[@]}</span> <span style="color: #800000;">${adobe2[@]}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${#adobe3[@]}</span>
<span style="color: #666666; font-style: italic;"># 打印</span>
<span style="color: #666666; font-style: italic;"># 7</span></pre></td></tr></table></div>

<h2>三、修改数组</h2>
<h3>1. 替换数组元素</h3>
<p>模式操作符对数组也是有效的，可以使用它来替换数组中的元素</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code23'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151823"><td class="code" id="p1518code23"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'Flash'</span> <span style="color: #ff0000;">'Flex'</span> <span style="color: #ff0000;">'Photoshop'</span> <span style="color: #ff0000;">'Dreamweaver'</span> <span style="color: #ff0000;">'Premiere'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${adobe[@]/Flash/FlashCS5}</span>
<span style="color: #666666; font-style: italic;"># 打印</span>
<span style="color: #666666; font-style: italic;"># 注意，打印的结果是一个字符串列表，不是数组</span>
<span style="color: #666666; font-style: italic;"># FlashCS5 Flex Photoshop Dreamweaver Premiere</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># 将替换后的值重新保存成数组</span>
<span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #800000;">${adobe[@]/Flash/FlashCS5}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<h3>2. 删除数组元素</h3>
<p>使用命令替换并重新赋值的方式删除数组元素</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code24'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151824"><td class="code" id="p1518code24"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># 删除Photoshop元素</span>
<span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'Flash'</span> <span style="color: #ff0000;">'Flex'</span> <span style="color: #ff0000;">'Photoshop'</span> <span style="color: #ff0000;">'Dreamweaver'</span> <span style="color: #ff0000;">'Premiere'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #800000;">${adobe[@]:0:2}</span> <span style="color: #800000;">${adobe[@]:3}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${adobe[@]}</span>
<span style="color: #666666; font-style: italic;"># 打印</span>
<span style="color: #666666; font-style: italic;"># Flash Flex Dreamweaver Premiere</span></pre></td></tr></table></div>

<p>使用模式操作符删除数组元素</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code25'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151825"><td class="code" id="p1518code25"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'Flash'</span> <span style="color: #ff0000;">'Flex'</span> <span style="color: #ff0000;">'Photoshop'</span> <span style="color: #ff0000;">'Dreamweaver'</span> <span style="color: #ff0000;">'Premiere'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #800000;">${adobe[@]/Photoshop/}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${adobe[@]}</span>
<span style="color: #666666; font-style: italic;"># 打印</span>
<span style="color: #666666; font-style: italic;"># Flash Flex Dreamweaver Premiere</span></pre></td></tr></table></div>

<h2>四、循环</h2>
<p>使用for in循环读取数组：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1518code26'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p151826"><td class="code" id="p1518code26"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">adobe</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'Flash'</span> <span style="color: #ff0000;">'Flex'</span> <span style="color: #ff0000;">'Photoshop'</span> <span style="color: #ff0000;">'Dreamweaver'</span> <span style="color: #ff0000;">'Premiere'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">for</span> item <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${adobe[@]}</span>;<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$item</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #666666; font-style: italic;"># 打印</span>
<span style="color: #666666; font-style: italic;"># Flash </span>
<span style="color: #666666; font-style: italic;"># Flex </span>
<span style="color: #666666; font-style: italic;"># Photoshop </span>
<span style="color: #666666; font-style: italic;"># Dreamweaver </span>
<span style="color: #666666; font-style: italic;"># Premiere</span></pre></td></tr></table></div>

<p>使用for循环读取数组：</p>
<pre><code>&lt;pre lang="BASH"&gt;
adobe=('Flash' 'Flex' 'Photoshop' 'Dreamweaver' 'Premiere')
len=${#adobe[@]}
for ((i=0;i&lt;$len;i++));do
    echo ${adobe[$i]}
done
# 打印
# Flash
# Flex
# Photoshop
# Dreamweaver
# Premiere
&lt;/pre&gt;
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://zengrong.net/post/1518.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PuTTYcyg的替代者FuTTY</title>
		<link>http://zengrong.net/post/1506.htm</link>
		<comments>http://zengrong.net/post/1506.htm#comments</comments>
		<pubDate>Sat, 21 Jan 2012 15:55:23 +0000</pubDate>
		<dc:creator>zrong</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://zengrong.net/?p=1506</guid>
		<description><![CDATA[<a href="http://zengrong.net/post/1506.htm" title="PuTTYcyg的替代者FuTTY"></a>我一直是使用PuTTYcyg作为Cygwin的终端程序的。因为Windows的Command命令行实在是难用的可以。 但是puTTYcyg已经有很长时间没有更新了，今天在它的网站发现这个：PuTTYcyg is looking for a new maintainer。看来作者也不准备再继续维护这个项目了。 与此同时，PuTTY标准版也开始支持作为Cygwin的终端使用，只是自己要编译一个cygtermd出来：PuTTY wish cygwin-terminal-window 由于我比较懒惰，不想去down PuTTY的源码来编译，就在google上搜索有没有编译好的cygtermd.exe。无意之中找到了FuTTY。 这就是我理想中的Cygwin终端了！ 与PuTTYcyg相比，好处如下： 基于PuTTY 0.61源码编译； 加入PuTTYcyg； 加入PuTTY Tray，可以将界面最小化到任务栏中； 菜单中加入&#8221;Reconnect&#8221;和&#8221;Save Current Session&#8221;功能； 支持在界面中单击url网址用浏览器打开； 界面透明； 远程控制命令复制到剪贴板。]]></description>
			<content:encoded><![CDATA[<a href="http://zengrong.net/post/1506.htm" title="PuTTYcyg的替代者FuTTY"></a><p>我一直是使用<a href="http://code.google.com/p/puttycyg/">PuTTYcyg</a>作为<a href="http://www.cygwin.com/">Cygwin</a>的终端程序的。因为Windows的Command命令行实在是难用的可以。</p>
<p>但是puTTYcyg已经有很长时间没有更新了，今天在它的网站发现这个：<a href="http://code.google.com/p/puttycyg/issues/detail?id=68">PuTTYcyg is looking for a new maintainer</a>。看来作者也不准备再继续维护这个项目了。</p>
<p>与此同时，PuTTY标准版也开始支持作为Cygwin的终端使用，只是自己要编译一个cygtermd出来：<a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/cygwin-terminal-window.html">PuTTY wish cygwin-terminal-window</a></p>
<p>由于我比较懒惰，不想去down PuTTY的源码来编译，就在google上搜索有没有编译好的cygtermd.exe。无意之中找到了<a href="http://code.google.com/p/futty/">FuTTY</a>。</p>
<p>这就是我理想中的Cygwin终端了！</p>
<p>与PuTTYcyg相比，好处如下：</p>
<ul>
<li>基于PuTTY 0.61源码编译；</li>
<li>加入PuTTYcyg；</li>
<li>加入PuTTY Tray，<strong>可以将界面最小化到任务栏中</strong>；</li>
<li>菜单中加入&#8221;Reconnect&#8221;和&#8221;Save Current Session&#8221;功能；</li>
<li>支持在界面中单击url网址用浏览器打开；</li>
<li>界面透明；</li>
<li>远程控制命令复制到剪贴板。</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://zengrong.net/post/1506.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Apache不显示符号链接的处理办法</title>
		<link>http://zengrong.net/post/1479.htm</link>
		<comments>http://zengrong.net/post/1479.htm#comments</comments>
		<pubDate>Wed, 23 Nov 2011 07:32:44 +0000</pubDate>
		<dc:creator>zrong</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://zengrong.net/?p=1479</guid>
		<description><![CDATA[<a href="http://zengrong.net/post/1479.htm" title="Apache不显示符号链接的处理办法"></a>现在主要操作系统转到ArchLinux。在搭建了Apache后，DocumentRoot为/srv/http 我/srv/http下建立了一个符号链接docs，指向/home/zrong/docs 可是，无论怎样设置（FollowSymLinks当然是加了的），Apache就是不显示这个符号链接。 怀疑是权限问题，但docs的权限已经设置成了777。 查看apache的log，发现一条有用的信息： Symbolic link not allowed or link target not accessible 看来确实是权限问题，仔细查看，我发现/home/zrong的权限是700。 为/home/zrong加上执行权限，一切正常： ?View Code BASHchmod +x /home/zrong 另外，网上还有说此错误是由于SELinux对apache的影响。因为我没有装SELinux，因此排除。]]></description>
			<content:encoded><![CDATA[<a href="http://zengrong.net/post/1479.htm" title="Apache不显示符号链接的处理办法"></a><p>现在主要操作系统转到ArchLinux。在搭建了Apache后，DocumentRoot为/srv/http</p>
<p>我/srv/http下建立了一个符号链接docs，指向/home/zrong/docs</p>
<p>可是，无论怎样设置（FollowSymLinks当然是加了的），Apache就是不显示这个符号链接。</p>
<p>怀疑是权限问题，但docs的权限已经设置成了777。</p>
<p>查看apache的log，发现一条有用的信息：</p>
<blockquote><p>
  Symbolic link not allowed or link target not accessible
</p></blockquote>
<p>看来确实是权限问题，仔细查看，我发现/home/zrong的权限是700。</p>
<p>为/home/zrong加上执行权限，一切正常：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1479code28'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p147928"><td class="code" id="p1479code28"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>zrong</pre></td></tr></table></div>

<p>另外，网上还有说此错误是由于SELinux对apache的影响。因为我没有装SELinux，因此排除。</p>
]]></content:encoded>
			<wfw:commentRss>http://zengrong.net/post/1479.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TNND，Adobe居然停止了AIR的Linux版本開發？</title>
		<link>http://zengrong.net/post/1349.htm</link>
		<comments>http://zengrong.net/post/1349.htm#comments</comments>
		<pubDate>Sun, 19 Jun 2011 00:35:19 +0000</pubDate>
		<dc:creator>zrong</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://zengrong.net/?p=1349</guid>
		<description><![CDATA[<a href="http://zengrong.net/post/1349.htm" title="TNND，Adobe居然停止了AIR的Linux版本開發？"></a>從2.7版本後，Adobe停止了在Linux桌面環境中發布AIR的運行時和SDK，原因是Linux佔有率太低，而Android在不斷上升，Adobe需要整合資源到移動設備的AIR開發中去。 想想蘋果拋棄了Flash，可Adobe始終對IOS不離不棄……可Adobe就這樣無情的拋棄了Linuxer，真的很憤怒啊！ 看看這兩篇文章，評論裡基本是罵聲一片 http://blogs.adobe.com/flashplayer/2011/06/adobe-air-and-linux-increasing-distribution-on-devices.html http://blogs.adobe.com/open/2011/06/focusing-on-the-next-linux-client.html 當然，Adobe也有它的解決方案，就這個08年發布的所謂OSP計劃：http://www.openscreenproject.org/partners/apply.html]]></description>
			<content:encoded><![CDATA[<a href="http://zengrong.net/post/1349.htm" title="TNND，Adobe居然停止了AIR的Linux版本開發？"></a><p>從2.7版本後，Adobe停止了在Linux桌面環境中發布AIR的運行時和SDK，原因是Linux佔有率太低，而Android在不斷上升，Adobe需要整合資源到移動設備的AIR開發中去。</p>
<p>想想蘋果拋棄了Flash，可Adobe始終對IOS不離不棄……可Adobe就這樣無情的拋棄了Linuxer，真的很憤怒啊！</p>
<p>看看這兩篇文章，評論裡基本是罵聲一片</p>
<p><a href="http://blogs.adobe.com/flashplayer/2011/06/adobe-air-and-linux-increasing-distribution-on-devices.html">http://blogs.adobe.com/flashplayer/2011/06/adobe-air-and-linux-increasing-distribution-on-devices.html</a></p>
<p><a href="http://blogs.adobe.com/open/2011/06/focusing-on-the-next-linux-client.html">http://blogs.adobe.com/open/2011/06/focusing-on-the-next-linux-client.html</a></p>
<p>當然，Adobe也有它的解決方案，就這個08年發布的所謂OSP計劃：<a href="http://www.openscreenproject.org/partners/apply.html">http://www.openscreenproject.org/partners/apply.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://zengrong.net/post/1349.htm/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>在git中批量重命名</title>
		<link>http://zengrong.net/post/1236.htm</link>
		<comments>http://zengrong.net/post/1236.htm#comments</comments>
		<pubDate>Wed, 01 Jun 2011 09:33:44 +0000</pubDate>
		<dc:creator>zrong</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://zengrong.net/?p=1236</guid>
		<description><![CDATA[<a href="http://zengrong.net/post/1236.htm" title="在git中批量重命名"></a>2011-09-09更新：为《学习Bash（第二版）》PDF手工加入书签。 2011-09-20更新：加入《Learning.The.Bash.Shell.3rd》下载。 有一批形如map_XXX.XXX的文件，要改名为map1_XXX.XXX。如果使用其他改名工具改名，git会认为是删除了这些文件，并要求将改名后的文件重新添加到版本库，这会无端的增加版本库的大小。 最好的办法当然是用git mv来处理。鼓捣了半小时，写了我的第一行BASH代码： ?View Code BASHfor i in map*&#123;jpg,xml&#125;;do git mv $i &#34;map1${i:3}&#34;;done 说明： map*{jpg,xml}是只处理jpg和xml文件； $i是引用循环中的文件名，和${i}的作用相同； ${i:3}返回文件名的第3至最后一个字符的字符串。 BASH真的很好玩，推荐两本书： 《高级 Bash 脚本编程指南》（Advanced Bash-Scripting Guide） 上面这本书扫描的很不清晰，很多代码看不清，最好是对照英文版来看，下面是英文版下载：]]></description>
			<content:encoded><![CDATA[<a href="http://zengrong.net/post/1236.htm" title="在git中批量重命名"></a><p><span style="color:red;">2011-09-09更新：</span>为《学习Bash（第二版）》PDF手工加入书签。<br />
<span style="color:red;">2011-09-20更新：</span>加入《Learning.The.Bash.Shell.3rd》下载。</p>
<hr />
<p>有一批形如<code>map_XXX.XXX</code>的文件，要改名为<code>map1_XXX.XXX</code>。如果使用其他改名工具改名，git会认为是删除了这些文件，并要求将改名后的文件重新添加到版本库，这会无端的增加版本库的大小。</p>
<p>最好的办法当然是用<code>git mv</code>来处理。鼓捣了半小时，写了我的第一行BASH代码：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1236code30'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p123630"><td class="code" id="p1236code30"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> map<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>jpg,xml<span style="color: #7a0874; font-weight: bold;">&#125;</span>;<span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">git mv</span> <span style="color: #007800;">$i</span> <span style="color: #ff0000;">&quot;map1<span style="color: #007800;">${i:3}</span>&quot;</span>;<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>说明：</p>
<ul>
<li><code>map*{jpg,xml}</code>是只处理jpg和xml文件；</li>
<li><code>$i</code>是引用循环中的文件名，和<code>${i}</code>的作用相同；</li>
<li><code>${i:3}</code>返回文件名的第3至最后一个字符的字符串。</li>
</ul>
<p>BASH真的很好玩，推荐两本书：</p>
<p><a href="http://www.linuxsir.org/main/?q=node/140" target="_blank">《高级 Bash 脚本编程指南》（Advanced Bash-Scripting Guide）</a></p>
Note: There is a file embedded within this post, please visit this post to download the file.
<p>上面这本书扫描的很不清晰，很多代码看不清，最好是对照英文版来看，下面是英文版下载：</p>
Note: There is a file embedded within this post, please visit this post to download the file.
]]></content:encoded>
			<wfw:commentRss>http://zengrong.net/post/1236.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vim调用Ant编译swf并自动调试</title>
		<link>http://zengrong.net/post/1307.htm</link>
		<comments>http://zengrong.net/post/1307.htm#comments</comments>
		<pubDate>Fri, 29 Apr 2011 02:00:11 +0000</pubDate>
		<dc:creator>zrong</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Ant]]></category>
		<category><![CDATA[FlashBuilder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://zengrong.net/?p=1307</guid>
		<description><![CDATA[<a href="http://zengrong.net/post/1307.htm" title="Vim调用Ant编译swf并自动调试"></a>或许很少有人像我这么极端吧，放着好好的盗版XP和盗版Flash Builder不用，偏要去鼓捣什么Vim…… 当然，在Vim下面，你可以自己写脚本调用Flex SDK的命令行编译器mxmlc进行编译，但我更愿意用Ant，原因如下： 配置方便 基于XML的配置文件，比命令行好读好写； JAVA原生 Ant是JAVA写的，Flex SDK的编译器（mxmlc、compc、asdoc……）也是JAVA写的； 通用 换用Linux或Mac，也一样用，顶多改改变量中的路径。 在Flash Builder下面，按F11后，就可以自动编译swf并打开Flash Player，并显示trace信息，以及调试断点。在Vim中也能这样么？ 大部分可以。我们可以用fdb进行swf的调试工作，能看到trace信息，也能设置断点和进行调试，可惜没有Flash Builder那么直观。但是！！！你可以用Vim写AS代码了！塞翁失马你有没有！！！！ 那么，开始吧！ (注意，本文假定你了解Vim) 安装Ant 到Ant下载页面下载最新版的Ant。我将它解压到D:\ant； Ant需要安装JRE，但是如果你安装JDK的话，支持的task更多，所以现在下载JDK并安装，我将其安装到D:\Java\jdk1.6.0_25； 设置环境变量JAVA_HOME到D:\Java\jdk1.6.0_25，设置环境变量ANT_HOME到D:\ant； 将D:\Java\jdk1.6.0_25\bin和D:\ant\bin加入环境变量PATH。 Vim的设置 只需一步，将下面这句代码加入你的vimrc即可： set makeprg=ant "设置编译器为ant Ant的设置 将下面两个文件复制到你的项目文件夹（即src文件夹的上层文件夹）这两个文件的最新版本在这里：https://gist.github.com/944712 ?Download build.properties# 设置FLEX SDK的路径 FLEX_HOME=c:/Program Files/Adobe/FlashBuilder4Plug-in/sdks/4.1.0 &#160; # 设置源文件路径 # &#8230;<p class="read-more"><a href="http://zengrong.net/post/1307.htm">继续阅读 &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://zengrong.net/post/1307.htm" title="Vim调用Ant编译swf并自动调试"></a><p><strong>或许很少有人像我这么极端吧，放着好好的盗版XP和盗版Flash Builder不用，偏要去鼓捣什么Vim……</strong></p>
<p>当然，在<a href="http://www.vim.org">Vim</a>下面，你可以自己写脚本调用Flex SDK的命令行编译器mxmlc进行编译，但我更愿意用<a href="http://ant.apache.org/">Ant</a>，原因如下：</p>
<ul>
<li>配置方便<br />
基于XML的配置文件，比命令行好读好写；</li>
<li>JAVA原生<br />
Ant是JAVA写的，Flex SDK的编译器（mxmlc、compc、asdoc……）也是JAVA写的；</li>
<li>通用<br />
换用Linux或Mac，也一样用，顶多改改变量中的路径。</li>
</ul>
<p>在Flash Builder下面，按F11后，就可以自动编译swf并打开Flash Player，并显示trace信息，以及调试断点。在Vim中也能这样么？</p>
<p>大部分可以。我们可以用fdb进行swf的调试工作，能看到trace信息，也能设置断点和进行调试，可惜没有Flash Builder那么直观。<br /><strong>但是！！！你可以用Vim写AS代码了！塞翁失马你有没有！！！！</strong></p>
<p><strong>那么，开始吧！</strong></p>
<p><strong>(注意，本文假定你了解Vim)</strong><br />
<span id="more-1307"></span></p>
<h2>安装Ant</h2>
<ol>
<li>到<a href="http://ant.apache.org/bindownload.cgi" target="_blank">Ant下载页面</a>下载最新版的Ant。我将它解压到D:\ant；</li>
<li>Ant需要安装JRE，但是如果你安装JDK的话，支持的task更多，所以现在<a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">下载JDK</a>并安装，我将其安装到D:\Java\jdk1.6.0_25；</li>
<li>设置环境变量JAVA_HOME到D:\Java\jdk1.6.0_25，设置环境变量ANT_HOME到D:\ant；</li>
<li>将D:\Java\jdk1.6.0_25\bin和D:\ant\bin加入环境变量PATH。</li>
</ol>
<h2>Vim的设置</h2>
<p>只需一步，将下面这句代码加入你的vimrc即可：</p>
<pre><code>set makeprg=ant         "设置编译器为ant
</code></pre>
<h2>Ant的设置</h2>
<p>将下面两个文件复制到你的项目文件夹（即src文件夹的上层文件夹）这两个文件的最新版本在这里：<a href="https://gist.github.com/944712" target="_blank">https://gist.github.com/944712</a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://zengrong.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=1307&amp;download=build.properties">build.properties</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p130733"><td class="code" id="p1307code33"><pre class="txt" style="font-family:monospace;"># 设置FLEX SDK的路径
FLEX_HOME=c:/Program Files/Adobe/FlashBuilder4Plug-in/sdks/4.1.0
&nbsp;
# 设置源文件路径
# {$basedir} 就是本文件所在的目录
SRC_DIR =${basedir}/src
&nbsp;
# libs目录，一般用来放swc文件
LIBS_DIR =${basedir}/libs
&nbsp;
# 这个就是Flash Builder建立的bin-debug
DEPLOY_DIR = ${basedir}/bin-debug
&nbsp;
#自定义的类库源码
LIBS_DUDU = e:/works/duduw_as3lib/src</pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://zengrong.net/wp-content/plugins/wp-codebox/wp-codebox.php?p=1307&amp;download=build.xml">build.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p130734"><td class="code" id="p1307code34"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;run_test&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;build&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- 载入配置文件 --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;build.properties&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- 确定flexTasks.jar的位置 --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;flexTasks.tasks&quot;</span> <span style="color: #000066;">classpath</span>=<span style="color: #ff0000;">&quot;${FLEX_HOME}/ant/lib/flexTasks.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;build&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;init,compile,fdb&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- 清理部署目录中的内容 --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;init&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${DEPLOY_DIR}/run_test.swf&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${DEPLOY_DIR}/assets&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #808080; font-style: italic;">&lt;!-- 将资源目录复制到部署目录 --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${DEPLOY_DIR}/assets&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_DIR}/assets&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- 编译 --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;compile&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mxmlc</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${SRC_DIR}/RunTest.as&quot;</span> <span style="color: #000066;">output</span>=<span style="color: #ff0000;">&quot;${DEPLOY_DIR}/run_test.swf&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-config</span> <span style="color: #000066;">filename</span>=<span style="color: #ff0000;">&quot;${FLEX_HOME}/frameworks/flex-config.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source-path</span> <span style="color: #000066;">path-element</span>=<span style="color: #ff0000;">&quot;${LIBS_DUDU}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #808080; font-style: italic;">&lt;!-- 需要libs的时候解开注释</span>
<span style="color: #808080; font-style: italic;">			&lt;compiler.library-path dir=&quot;${basedir}&quot; append=&quot;true&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">				&lt;include name=&quot;libs&quot; /&gt;</span>
<span style="color: #808080; font-style: italic;">			&lt;/compiler.library-path&gt;</span>
<span style="color: #808080; font-style: italic;">			--&gt;</span>
			<span style="color: #808080; font-style: italic;">&lt;!-- 必须加上这行，如果不加，当使用[Embed]的标签的时候，就会出现VerifyError: Error #1014: 无法找到类 。 原因应该是没有将mx.core包编译进入。官方文档说这个属性默认是true， 不要相信它--&gt;</span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;static-link-runtime-shared-libraries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/static-link-runtime-shared-libraries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #808080; font-style: italic;">&lt;!-- 编译成可调试的版本 --&gt;</span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;compiler.debug<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/compiler.debug<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>			
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mxmlc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- 打开调试器进行调试 --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;fdb&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #808080; font-style: italic;">&lt;!-- 不能直接调用fdb，因为这样不会打开新的命令行窗口，必须使用/K或者/C参数，加上start来启动fdb --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exec</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;cmd&quot;</span> <span style="color: #000066;">spawn</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">osfamily</span>=<span style="color: #ff0000;">&quot;windows&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;/K start fdb ${DEPLOY_DIR}/run_test.swf&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exec<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<h2>编译</h2>
<p>这个就简单了，只需要在Vim下执行下面的语句：</p>
<pre>:make</pre>
<p>或者</p>
<pre>:!ant</pre>
<p>当然，也可以带参数。例如你的项目中有一个以上的主文件，你可以制作build_a.xml、build_b.xml等等，然后执行：</p>
<pre>:make -f build_a.xml</pre>
<h2>看图片吧！</h2>

<a href='http://zengrong.net/post/1307.htm/vim_ant_swf1' title='vim_ant_swf1'><img width="150" height="150" src="http://zengrong.net/wp-content/uploads/2011/04/vim_ant_swf1-150x150.png" class="attachment-thumbnail" alt="vim_ant_swf1" title="vim_ant_swf1" /></a>
<a href='http://zengrong.net/post/1307.htm/vim_ant_swf2' title='vim_ant_swf2'><img width="150" height="150" src="http://zengrong.net/wp-content/uploads/2011/04/vim_ant_swf2-150x150.png" class="attachment-thumbnail" alt="vim_ant_swf2" title="vim_ant_swf2" /></a>

]]></content:encoded>
			<wfw:commentRss>http://zengrong.net/post/1307.htm/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>[转]shell总结</title>
		<link>http://zengrong.net/post/1256.htm</link>
		<comments>http://zengrong.net/post/1256.htm#comments</comments>
		<pubDate>Thu, 10 Feb 2011 14:52:56 +0000</pubDate>
		<dc:creator>zrong</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://zengrong.net/post/1256.htm</guid>
		<description><![CDATA[<a href="http://zengrong.net/post/1256.htm" title="[转]shell总结"></a>转自：乔部落格 Shell元字符 元字符 含义 &#62; 将标准输出重定向到文件 &#62;&#62; 将标准输出附加到文件 &#60; 从文件中获取标准输入 &#124; p1&#124;p2将p1的标准输出作为p2的标准输入 &#60;&#60;串 here文档：标准输入从here文档读入，直到出现串 * 匹配文件名中的零个或多个字符 ? 匹配文件名中的任何单个字符 [ccc] 匹配文件名中 ccc范围内的任何字符 ; 命令结束符，如p1;p2表示先执行p1,再执行p2 &#38; 与;类似，但不等p1结束 `…` 运行…中的命令，输出结果代替`…` (…) 在子shell中运行…中的命令 {…} 在当前shell中运行…中的命令 $1, $2等 $0…$9可代表shell文件的参数 $变量 Shell变量的值 ${变量} Shell变量的值，为避免在文本联接时混淆 \ 转义字符，\c将c字符作为字符 &#8230;<p class="read-more"><a href="http://zengrong.net/post/1256.htm">继续阅读 &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://zengrong.net/post/1256.htm" title="[转]shell总结"></a><p>转自：<a href="http://joe.is-programmer.com/posts/17466.html" target="_blank">乔部落格</a></p>
<p><strong>Shell元字符</strong></p>
<table border="1" cellspacing="0" cellpadding="4" width="100%">
<colgroup>
<col width="97"></col>
<col width="159"></col>
</colgroup>
<tbody>
<tr valign="top">
<td width="38%">元字符</td>
<td width="62%">含义</td>
</tr>
<tr valign="top">
<td width="38%">&gt;</td>
<td width="62%">将标准输出重定向到文件</td>
</tr>
<tr valign="top">
<td width="38%">&gt;&gt;</td>
<td width="62%">将标准输出附加到文件</td>
</tr>
<tr valign="top">
<td width="38%">&lt;</td>
<td width="62%">从文件中获取标准输入</td>
</tr>
<tr valign="top">
<td width="38%">|</td>
<td width="62%">p1|p2将p1的标准输出作为p2的标准输入</td>
</tr>
<tr valign="top">
<td width="38%">&lt;&lt;串</td>
<td width="62%">here文档：标准输入从here文档读入，直到出现串</td>
</tr>
<tr valign="top">
<td width="38%">*</td>
<td width="62%">匹配文件名中的零个或多个字符</td>
</tr>
<tr valign="top">
<td width="38%">?</td>
<td width="62%">匹配文件名中的任何单个字符</td>
</tr>
<tr valign="top">
<td width="38%">[ccc]</td>
<td width="62%">匹配文件名中 ccc范围内的任何字符</td>
</tr>
<tr valign="top">
<td width="38%">;</td>
<td width="62%">命令结束符，如p1;p2表示先执行p1,再执行p2</td>
</tr>
<tr valign="top">
<td width="38%">&amp;</td>
<td width="62%">与;类似，但不等p1结束</td>
</tr>
<tr valign="top">
<td width="38%">`…`</td>
<td width="62%">运行…中的命令，输出结果代替`…`</td>
</tr>
<tr valign="top">
<td width="38%">(…)</td>
<td width="62%">在子shell中运行…中的命令</td>
</tr>
<tr valign="top">
<td width="38%">{…}</td>
<td width="62%">在当前shell中运行…中的命令</td>
</tr>
<tr valign="top">
<td width="38%">$1, $2等</td>
<td width="62%">$0…$9可代表shell文件的参数</td>
</tr>
<tr valign="top">
<td width="38%">$变量</td>
<td width="62%">Shell变量的值</td>
</tr>
<tr valign="top">
<td width="38%">${变量}</td>
<td width="62%">Shell变量的值，为避免在文本联接时混淆</td>
</tr>
<tr valign="top">
<td width="38%">\</td>
<td width="62%">转义字符，\c将c字符作为字符</td>
</tr>
<tr valign="top">
<td width="38%">&#8216;…&#8217;</td>
<td width="62%">单引号内表示文字</td>
</tr>
<tr valign="top">
<td width="38%">&#8220;…&#8221;</td>
<td width="62%">在…中的$, `…`,和\得到解释后，将…作为文本文字</td>
</tr>
<tr valign="top">
<td width="38%">#</td>
<td width="62%">注释</td>
</tr>
<tr valign="top">
<td width="38%">变量=值</td>
<td width="62%">为变量赋值</td>
</tr>
<tr valign="top">
<td width="38%">p1&amp;&amp;p2</td>
<td width="62%">运行p1;若成功，再运行p2</td>
</tr>
<tr valign="top">
<td width="38%">p1||p2</td>
<td width="62%">运行p1;若不成功，再运行p2</td>
</tr>
</tbody>
</table>
<p><strong>Shell内部变量<span id="more-1256"></span></strong></p>
<table border="1" cellspacing="0" cellpadding="4" width="100%">
<colgroup>
<col width="128"></col>
<col width="128"></col>
</colgroup>
<tbody>
<tr valign="top">
<td width="50%">变量</td>
<td width="50%">含义</td>
</tr>
<tr valign="top">
<td width="50%">$#</td>
<td width="50%">参数个数</td>
</tr>
<tr valign="top">
<td width="50%">$*</td>
<td width="50%">Shell的所有参数</td>
</tr>
<tr valign="top">
<td width="50%">$@（注）</td>
<td width="50%">类似$*</td>
</tr>
<tr valign="top">
<td width="50%">$-</td>
<td width="50%">Shell的选项</td>
</tr>
<tr valign="top">
<td width="50%">$?</td>
<td width="50%">上次执行命令的返回值</td>
</tr>
<tr valign="top">
<td width="50%">$$</td>
<td width="50%">Shell的pid</td>
</tr>
<tr valign="top">
<td width="50%">$!</td>
<td width="50%">用&amp;启动的最后一个命令的pid</td>
</tr>
<tr valign="top">
<td width="50%">$HOME</td>
<td width="50%">Cd命令的默认参数</td>
</tr>
<tr valign="top">
<td width="50%">$IFS</td>
<td width="50%">参数分隔符</td>
</tr>
<tr valign="top">
<td width="50%">$PATH</td>
<td width="50%">搜索命令的目录表</td>
</tr>
<tr valign="top">
<td width="50%">$PS1,$PS2</td>
<td width="50%">提示符</td>
</tr>
</tbody>
</table>
<p>注：($*与$@区别)</p>
<ol>
<li>$*和$@扩展为参数，并被重复扫描；参数的空格将字符串分成多个参数。</li>
<li>&#8220;$*&#8221;表示shell文件的所有参数及其空格连在一起作为单个词处理。</li>
<li>&#8220;$@&#8221;与shell文件接收的参数等价，参数中的空格被忽略，其结果是等同于原来参数的一个单词列表。</li>
</ol>
<p><strong>Shell变量的赋值</strong></p>
<table border="1" cellspacing="0" cellpadding="4" width="100%">
<colgroup>
<col width="128"></col>
<col width="128"></col>
</colgroup>
<tbody>
<tr valign="top">
<td width="50%">变量</td>
<td width="50%">赋值</td>
</tr>
<tr valign="top">
<td width="50%">$var</td>
<td width="50%">var的值；若var无定义则无值</td>
</tr>
<tr valign="top">
<td width="50%">${var}</td>
<td width="50%">同上；用于变量后跟着字母数字串的情况</td>
</tr>
<tr valign="top">
<td width="50%">${var-thing}</td>
<td width="50%">var有定义时，取值var；否则取值thing，而$var的值不变</td>
</tr>
<tr valign="top">
<td width="50%">${var=thing}</td>
<td width="50%">var有定义时，取值var；否则取值thing，$var的值设为thing</td>
</tr>
<tr valign="top">
<td width="50%">${var?message}</td>
<td width="50%">var有定义时，取值var；否则打印message</td>
</tr>
<tr valign="top">
<td width="50%">${var+thing}</td>
<td width="50%">var有定义时，取值thing；否则无值</td>
</tr>
</tbody>
</table>
<p>&gt;a或touch a创建文件。</p>
<p>Cat &gt; a从标准输入获取字符，写入文件a中，按ctrl-d结束。</p>
<p>（以上参考《UNIX编程环境》）</p>
<p>为了装软件方便，我写了一个简单的小脚本（我使用yum作为软件包管理者）。</p>
<p>脚本如下：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1256code36'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125636"><td class="code" id="p1256code36"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#program name: pack.sh</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> “try pach.sh <span style="color: #660033;">-h</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">help</span>”
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">in</span>
“-h”<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">echo</span> “usage: pack.sh -<span style="color: #7a0874; font-weight: bold;">&#91;</span>suihc<span style="color: #7a0874; font-weight: bold;">&#93;</span> ‘pack’”
<span style="color: #7a0874; font-weight: bold;">echo</span> “-s <span style="color: #000000; font-weight: bold;">for</span> search, <span style="color: #660033;">-u</span> <span style="color: #000000; font-weight: bold;">for</span> update, <span style="color: #660033;">-i</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">install</span>, <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">for</span> check updates”
<span style="color: #000000; font-weight: bold;">;;</span>
“-s”<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">echo</span> “This may take a few minutes, please <span style="color: #7a0874; font-weight: bold;">wait</span>…”
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">yum list</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$2</span>
<span style="color: #000000; font-weight: bold;">;;</span>
“-c”<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">echo</span> “This may take a few minutes, please <span style="color: #7a0874; font-weight: bold;">wait</span>…”
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">yum check-update</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">yum check-update</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$2</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">;;</span>
“-u”<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">yum</span> <span style="color: #660033;">-y</span> update <span style="color: #007800;">$2</span>
<span style="color: #000000; font-weight: bold;">;;</span>
“-i”<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">yum</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #007800;">$2</span>
<span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">echo</span> “NO such options<span style="color: #000000; font-weight: bold;">!</span>try pach.sh -h”
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">2</span>
<span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://zengrong.net/post/1256.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[转]Bash命令行历史权威指南</title>
		<link>http://zengrong.net/post/1254.htm</link>
		<comments>http://zengrong.net/post/1254.htm#comments</comments>
		<pubDate>Thu, 10 Feb 2011 14:36:58 +0000</pubDate>
		<dc:creator>zrong</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://zengrong.net/post/1254.htm</guid>
		<description><![CDATA[<a href="http://zengrong.net/post/1254.htm" title="[转]Bash命令行历史权威指南"></a>转自：逍遥云&#8217;s Blog 本文PDF格式电子书下载： 首先，让我们回顾下一些基本的历史命令快捷键 你可能记得，Bash提供了两种编辑命令的模式：emacs与vi, 很多快捷键在不同的编辑模式下是不同的。 切换模式： ?View Code BASH$ set -o mode &#40;vi/emacs&#41; 假设你要执行如下命令： ?View Code BASH$ echo foo bar baz $ iptables -L -n -v -t nat $ ... lots and lots more commands $ echo foo foo &#8230;<p class="read-more"><a href="http://zengrong.net/post/1254.htm">继续阅读 &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://zengrong.net/post/1254.htm" title="[转]Bash命令行历史权威指南"></a><p>转自：<a href="http://pallove.is-programmer.com/posts/21998.html" target="_blank">逍遥云&#8217;s Blog</a></p>
<p>本文PDF格式电子书下载：</p>
Note: There is a file embedded within this post, please visit this post to download the file.
<p>首先，让我们回顾下一些基本的历史命令快捷键</p>
<p>你可能记得，Bash提供了两种编辑命令的模式：emacs与vi, 很多快捷键在不同的编辑模式下是不同的。</p>
<p>切换模式：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code64'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125464"><td class="code" id="p1254code64"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span><span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-o</span> mode <span style="color: #7a0874; font-weight: bold;">&#40;</span>vi<span style="color: #000000; font-weight: bold;">/</span>emacs<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<p>假设你要执行如下命令：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code65'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125465"><td class="code" id="p1254code65"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> foo bar baz
$ iptables <span style="color: #660033;">-L</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-t</span> nat
$ ... lots and lots <span style="color: #c20cb9; font-weight: bold;">more</span> commands
$ <span style="color: #7a0874; font-weight: bold;">echo</span> foo foo foo
$ <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-wle</span> <span style="color: #ff0000;">'print q/hello world/'</span>
$ <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$1}'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span></pre></td></tr></table></div>

<p>然后你想执行最后一条历史命令(awk -F &#8230;).</p>
<p>你会想当然的按下键盘的上箭头并切安逸地陪伴你一生，但是真的需要把你的手移动哪么远吗？<span id="more-1254"></span></p>
<p>如果在Emacs模式下你只用按下Ctrl-P就能够从历史记录中取到前一条命令（Ctrl-n取下一条命令）</p>
<p>在vi模式下你只要按下Ctrl-[(或ESC)(用来切换到命令模式)与'h'('j'取下一条命令)即可</p>
<p>这儿有一个等同有效的方式就是Bash的历史扩展机制－－事件引用符， 输入"!!"就可以达到以上等同的效果（详细后面说明）</p>
<p>现在，假设你不想通过再次重复输入就想执行以上第二条命令'iptables -L -n -v -t nat'</p>
<p>天真的用户会照常按下键盘上箭头直到找那所需的那条命令，但这并不是黑客们的玩转方式，黑客们喜欢快速有效的方式。忘掉键盘的上下右左键以及翻页那一块键吧，依我看，它们跟本用不着，而且离键盘主要工作区域太远了。（看来作者应该玩的是vi）</p>
<p><!--more--></p>
<p>在emacs模式下输入'iptables'前几个字符，然后使用Ctrl-r就行了，比如:'ipt', 这将会正确地得到最后的以'iptables'起始的命令，再次输入Ctrl-r会得到更老输入的匹配，假如你错过了正确的结果，你要通过Ctrl-s就可以反向的搜索了（不要忘记默认的Ctrl-s操作会停止终端的输入，看起来像是假死了，记得按下Ctrl-g让终端恢复正常，具体设置，参见'sttycommand'）。</p>
<p>在vi模式下使用Ctrl-r与Ctrl-s会有些不同。</p>
<p>通过使用'Ctrl-['或'ESC'结合'/'来切换到命令模式，输入'iptables'前几个字符（插入模式），如'ipt'，然后回车. Bash将会匹配到最近的一条以'ipt'开始的历史记录，输入'n'或者通过'/'再次操作会得到相关的上一条命令，使用 'N' or '?' 得到下一条命令。</p>
<p>通过事件引用符可以得到最最近以'string'开头的历史命令</p>
<p>而使用'!iptables'就能扩展到最近的以'iptables'开头的历史命令</p>
<p>另一种方式是使用Bash自身的'history'命令与grep结合，然后再使用事件引用符'!N', N指的是历史记录中的第几条命令。</p>
<p>例如：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code66'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125466"><td class="code" id="p1254code66"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'ipt'</span>
<span style="color: #000000;">2</span> iptables <span style="color: #660033;">-L</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-t</span> nat
$ <span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">2</span> <span style="color: #666666; font-style: italic;"># will execute the iptables command</span></pre></td></tr></table></div>

<p>在vi编辑模式下，使用'N'（命令行号）与'G'， 就可以达到相同的效果，此例使用'2G'即可</p>
<p><strong>列出与擦除历史命令</strong></p>
<p>Bash内建了历史命令('history')的查看与擦除</p>
<p>及以下例为例：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code67'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125467"><td class="code" id="p1254code67"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> foo bar baz
$ iptables <span style="color: #660033;">-L</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-t</span> nat
$ ... lots and lots <span style="color: #c20cb9; font-weight: bold;">more</span> commands
$ <span style="color: #7a0874; font-weight: bold;">echo</span> foo foo foo
$ <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-wle</span> <span style="color: #ff0000;">'print q/hello world/'</span>
$ <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$1}'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span></pre></td></tr></table></div>

<p>输入'history'将会得到所有的带行号的历史命令</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code68'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125468"><td class="code" id="p1254code68"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">echo</span> foo bar baz
<span style="color: #000000;">2</span> iptables <span style="color: #660033;">-L</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-t</span> nat
... lots and lots <span style="color: #c20cb9; font-weight: bold;">more</span> commands
<span style="color: #000000;">568</span> <span style="color: #7a0874; font-weight: bold;">echo</span> foo foo foo
<span style="color: #000000;">569</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-wle</span> <span style="color: #ff0000;">'print q/hello world/'</span>
<span style="color: #000000;">570</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$1}'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span></pre></td></tr></table></div>

<p>输入'history N'(N为整数)，会得到最近的N条历史命令，如:'history 3', 结果如下：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code69'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125469"><td class="code" id="p1254code69"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">568</span> <span style="color: #7a0874; font-weight: bold;">echo</span> foo foo foo
<span style="color: #000000;">569</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-wle</span> <span style="color: #ff0000;">'print q/hello world/'</span>
<span style="color: #000000;">570</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$1}'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span></pre></td></tr></table></div>

<p>'history -c'将清除所以的历史记录，'history -d N'将会删除N条历史记录</p>
<p>默认在用户的主目录下会有一个名为'.bash_history'的历史记录文件</p>
<p><strong>历史命令扩展</strong></p>
<p>历史命令扩展的完善就是依赖所谓的事件引用符与词组引用符，事件引用符适用于先前取得的命令（事件），词组引用符适用于由事件而来的命令行。我们可以选择的就是：多样的修饰符可应用于已提取的参数。</p>
<p><strong>事件引用符</strong></p>
<p>事件引用符都是的以感叹号开头的特殊命令（也有以"^"开头的），它们可跟一个词组引用符和一个或多个修饰符。引用符与修饰符都是由':' 分隔开的</p>
<p>让我们看看下面的一组事件引用符的例子是如何运作的。</p>
<p>事件引用符"!!"用来取得前一条命令，例如：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code70'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125470"><td class="code" id="p1254code70"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> foo bar baz
foo bar baz
$ <span style="color: #000000; font-weight: bold;">!!</span>
foo bar baz</pre></td></tr></table></div>

<p>这里的"!!"就执行了'echo foo bar baz'这条命令</p>
<p>事件引用符'!N'用于执行命令历史的第N条记录</p>
<p>假如你的历史记录输出如下：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code71'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125471"><td class="code" id="p1254code71"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">echo</span> foo foo foo
<span style="color: #000000;">2</span> iptables <span style="color: #660033;">-L</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-t</span> nat
... lots and lots <span style="color: #c20cb9; font-weight: bold;">more</span> commands
<span style="color: #000000;">568</span> <span style="color: #7a0874; font-weight: bold;">echo</span> bar bar bar
<span style="color: #000000;">569</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-wle</span> <span style="color: #ff0000;">'print q/hello world/'</span>
<span style="color: #000000;">570</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F: <span style="color: #ff0000;">'{print$1}'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span><span style="color: #000000; font-weight: bold;">!</span></pre></td></tr></table></div>

<p>"!569"就会执行'perl …' 这条命令，而'!1'就会执行'echo foo foo foo'</p>
<p>'!-N'就会执行当前的命令的计数前N条命令（中间的'-'可以理解为减号），如下：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code72'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125472"><td class="code" id="p1254code72"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> foo bar baz
foo bar baz
$ <span style="color: #7a0874; font-weight: bold;">echo</span> a b c d e
a b c d e
$ <span style="color: #000000; font-weight: bold;">!</span>-<span style="color: #000000;">2</span>
foo bar baz</pre></td></tr></table></div>

<p>'!-2'执行上上一条命令，或者说是当前的命令的前2条命令<br />
'!string'适用以'string'开头的历史命令。例如:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code73'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125473"><td class="code" id="p1254code73"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">--help</span>
$ <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">--help</span></pre></td></tr></table></div>

<p>'!p'或者'!perl'或者'!per'都可以正确是执行到'perl -help'， 同理，'!a'亦可以执行那条以awk开头的命令</p>
<p>面'!?string?'就能匹配到包含'string'的命令，并不严格要求开头。</p>
<p>最有意思的事件引用符莫过于'^string1^string^'了，它将替换最后一条命令中的'string1'字符窜为'string2'，例如：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code74'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125474"><td class="code" id="p1254code74"><pre class="bash" style="font-family:monospace;">$ ehco foo bar baz
bash: ehco: <span style="color: #7a0874; font-weight: bold;">command</span> not found
$ ^ehco^<span style="color: #7a0874; font-weight: bold;">echo</span>^
foo bar baz</pre></td></tr></table></div>

<p>上面的'^ehco^echo^'作用就是取得上一条历史记录并替换ehco为echo，然后再执行</p>
<p><strong>词组引用符与修饰符</strong></p>
<p>事件引用符后面词组引用符（一个或多个）是用冒句分隔开的，它们适用于当前参照命令的部分或者所有的参数</p>
<p>例如：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code75'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125475"><td class="code" id="p1254code75"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> a b c d e
a b c d e
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">!!</span>:<span style="color: #000000;">2</span>
b</pre></td></tr></table></div>

<p>这里有一个最简单的词组引用符，':2'对应第2个参数（第3个单词），通常情况下':N'对应命令的第N-1个单词</p>
<p>词组引用符也接受一个范围值，例如：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code76'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125476"><td class="code" id="p1254code76"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> a b c d e
a b c d e
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">!!</span>:<span style="color: #000000;">3</span>-<span style="color: #000000;">4</span>
c d</pre></td></tr></table></div>

<p>符号用法也是多样的，例如，":$"对应最后一个参数，":^"对应第一个参数，":*"对应所有的参数(等同':1-$'), 等等，详情看完整的参照表</p>
<p>修饰符可以改变单词引用符的行为，例如：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code77'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125477"><td class="code" id="p1254code77"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvzf</span> software-<span style="color: #000000;">1.0</span>.tgz
software-<span style="color: #000000;">1.0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">file</span>
...
$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">!!</span>:$:r
<span style="color: #666666;">software-1.0$</span></pre></td></tr></table></div>

<p>'r'在这里就匹配了上一条命令的最后一个参数，'r'在此用作去掉后缀'.tgz'</p>
<p>'h'用于匹配并删除文件路径中的文件名部分，返回文件路径的开头部分：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code78'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125478"><td class="code" id="p1254code78"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">!!</span>:$:h
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span></pre></td></tr></table></div>

<p>'e'则只保留扩展名</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code79'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125479"><td class="code" id="p1254code79"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>software-<span style="color: #000000;">4.2</span>.messy-Extension
...
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/*!!</span>:$:e
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/*</span>.messy-Extension <span style="color: #666666; font-style: italic;"># ls could have been used instead of echo</span></pre></td></tr></table></div>

<p>另一个有趣的修饰符是替换符':s/old/new/', 即替换单词'old'为'new'，'g'用于全局替换，例如：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code80'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125480"><td class="code" id="p1254code80"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">/</span>urs<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>software-<span style="color: #000000;">4.2</span> <span style="color: #000000; font-weight: bold;">/</span>urs<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>software-<span style="color: #000000;">4.3</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ls: <span style="color: #000000; font-weight: bold;">/</span>urs<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>software-<span style="color: #000000;">4.2</span>: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ls: <span style="color: #000000; font-weight: bold;">/</span>urs<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>software-<span style="color: #000000;">4.3</span>: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory
$ <span style="color: #000000; font-weight: bold;">!!</span>:gs<span style="color: #000000; font-weight: bold;">/</span>urs<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>
...</pre></td></tr></table></div>

<p>以上这个例子就是替换所有的"urs"为'usr'来达到我们想要的结果。</p>
<p>这里还有一些其它的修饰符，如'p'只是用来回显扩展过的命令，并不执行。详情看完整的参照表。</p>
<p><strong>配置命令历史</strong></p>
<p>Bash允许用户自己配置命令历史文件，文件保存着命令以及记录号和一些选项</p>
<p>变量 HISTFILE, HISTFILESIZE, HISTIGNORE 和 HISTSIZEenvironment 对命令历史起着决定的作用。</p>
<p>HISTFILE, 正如词面意思，代表命令历史文件的路径</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code81'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125481"><td class="code" id="p1254code81"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>pkrumins<span style="color: #000000; font-weight: bold;">/</span>todays_history</pre></td></tr></table></div>

<p>上面命令当保存命令历史文件路径为'/home/pkrumins/todays_history'</p>
<p>值设置为'/dev/null'或空将不保存历史记录</p>
<p>HISTFILESIZE 控制着历史文件最大记录数，例如：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code82'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125482"><td class="code" id="p1254code82"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTFILESIZE</span>=<span style="color: #000000;">1000</span></pre></td></tr></table></div>

<p>这将保存1000条最近的历史命令</p>
<p>HISTSIZE 控制着当前会话（终端）的历史记录条数</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code83'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125483"><td class="code" id="p1254code83"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTSIZE</span>=<span style="color: #000000;">42</span></pre></td></tr></table></div>

<p>上面将保存当前会话最近42条历史命令</p>
<p>如果HISTSIZE变量的值小于HISTFILESIZE变量的值，只有限定数量的命令会被记录下来</p>
<p>HISTIGNORE 用来控制我们不想记录的命令，此变量是用冒号来分隔不同的模式，'&amp;' 对匹配历史命令起来特殊的作用。</p>
<p>'[ ]*&#8217;这个技巧可以用来忽略以空格开头的命令。</p>
<p>例如：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code84'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125484"><td class="code" id="p1254code84"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTIGNORE</span>=<span style="color: #ff0000;">&quot;&amp;amp;:[ ]*:exit&quot;</span></pre></td></tr></table></div>

<p>上面的命令就控制bash忽略复制命令，以及以空格开头，以及内容为&#8217;exit&#8217;字符的命令</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code85'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125485"><td class="code" id="p1254code85"><pre class="bash" style="font-family:monospace;">There are several other options of interest controlled by the built-in <span style="color: #ff0000;">'shopt'</span> command.</pre></td></tr></table></div>

<p>这儿有几个有关&#8217;shopt&#8217;命令的选项。</p>
<p>&#8216;-s&#8217;参数让&#8217;shopt&#8217;命令的配置有效，而&#8217;-u&#8217;参数使其无效。</p>
<p>&#8216;histappend&#8217;控制着历史列表如何写到命令历史记录中，设置这个选项将追加当前会话的历史命令到命令历史记录中，不设置（默认不设置，我的ubuntu 10.04默认却是打开的）每次将会重写命令历史记录文件。</p>
<p>打开：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code86'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125486"><td class="code" id="p1254code86"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span><span style="color: #7a0874; font-weight: bold;">shopt</span> <span style="color: #660033;">-s</span> histappend</pre></td></tr></table></div>

<p>关闭：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code87'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125487"><td class="code" id="p1254code87"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span><span style="color: #7a0874; font-weight: bold;">shopt</span> <span style="color: #660033;">-u</span> histappend</pre></td></tr></table></div>

<p>选项&#8217;histreedit&#8217;允许用户重编辑一条有误的历史替换命令</p>
<p>试想你已经输入如下：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code88'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125488"><td class="code" id="p1254code88"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span><span style="color: #7a0874; font-weight: bold;">echo</span> foo bar baz</pre></td></tr></table></div>

<p>本意想通过&#8217;^baz^test^&#8217;替换&#8217;baz&#8217;为&#8217;test&#8217;, 但是却输成了&#8217;^boo^test^&#8217;, 这将因为不匹配而导致替换失败</p>
<p>如果将此选项打开，bash将会保持你当前的&#8217;^boo^test^&#8217;错误的输入</p>
<p>最后，选项&#8217;histverify&#8217;允许用户去验证一条替换历史扩展命令</p>
<p>就拿前面的例子来说吧，假设你想通过&#8217;!!&#8217;再次&#8217;echo&#8217;命令，如果这个选项打开，bash将不会立即执行这条&#8217;echo&#8217;命令，而是将命令显示好等待你去验证是否是你想要的结果。</p>
<p><strong>调整命令提示</strong></p>
<p>我的命令提示是这样的：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code89'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125489"><td class="code" id="p1254code89"><pre class="bash" style="font-family:monospace;">Wed Jan <span style="color: #000000;">30</span><span style="color: #000000; font-weight: bold;">@</span>07:07:03
pkrumins<span style="color: #000000; font-weight: bold;">@</span>catonmat:<span style="color: #000000;">1002</span>:<span style="color: #000000;">2</span>:~$</pre></td></tr></table></div>

<p>第一行显示日期与时间可以及时的追溯命令</p>
<p>第二行显示用户名，主机名，全局行号以及当前命令当号</p>
<p>全局行号可以让我更快捷地使用事件引用符</p>
<p>我的PS1参数，变量值如下：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1254code90'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p125490"><td class="code" id="p1254code90"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">'\d@\t\n\u@\h:\!:\#:\w$ '</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://zengrong.net/post/1254.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[转]bash命令行快捷键</title>
		<link>http://zengrong.net/post/1253.htm</link>
		<comments>http://zengrong.net/post/1253.htm#comments</comments>
		<pubDate>Thu, 10 Feb 2011 14:18:12 +0000</pubDate>
		<dc:creator>zrong</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://zengrong.net/post/1253.htm</guid>
		<description><![CDATA[<a href="http://zengrong.net/post/1253.htm" title="[转]bash命令行快捷键"></a>转自：乔部落格 bash是Linuxer们常用的工具，高效的使用它能大大提高工作的效率。 下面就来总结一下bash命令行快捷键。 CTRL+a或Home移动光标至行首。 CTRL+e或End移动光标至行尾。 CTRL+左方向键或ALT +b将光标向前移动一个单词。 CTRL+右方向键或ALT +f将光标向后移动一个单词。 CTRL+w向前删除一个单词。 Esc+d向后删除一个单词。 CTRL+u删除光标至行首的字符。 CTRL+k删除光标至行尾的字符。 上方向键查找前一个命令，下方向键查找后一个命令。 CTRL+r向前搜索历史命令。 CTRL+y复制最后删除的项。 !$代表上一个命令的最后一个参数。 ALT+.复制上一个命令的最后一个参数。 CTRL+l清除屏幕。 CTRL+t反转光标所在字符及其前面的字符。 ^字符a^字符b将上一个命令中的字符a替换为字符b并执行。 ^字符a删除上一个命令中的字符a并执行。]]></description>
			<content:encoded><![CDATA[<a href="http://zengrong.net/post/1253.htm" title="[转]bash命令行快捷键"></a><p>转自：<a href="http://joe.is-programmer.com/posts/17465.html" target="_blank">乔部落格</a></p>
<p>bash是Linuxer们常用的工具，高效的使用它能大大提高工作的效率。</p>
<p>下面就来总结一下bash命令行快捷键。</p>
<p>CTRL+a或Home移动光标至行首。</p>
<p>CTRL+e或End移动光标至行尾。</p>
<p>CTRL+左方向键或ALT +b将光标向前移动一个单词。</p>
<p>CTRL+右方向键或ALT +f将光标向后移动一个单词。</p>
<p>CTRL+w向前删除一个单词。</p>
<p>Esc+d向后删除一个单词。</p>
<p>CTRL+u删除光标至行首的字符。</p>
<p>CTRL+k删除光标至行尾的字符。</p>
<p>上方向键查找前一个命令，下方向键查找后一个命令。</p>
<p>CTRL+r向前搜索历史命令。</p>
<p>CTRL+y复制最后删除的项。</p>
<p>!$代表上一个命令的最后一个参数。</p>
<p>ALT+.复制上一个命令的最后一个参数。</p>
<p>CTRL+l清除屏幕。</p>
<p>CTRL+t反转光标所在字符及其前面的字符。</p>
<p>^字符a^字符b将上一个命令中的字符a替换为字符b并执行。</p>
<p>^字符a删除上一个命令中的字符a并执行。</p>
]]></content:encoded>
			<wfw:commentRss>http://zengrong.net/post/1253.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>git乱码解决方案汇总</title>
		<link>http://zengrong.net/post/1249.htm</link>
		<comments>http://zengrong.net/post/1249.htm#comments</comments>
		<pubDate>Wed, 09 Feb 2011 17:59:50 +0000</pubDate>
		<dc:creator>zrong</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://zengrong.net/post/1249.htm</guid>
		<description><![CDATA[<a href="http://zengrong.net/post/1249.htm" title="git乱码解决方案汇总"></a>2011-10-24更新： 从一篇链接到本篇文章的文章(我对这篇文章提出的与windows患者的相处之道深感赞同)找到了一个“终极”解决方案，但我没有测试。 我一直是在cygwin下使用git，辅以TortoiseGit。使用上没什么问题，但今天在处理一个有中文文件名的项目时却出现文件名乱码的问题。 情况是这样的： 在一个使用cygwin的bash提交的git项目中，已经完成了所有的提交，但使用TortoiseGit查看的时候，却发现仍有文件没有提交，甚至是有文件还处于未暂存的状态。于是使用TortoiseGit提交； 再次用cygwin下的git status查看，这次又发现了未提交的情况。再次用git commit命令行提交； 回到TortoiseGit下查看，问题又出现了！此时准备返回两次提交前的版本，却因为文件名乱码的问题，无法返回了！ 搜索一番，发现git文件名、log乱码，是普遍问题，这其中有编码的原因，也有跨平台的原因。因为git是从linux移植过来，默认采用UTF-8编码。而Windows默认使用UTF-16编码来保存文件名，应该就是这些不同的处理方式造成了乱码。下面是解决方案： 乱码情景1 在cygwin中，使用git add添加要提交的文件的时候，如果文件名是中文，会显示形如274\232\350\256\256\346\200\273\347\273\223.png的乱码。 解决方案： 在bash提示符下输入： git config &#8211;global core.quotepath false ore.quotepath设为false的话，就不会对0&#215;80以上的字符进行quote。中文显示正常。 乱码情景2 在MsysGit中，使用git log显示提交的中文log乱码。 解决方案： 设置git gui的界面编码 git config &#8211;global gui.encoding utf-8 设置 commit log 提交时使用 utf-8 编码，可避免服务器上乱码，同时与linix上的提交保持一致！ git config &#8230;<p class="read-more"><a href="http://zengrong.net/post/1249.htm">继续阅读 &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://zengrong.net/post/1249.htm" title="git乱码解决方案汇总"></a><p><span style="color:red;">2011-10-24更新：</span> 从<a href="http://giftdotyoung.blogspot.com/2011/03/blog-post_31.html" title="宽容那些与我们不同的人" target="_blank">一篇链接到本篇文章的文章(我对这篇文章提出的与windows患者的相处之道深感赞同)</a>找到了一个“终极”解决方案，但我没有测试。</p>
<hr />
<p>我一直是在cygwin下使用git，辅以TortoiseGit。使用上没什么问题，但今天在处理一个有中文文件名的项目时却出现文件名乱码的问题。</p>
<p>情况是这样的：</p>
<ol>
<li>在一个使用cygwin的bash提交的git项目中，已经完成了所有的提交，但使用TortoiseGit查看的时候，却发现仍有文件没有提交，甚至是有文件还处于未暂存的状态。于是使用TortoiseGit提交；</li>
<li>再次用cygwin下的git status查看，这次又发现了未提交的情况。再次用git commit命令行提交；</li>
<li>回到TortoiseGit下查看，问题又出现了！此时准备返回两次提交前的版本，却因为文件名乱码的问题，无法返回了！</li>
</ol>
<p>搜索一番，发现git文件名、log乱码，是普遍问题，这其中有编码的原因，也有跨平台的原因。因为git是从linux移植过来，默认采用UTF-8编码。而Windows默认使用UTF-16编码来保存文件名，应该就是这些不同的处理方式造成了乱码。下面是解决方案：</p>
<p><span id="more-1249"></span></p>
<h2><strong>乱码情景1</strong></h2>
<p>在cygwin中，使用git add添加要提交的文件的时候，如果文件名是中文，会显示形如274\232\350\256\256\346\200\273\347\273\223.png的乱码。</p>
<p><strong>解决方案：</strong></p>
<p>在bash提示符下输入：</p>
<blockquote><p>git config &#8211;global core.quotepath false</p></blockquote>
<p>ore.quotepath设为false的话，就不会对0&#215;80以上的字符进行quote。中文显示正常。</p>
<h2><strong>乱码情景2</strong></h2>
<p>在MsysGit中，使用git log显示提交的中文log乱码。</p>
<p><strong>解决方案：</strong></p>
<p>设置git gui的界面编码</p>
<blockquote><p>git config &#8211;global gui.encoding utf-8</p></blockquote>
<p>设置 commit log 提交时使用 utf-8 编码，可避免服务器上乱码，同时与linix上的提交保持一致！</p>
<blockquote><p>git config &#8211;global i18n.commitencoding utf-8</p></blockquote>
<p>使得在 $ git log 时将 utf-8 编码转换成 gbk 编码，解决Msys bash中git log 乱码。</p>
<blockquote><p>git config &#8211;global i18n.logoutputencoding gbk</p></blockquote>
<p>使得 git log 可以正常显示中文（配合i18n.logoutputencoding = gbk)，在 /etc/profile 中添加：</p>
<blockquote><p>export LESSCHARSET=utf-8</p></blockquote>
<h2><strong>乱码情景3</strong></h2>
<p>在MsysGit自带的bash中，使用ls命令查看中文文件名乱码。cygwin没有这个问题。</p>
<p><strong>解决方案：</strong></p>
<p>使用ls &#8211;show-control-chars命令来强制使用控制台字符编码显示文件名，即可查看中文文件名。</p>
<p>为了方便使用，可以编辑/etc/git-completion.bash ，新增一行 alias ls=&#8221;ls &#8211;show-control-chars&#8221;</p>
<hr id="hr" />最终，还是没能解决最开始我提到的文件名提交乱码的问题。不过倒是有了一个新发现：<strong>使用git gui命令，在MsysGit下，看到的中文文件名为正常；而在cygwin下，看到的中文文件名为乱码。</strong></p>
<p>同样的，如果一直使用TortoiseGit（实际调用MsysGit）提交，那么中文文件名没问题；一直使用cygwin提交，中文文件名也没问题。<strong>但一定不能交叉使用。</strong>这应该是两个平台默认处理中文文件名的方式不同造成的。</p>
<p>分别设置L<strong>ANG、LC_CTYPE、LC_ALL</strong>参数为同样的编码，问题依旧。</p>
<p>cygwin官方网站提到了非拉丁语文件名的问题，也许研究后能解决该吧：<a href="http://www.cygwin.com/cygwin-ug-net/setup-locale.html" target="_blank">Chapter 2. Setting Up Cygwin</a></p>
<p>这里还有一篇讲解Linux系统编码文章：<a href="http://jmut.bokee.com/6874378.html" target="_blank">locale的设定及其LANG、LC_ALL、LANGUAGE环境变量的区别</a></p>
<p>貌似终极的解决办法是通过修改git和TortoiseGit源码实现的，有网友这么做了：<a href="http://www.cnblogs.com/tinyfish/archive/2010/12/17/1909463.html" target="_blank">让Windows下Git和TortoiseGit支持中文文件名/UTF-8</a></p>
<h2>又一个“终极”解决方案（<a href="http://giftdotyoung.blogspot.com/2011/03/blog-post_31.html" target="_blank">来自</a>）：</h2>
<p>在操作git时，把区域设置修改为 中文GBK。这之后就可以进行git相关操作了。</p>
<p><strong>在终端中跟windows保持一致</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1249code94'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p124994"><td class="code" id="p1249code94"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LC_ALL</span>=zh_CN.GBK; <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LANG</span>=zh_CN.GBK
terminal -<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">set</span> charactor encoding -<span style="color: #000000; font-weight: bold;">&gt;</span> gbk</pre></td></tr></table></div>

<p><strong>切换回linux默认</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1249code95'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p124995"><td class="code" id="p1249code95"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LC_ALL</span>=en_US.utf8; <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LANG</span>=en_US.utf8
terminal -<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">set</span> charactor encoding -<span style="color: #000000; font-weight: bold;">&gt;</span> unicode<span style="color: #7a0874; font-weight: bold;">&#40;</span>utf-<span style="color: #000000;">8</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<p><strong>改变文件名的编码</strong></p>
<p>如果已经造成乱码的恶果，还可以在utf8和gbk之间切换文件名。真的修改，而不是像上面那样修改显示的（解码的）效果。</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1249code96'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p124996"><td class="code" id="p1249code96"><pre class="bash" style="font-family:monospace;">convmv <span style="color: #000000; font-weight: bold;">&lt;</span>filename<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #660033;">-f</span> utf8 <span style="color: #660033;">-t</span> gbk</pre></td></tr></table></div>

<p>例外。convmv在fat32的U盘上运行无效，估计是fat32不允许非法编码。</p>
<p><strong>本文参考链接：</strong></p>
<ul>
<li><a href="http://topic.csdn.net/u/20110113/19/b0d5d506-4307-428b-a61d-7974aa66a2da.html" target="_blank">搞定Git中文乱码、用TortoiseMerge实现Diff/Merge</a></li>
<li><a href="http://topic.csdn.net/u/20110106/20/f11ef8dd-44ec-478e-b78a-73240bcdde43.html" target="_blank">MsysGit乱码与跨平台版本管理</a></li>
<li><a href="http://bbs.et8.net/bbs/showthread.php?t=942185" target="_blank">git中文文件名、目录名乱码应该怎么解决？</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://zengrong.net/post/1249.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

