<?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>A18制造 &#187; bash</title>
	<atom:link href="http://a18zhizao.com/ytag/bash/feed" rel="self" type="application/rss+xml" />
	<link>http://a18zhizao.com</link>
	<description>梦想的种子飞入了大地，所需要的只有时间。</description>
	<lastBuildDate>Sun, 22 Apr 2012 13:46:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>bash_completion install in Mac OS X Snow Leopard</title>
		<link>http://a18zhizao.com/y2010/1410_bash_completion-install-in-mac-os-x-snow-leopard.html</link>
		<comments>http://a18zhizao.com/y2010/1410_bash_completion-install-in-mac-os-x-snow-leopard.html#comments</comments>
		<pubDate>Wed, 05 May 2010 04:24:55 +0000</pubDate>
		<dc:creator>a18ccms</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[completion]]></category>
		<category><![CDATA[雪豹]]></category>

		<guid isPermaLink="false">http://a18zhizao.com/?p=1410</guid>
		<description><![CDATA[Recently，I Try to use the Snow Leopard ,But it lacks a feature. Debian-like bash_completion! I missed you! So I Seached with Google! To install it just do: Tip: You must have MacPorts installed to run the first command. MacPorts Form http://www.macports.org . If you don’t know yet what is bash_completion, it is  a feature for [...]]]></description>
			<content:encoded><![CDATA[<p>Recently，I Try to use the Snow Leopard ,But it lacks a feature.</p>
<p>Debian-like bash_completion! I missed you! So I Seached with Google!</p>
<p>To install it just do:</p>
<pre class="brush: bash; title: ; notranslate">
sudo port install bash-completion
echo &quot;source /opt/local/etc/bash_completion&quot; &gt;&gt; ~/.bash_profile
chmod +x ~/.bash_profile
</pre>
<p>Tip: You must have MacPorts installed to run the first command. MacPorts Form <a href="http://www.macports.org/" target="_blank">http://www.macports.org</a> .</p>
<p>If you don’t know yet what is bash_completion, it is  a feature for  shells to autocomplete commands. Example: You are on a git repository.  You type git fe and press TAB, bash_completion will fill “fetch” for  you. If you have branches, they are autocompleted too. GNU Tar only  shows files compatible with the filters you selected. So if you tar xvzf  my-softw TAB, it will complete only filenames that are on tar.gz or tgz  format and that starts with the string you already typed.</p>
<p>It is heaven again.</p>
]]></content:encoded>
			<wfw:commentRss>http://a18zhizao.com/y2010/1410_bash_completion-install-in-mac-os-x-snow-leopard.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Add Bash Completion In Debian</title>
		<link>http://a18zhizao.com/y2010/1326_add-bash-completion-in-debian.html</link>
		<comments>http://a18zhizao.com/y2010/1326_add-bash-completion-in-debian.html#comments</comments>
		<pubDate>Tue, 16 Mar 2010 01:05:24 +0000</pubDate>
		<dc:creator>a18ccms</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[completion]]></category>
		<category><![CDATA[debian]]></category>

		<guid isPermaLink="false">http://a18zhizao.com/?p=1326</guid>
		<description><![CDATA[Bash completion is a useful tool for completion of file paths, commands etc. By default it is enabled on Ubuntu but not on Debian. With two simple steps it can also be enabled on Debian. 1. Install bash-completion First of all we need the install the according package: apt-get install bash-completion 2. Add it to [...]]]></description>
			<content:encoded><![CDATA[<p>Bash completion is a useful tool for completion of file paths, commands etc. By default it is enabled on Ubuntu but not on Debian. With two simple steps it can also be enabled on Debian.</p>
<p>1. Install bash-completion</p>
<p>First of all we need the install the according package:<br />
<span id="more-1326"></span><br />
<code>apt-get install bash-completion</code></p>
<p>2. Add it to the bash profile</p>
<p>Either edit the ~/.bash_profile file to enable it only for a given user or edit /etc/profile to add it system-wide. Add the following code:</p>
<pre class="brush: bash; title: ; notranslate">
if [ -f /etc/bash_completion ]; then
 . /etc/bash_completion
fi
</pre>
<p>3. Try it<br />
In order for it to work you have to log out and relogin and then you can make use of bash completion the usual way. E.g. issue:</p>
<p><code>apt-g</code></p>
<p>and then press the TAB key once and the command will be completed to apt-get. Or issue this:</p>
<p><code>apt</code></p>
<p>and then press TAB key twice. You can also try with</p>
<p><code>apt-get install apa</code></p>
<p>and then press TAB key once to complete as far as possible and a second time to list all options.</p>
]]></content:encoded>
			<wfw:commentRss>http://a18zhizao.com/y2010/1326_add-bash-completion-in-debian.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bash 使用技巧大补贴</title>
		<link>http://a18zhizao.com/y2010/1319_bash-tips-big-subsidies.html</link>
		<comments>http://a18zhizao.com/y2010/1319_bash-tips-big-subsidies.html#comments</comments>
		<pubDate>Wed, 10 Mar 2010 14:49:45 +0000</pubDate>
		<dc:creator>a18ccms</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[技巧]]></category>

		<guid isPermaLink="false">http://a18zhizao.com/?p=1319</guid>
		<description><![CDATA[Bash 是我们经常与之打交道的 Shell 程序，本文针对其使用技巧进行了搜罗。相信在你看过这些内容之后，定会在 Bash 的世界里游刃有余。 从历史中执行命令 有时候，我们需要在 Bash 中重复执行先前的命令。你当然可以使用上方向键来查看之前曾经运行过的命令。但这里有一种更好的方式：你可以按 Ctrl + r 组合键进入历史搜索模式，一旦找到需要重复执行的命令，按回车键即可。 重复命令参数 先来看一个例子： 本例中，第一行命令将创建一个目录，而第二行的命令则转到刚创建的目录。这里，“!$”的作用就是重复前一个命令的参数。事实上，不仅是命令的参数可以重复，命令的选项同样可以。另外，Esc + . 快捷键可以切换这些命令参数或选项。 用于编辑的快捷键 Ctrl + a：将光标定位到命令的开头 Ctrl + e：与上一个快捷键相反，将光标定位到命令的结尾 Ctrl + u：剪切光标之前的内容 Ctrl + k：与上一个快捷键相反，剪切光标之后的内容 Ctrl + y：粘贴以上两个快捷键所剪切的内容 Ctrl + t：交换光标之前两个字符的顺序 Ctrl + w：删除光标左边的参数（选项）或内容 Ctrl + l：清屏 处理作业 首先，使用 Ctrl + z 快捷键可以让正在执行的命令挂起。如果要让该进程在后台执行，那么可以执行 bg 命令。而 fg 命令则可以让该进程重新回到前台来。使用 [...]]]></description>
			<content:encoded><![CDATA[<p>Bash 是我们经常与之打交道的 Shell 程序，本文针对其使用技巧进行了搜罗。相信在你看过这些内容之后，定会在 Bash 的世界里游刃有余。<br />
<span id="more-1319"></span></p>
<ul>
<li>从历史中执行命令 有时候，我们需要在 Bash 中重复执行先前的命令。你当然可以使用上方向键来查看之前曾经运行过的命令。但这里有一种更好的方式：你可以按 Ctrl + r 组合键进入历史搜索模式，一旦找到需要重复执行的命令，按回车键即可。</li>
<li>重复命令参数 先来看一个例子：
<pre class="brush: bash; title: ; notranslate">
mkdir /path/to/exampledir
cd !$
</pre>
<p>本例中，第一行命令将创建一个目录，而第二行的命令则转到刚创建的目录。这里，“!$”的作用就是重复前一个命令的参数。事实上，不仅是命令的参数可以重复，命令的选项同样可以。另外，Esc + . 快捷键可以切换这些命令参数或选项。</li>
<li>用于编辑的快捷键
<ul>
<li>Ctrl + a：将光标定位到命令的开头</li>
<li>Ctrl + e：与上一个快捷键相反，将光标定位到命令的结尾</li>
<li>Ctrl + u：剪切光标之前的内容</li>
<li>Ctrl + k：与上一个快捷键相反，剪切光标之后的内容</li>
<li>Ctrl + y：粘贴以上两个快捷键所剪切的内容</li>
<li>Ctrl + t：交换光标之前两个字符的顺序</li>
<li>Ctrl + w：删除光标左边的参数（选项）或内容</li>
<li>Ctrl + l：清屏</li>
</ul>
</li>
<li>处理作业 首先，使用 Ctrl + z 快捷键可以让正在执行的命令挂起。如果要让该进程在后台执行，那么可以执行 bg 命令。而 fg 命令则可以让该进程重新回到前台来。使用 jobs 命令能够查看到哪些进程在后台执行。 你也可以在 fg 或 bg 命令中使用作业 id，如：
<pre class="brush: bash; title: ; notranslate">
bg %7
</pre>
<p> 又如：</p>
<pre class="brush: bash; title: ; notranslate">
fg %3
</pre>
</li>
<li>使用置换
<ul>
<li>命令置换 先看例子：
<pre class="brush: bash; title: ; notranslate">
du -h -a -c $(find . -name *.conf 2&gt;&amp;-)
</pre>
<p>注意 $() 中的部分，这将告诉 Bash 运行 find 命令，然后把返回的结果作为 du 的参数。</li>
<li>进程置换 仍然先看例子：
<pre class="brush: bash; title: ; notranslate">
diff &lt;(ps axo comm) &lt;(ssh user@host ps axo comm)
</pre>
<p>该命令将比较本地系统和远程系统中正在运行的进程。请注意 &lt;() 中的部分。</li>
<li>xargs 看例：
<pre class="brush: bash; title: ; notranslate">
find . -name *.conf -print0 | xargs -0 grep -l -Z mem_limit | xargs -0 -i cp {} {}.bak
</pre>
<p> 该命令将备份当前目录中的所有 .conf 文件。</li>
</ul>
</li>
<li>使用管道 下面是一个简单的使用管道的例子：
<pre class="brush: bash; title: ; notranslate">
ps aux | grep init
</pre>
<p>这里，“|”操作符将 ps aux 的输出重定向给 grep init。 下面还有两个稍微复杂点的例子： </p>
<pre class="brush: bash; title: ; notranslate">
ps aux | tee filename | grep init
</pre>
<p>及：</p>
<pre class="brush: bash; title: ; notranslate">
ps aux | tee -a filename | grep init
</pre>
</li>
<li>将标准输出保存为文件 你可以将命令的标准输出内容保存到一个文件中，举例如下：
<pre class="brush: bash; title: ; notranslate">
ps aux &gt; filename
</pre>
<p>注意其中的“>”符号。 你也可以将这些输出内容追加到一个已存在的文件中：</p>
<pre class="brush: bash; title: ; notranslate">
ps aux &gt;&gt; filename
</pre>
<p>你还可以分割一个较长的行： </p>
<pre class="brush: bash; title: ; notranslate">
command1 | command2 | ... | commandN &gt; tempfile1
cat tempfile1 | command1 | command2 | ... | commandN &gt; tempfile2
</pre>
</li>
<li>标准流：重定向与组合 重定向流的例子：
<pre class="brush: bash; title: ; notranslate">
ps aux 2&gt;&amp;1 | grep init
</pre>
<p>这里的数字代表：</p>
<ul>
<li>0：stdin</li>
<li>1：stdout</li>
<li>2：sterr</li>
</ul>
<p>上面的命令中，“grep init”不仅搜索“ps aux”的标准输出，而且搜索 sterr 输出。</li>
</ul>
<p>via: <a href="http://www.linuxtutorialblog.com/post/tutorial-the-best-tips-tricks-for-bash">The best tips &#038; tricks for bash, explained [Linux Tutorials Blog]</a></p>
<hr />
下面两个诀窍可以增强 Bash 的功能，一个是针对 Bash 的命令历史管理进行了改善，另一个是使 Bash 能够具有更加智能的自动完成特性。实现的过程并不复杂，只需修改 Bash 的默认配置即可。</p>
<p>改善 Bash 的命令历史管理功能： Bash 的默认配置会存在一个问题，如果同时打开两个（或两个以上的）控制台，那么在这两个控制台中执行的命令并不会互相分享到 history 中。有的命令历史甚至最终会被覆盖掉。要解决这个问题，可把下列内容添加到 <code>~/.bashrc</code> 或 <code>~/.bash_profile</code> 文件中：</p>
<pre class="brush: bash; title: ; notranslate">
#Bash should append rather than overwrite the history
shopt -s histappend

#When displaying the prompt, write the previous line to disk
PROMPT_COMMAND='history -a'
</pre>
<p>第一句的作用是将命令追加到 history 中。第二句是在显示命令提示符时，保存 history。<br />
设置智能的自动完成功能： 在 Bash 中我们已经可以通过按 Tab 键来享用自动完成的特性。通过下面的设置，则可以使用 Up 和 Down 键来选择命令后所跟的参数。在 .inputrc（如果该文件不存在，则创建一个）中加入下列内容：</p>
<pre class="brush: bash; title: ; notranslate">
#Move in history using up and down arrows
&quot;\e[A&quot;: history-search-backward
&quot;\e[B&quot;: history-search-forward                                                    

#On tab show completion
set show-all-if-ambiguous on
</pre>
<p>前两句使用 Up 和 Down 在 history 中进行搜索。后一句是按 Tab 显示自动完成。如果结合 Ctrl - R，则更加好用。 </p>
<p>via <a href="http://amix.dk/blog/viewEntry/19030">amix</a></p>
<hr />
这是我所见过的 Bash 提示当中非常 Cool 的几个，使用它们能够让你充分地享受到 CLI的高效，并免除重复输入的麻烦，从而节省大量地时间。<br />
<OL><br />
<LI>清屏 一般来讲，为了清屏，我们通常使用 clear 命令。你有没有试过它的快捷键 Ctrl+L？个人认为使用组合键操作更快捷。<br />
<LI>逆向搜索 有时候我们需要重新执行先前输入的命令。那么，在使用快捷键 Ctrl+R 后输入命令，Bash 将为你自动完成。<br />
<LI>命令置换 谁都避免不了输入错误命令的情况，不要紧，可以使用 ^texttosobstitute^sobstitution 来置换。比如，你输入了一个sudo apt-get updkte 的错误命令，Bash 当然无法执行它了，这时可以通过输入 ^updkte^update（或 ^k^a）来纠正错误。<br />
<LI>重复上次的操作 如果你想要重复执行上次的命令，那么只需输入 !! 即可。<br />
<LI>重复上次的参数 如果你想要重复使用上次所用命令的参数，则可以使用 !$。举个例子，假如你上次执行的命令为 ls -lsh，那么，现在可以用 ls !$<br />
来达到同样的目的。 </LI></OL></p>
<hr />
以上两篇文章感谢：<a href="http://linuxtoy.org/archives/author/admin/">Toy翻译</a></p>
]]></content:encoded>
			<wfw:commentRss>http://a18zhizao.com/y2010/1319_bash-tips-big-subsidies.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux启动是自动加载的几个文件说明bashrc等</title>
		<link>http://a18zhizao.com/y2010/1242_linux-boot-is-automatically-loaded-a-few-documented-bashrc-etc.html</link>
		<comments>http://a18zhizao.com/y2010/1242_linux-boot-is-automatically-loaded-a-few-documented-bashrc-etc.html#comments</comments>
		<pubDate>Thu, 25 Feb 2010 02:26:40 +0000</pubDate>
		<dc:creator>a18ccms</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bashrc]]></category>
		<category><![CDATA[profile]]></category>
		<category><![CDATA[加载]]></category>

		<guid isPermaLink="false">http://www.a18zhizao.cn/?p=1242</guid>
		<description><![CDATA[（1）/etc/profile 全局（公有）配置，不管是哪个用户，登录时都会读取该文件。 （2）/ect/bashrc Ubuntu没有此文件，与之对应的是/ect/bash.bashrc 它也是全局（公有）的 bash执行时，不管是何种方式，都会读取此文件。 （3）~/.profile 若bash是以login方式执行时，读取~/.bash_profile，若它不存在，则读取~/.bash_login，若前两者不存在，读取~/.profile。 另外，图形模式登录时，此文件将被读取，即使存在~/.bash_profile和~/.bash_login。 （4）~/.bash_login 若bash是以login方式执行时，读取~/.bash_profile，若它不存在，则读取~/.bash_login，若前两者不存在，读取~/.profile。 （5）~/.bash_profile Unbutu默认没有此文件，可新建。 只有bash是以login形式执行时，才会读取此文件。通常该配置文件还会配置成去读取~/.bashrc。 （6）~/.bashrc 当bash是以non-login形式执行时，读取此文件。若是以login形式执行，则不会读取此文件。 （7）~/.bash_logout 注销时，且是longin形式，此文件才会读取。也就是说，在文本模式注销时，此文件会被读取，图形模式注销时，此文件不会被读取。 下面是在本机的几个例子： 1. 图形模式登录时，顺序读取：/etc/profile和~/.profile 2. 图形模式登录后，打开终端时，顺序读取：/etc/bash.bashrc和~/.bashrc 3. 文本模式登录时，顺序读取：/etc/bash.bashrc，/etc/profile和~/.bash_profile 4. 从其它用户su到该用户，则分两种情况： （1）如果带-l参数（或-参数，–login参数），如：su -l username，则bash是lonin的，它将顺序读取以下配置文件：/etc/bash.bashrc，/etc/profile和~/.bash_profile。 （2）如果没有带-l参数，则bash是non-login的，它将顺序读取：/etc/bash.bashrc和~/.bashrc 5. 注销时，或退出su登录的用户，如果是longin方式，那么bash会读取：~/.bash_logout 6. 执行自定义的shell文件时，若使用“bash -l a.sh”的方式，则bash会读取行：/etc/profile和~/.bash_profile，若使用其它方式，如：bash a.sh， ./a.sh，sh a.sh（这个不属于bash shell），则不会读取上面的任何文件。 7. 上面的例子凡是读取到~/.bash_profile的，若该文件不存在，则读取~/.bash_login，若前两者不存在，读取~/.profile。 其中PATH这个变量特殊说明一下: 如果是超级用户登录,在没有执行/etc/profile之前,PATH已经设定了下面的路径: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 如果是普通用户,PATH在/etc/profile执行之前设定了以下的路径: /usr/local/bin:/bin:/usr/bin 这里要注意的是:在用户切换并加载变量,例如su -,这时，如果用户自己切换自己,比如root用户再用su - root切换的话,加载的PATH和上面的不一样. 准确的说，会因为在/etc/profile脚本中的配置产生变化，因为它做了如下的配置: if [ [...]]]></description>
			<content:encoded><![CDATA[<p>（1）/etc/profile<br />
全局（公有）配置，不管是哪个用户，登录时都会读取该文件。</p>
<p>（2）/ect/bashrc<br />
Ubuntu没有此文件，与之对应的是/ect/bash.bashrc<br />
它也是全局（公有）的<br />
bash执行时，不管是何种方式，都会读取此文件。</p>
<p>（3）~/.profile<br />
若bash是以login方式执行时，读取~/.bash_profile，若它不存在，则读取~/.bash_login，若前两者不存在，读取~/.profile。<br />
另外，图形模式登录时，此文件将被读取，即使存在~/.bash_profile和~/.bash_login。<br />
<span id="more-1242"></span><br />
（4）~/.bash_login<br />
若bash是以login方式执行时，读取~/.bash_profile，若它不存在，则读取~/.bash_login，若前两者不存在，读取~/.profile。</p>
<p>（5）~/.bash_profile<br />
Unbutu默认没有此文件，可新建。<br />
只有bash是以login形式执行时，才会读取此文件。通常该配置文件还会配置成去读取~/.bashrc。</p>
<p>（6）~/.bashrc<br />
当bash是以non-login形式执行时，读取此文件。若是以login形式执行，则不会读取此文件。</p>
<p>（7）~/.bash_logout<br />
注销时，且是longin形式，此文件才会读取。也就是说，在文本模式注销时，此文件会被读取，图形模式注销时，此文件不会被读取。</p>
<p>下面是在本机的几个例子：<br />
1. 图形模式登录时，顺序读取：/etc/profile和~/.profile<br />
2. 图形模式登录后，打开终端时，顺序读取：/etc/bash.bashrc和~/.bashrc<br />
3. 文本模式登录时，顺序读取：/etc/bash.bashrc，/etc/profile和~/.bash_profile<br />
4. 从其它用户su到该用户，则分两种情况：<br />
（1）如果带-l参数（或-参数，–login参数），如：su -l username，则bash是lonin的，它将顺序读取以下配置文件：/etc/bash.bashrc，/etc/profile和~/.bash_profile。<br />
（2）如果没有带-l参数，则bash是non-login的，它将顺序读取：/etc/bash.bashrc和~/.bashrc<br />
5. 注销时，或退出su登录的用户，如果是longin方式，那么bash会读取：~/.bash_logout<br />
6. 执行自定义的shell文件时，若使用“bash -l a.sh”的方式，则bash会读取行：/etc/profile和~/.bash_profile，若使用其它方式，如：bash a.sh， ./a.sh，sh a.sh（这个不属于bash shell），则不会读取上面的任何文件。<br />
7. 上面的例子凡是读取到~/.bash_profile的，若该文件不存在，则读取~/.bash_login，若前两者不存在，读取~/.profile。</p>
<p>其中PATH这个变量特殊说明一下:<br />
如果是超级用户登录,在没有执行/etc/profile之前,PATH已经设定了下面的路径:<br />
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin<br />
如果是普通用户,PATH在/etc/profile执行之前设定了以下的路径:<br />
/usr/local/bin:/bin:/usr/bin<br />
这里要注意的是:在用户切换并加载变量,例如su -,这时，如果用户自己切换自己,比如root用户再用su - root切换的话,加载的PATH和上面的不一样.<br />
准确的说，会因为在/etc/profile脚本中的配置产生变化，因为它做了如下的配置:</p>
<p>if [ "`id -u`" -eq 0 ]; then<br />
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"<br />
else<br />
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/games"<br />
fi</p>
]]></content:encoded>
			<wfw:commentRss>http://a18zhizao.com/y2010/1242_linux-boot-is-automatically-loaded-a-few-documented-bashrc-etc.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

