<?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>LinuxByte &#187; shell</title>
	<atom:link href="http://www.linuxbyte.org/tag/shell/feed" rel="self" type="application/rss+xml" />
	<link>http://www.linuxbyte.org</link>
	<description>一个Linux Blog</description>
	<lastBuildDate>Thu, 26 Jan 2012 08:13:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>History 命令经典用法15例</title>
		<link>http://www.linuxbyte.org/history-ming-ling-jing-dian-yong-fa-15li.html</link>
		<comments>http://www.linuxbyte.org/history-ming-ling-jing-dian-yong-fa-15li.html#comments</comments>
		<pubDate>Wed, 16 Feb 2011 05:01:49 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[精品文档]]></category>
		<category><![CDATA[系统管理]]></category>
		<category><![CDATA[History]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=607</guid>
		<description><![CDATA[如果你经常使用 Linux 命令行，那么使用 history（历史）命令可以有效地提升你的效率。本文将通过实例的方式向你介绍 history 命令的 15 个用法。 使用 HISTTIMEFORMAT 显示时间戳 当你从命令行执行 ... ]]></description>
			<content:encoded><![CDATA[<p>如果你经常使用 Linux 命令行，那么使用 history（历史）命令可以有效地提升你的效率。本文将通过实例的方式向你介绍 history 命令的 15 个用法。</p>
<p><strong>使用 HISTTIMEFORMAT 显示时间戳</strong></p>
<p>当你从命令行执行 history 命令后，通常只会显示已执行命令的序号和命令本身。如果你想要查看命令历史的时间戳，那么可以执行：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># export HISTTIMEFORMAT='%F %T '</span>
<span style="color: #666666; font-style: italic;"># history | more</span>
<span style="color: #000000;">1</span>  <span style="color: #000000;">2008</span>-08-05 <span style="color: #000000;">19</span>:02:<span style="color: #000000;">39</span> service network restart
<span style="color: #000000;">2</span>  <span style="color: #000000;">2008</span>-08-05 <span style="color: #000000;">19</span>:02:<span style="color: #000000;">39</span> <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000;">3</span>  <span style="color: #000000;">2008</span>-08-05 <span style="color: #000000;">19</span>:02:<span style="color: #000000;">39</span> <span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #000000;">4</span>  <span style="color: #000000;">2008</span>-08-05 <span style="color: #000000;">19</span>:02:<span style="color: #000000;">39</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>redhat-release</pre></div></div>

<p><span id="more-607"></span><br />
<strong>注意</strong>：这个功能只能用在当 HISTTIMEFORMAT 这个环境变量被设置之后，之后的那些新执行的 bash 命令才会被打上正确的时间戳。在此之前的所有命令，都将会显示成设置 HISTTIMEFORMAT 变量的时间。[感谢 NightOwl 读者补充]</p>
<p><strong>使用 Ctrl+R 搜索历史</strong></p>
<p>Ctrl+R 是我经常使用的一个快捷键。此快捷键让你对命令历史进行搜索，对于想要重复执行某个命令的时候非常有用。当找到命令后，通常再按回车键就可以执行该命令。如果想对找到的命令进行调整后再执行，则可以按一下左或右方向键。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># [Press Ctrl+R from the command prompt, which will display the reverse-i-search prompt]</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>reverse-i-search<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">red</span>‘: <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>redhat-release
<span style="color: #7a0874; font-weight: bold;">&#91;</span>Note: Press enter when you see your <span style="color: #7a0874; font-weight: bold;">command</span>, <span style="color: #c20cb9; font-weight: bold;">which</span> will execute the <span style="color: #7a0874; font-weight: bold;">command</span> from the <span style="color: #7a0874; font-weight: bold;">history</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># cat /etc/redhat-release</span>
Fedora release <span style="color: #000000;">9</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Sulphur<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p><strong>快速重复执行上一条命令</strong></p>
<p>有 4 种方法可以重复执行上一条命令：</p>
<ol>
<li>使用上方向键，并回车执行。</li>
<li>按 !! 并回车执行。</li>
<li>输入 !-1 并回车执行。</li>
<li>按 Ctrl+P 并回车执行。</li>
</ol>
<p><strong>从命令历史中执行一个指定的命令</strong></p>
<p>在下面的例子中，如果你想重复执行第 4 条命令，那么可以执行 !4：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># history | more</span>
<span style="color: #000000;">1</span>  service network restart
<span style="color: #000000;">2</span>  <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000;">3</span>  <span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #000000;">4</span>  <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>redhat-release
<span style="color: #666666; font-style: italic;"># !4</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>redhat-release
Fedora release <span style="color: #000000;">9</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Sulphur<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p><strong>通过指定关键字来执行以前的命令</strong></p>
<p>在下面的例子，输入 !ps 并回车，将执行以 ps 打头的命令：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># !ps</span>
<span style="color: #c20cb9; font-weight: bold;">ps</span> aux <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> yp
root     <span style="color: #000000;">16947</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.1</span>  <span style="color: #000000;">36516</span>  <span style="color: #000000;">1264</span> ?        Sl   <span style="color: #000000;">13</span>:<span style="color: #000000;">10</span>   <span style="color: #000000;">0</span>:00 ypbind
root     <span style="color: #000000;">17503</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.0</span>   <span style="color: #000000;">4124</span>   <span style="color: #000000;">740</span> pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>    S+   <span style="color: #000000;">19</span>:<span style="color: #000000;">19</span>   <span style="color: #000000;">0</span>:00 <span style="color: #c20cb9; font-weight: bold;">grep</span> yp</pre></div></div>

<p><strong>使用 HISTSIZE 控制历史命令记录的总行数</strong></p>
<p>将下面两行内容追加到 .bash_profile 文件并重新登录 bash shell，命令历史的记录数将变成 450 条：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vi ~/.bash_profile</span>
<span style="color: #007800;">HISTSIZE</span>=<span style="color: #000000;">450</span>
<span style="color: #007800;">HISTFILESIZE</span>=<span style="color: #000000;">450</span></pre></div></div>

<p><strong>使用 HISTFILE 更改历史文件名称</strong></p>
<p>默认情况下，命令历史存储在 ~/.bash<em>history 文件中。添加下列内容到 .bash</em>profile 文件并重新登录 bash shell，将使用 .commandline_warrior 来存储命令历史：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vi ~/.bash_profile</span>
<span style="color: #007800;">HISTFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.commandline_warrior</pre></div></div>

<p><strong>使用 HISTCONTROL 从命令历史中剔除连续重复的条目</strong></p>
<p>在下面的例子中，pwd 命令被连续执行了三次。执行 history 后你会看到三条重复的条目。要剔除这些重复的条目，你可以将 HISTCONTROL 设置为 ignoredups：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># pwd</span>
<span style="color: #666666; font-style: italic;"># pwd</span>
<span style="color: #666666; font-style: italic;"># pwd</span>
<span style="color: #666666; font-style: italic;"># history | tail -4</span>
<span style="color: #000000;">44</span>  <span style="color: #7a0874; font-weight: bold;">pwd</span>
<span style="color: #000000;">45</span>  <span style="color: #7a0874; font-weight: bold;">pwd</span>
<span style="color: #000000;">46</span>  <span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Note that there are three <span style="color: #7a0874; font-weight: bold;">pwd</span> commands <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #7a0874; font-weight: bold;">history</span>, after executing <span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">times</span> <span style="color: #c20cb9; font-weight: bold;">as</span> shown above<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">47</span>  <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-4</span>
<span style="color: #666666; font-style: italic;"># export HISTCONTROL=ignoredups</span>
<span style="color: #666666; font-style: italic;"># pwd</span>
<span style="color: #666666; font-style: italic;"># pwd</span>
<span style="color: #666666; font-style: italic;"># pwd</span>
<span style="color: #666666; font-style: italic;"># history | tail -3</span>
<span style="color: #000000;">56</span>  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTCONTROL</span>=ignoredups
<span style="color: #000000;">57</span>  <span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Note that there is only one <span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #7a0874; font-weight: bold;">command</span> <span style="color: #000000; font-weight: bold;">in</span> the <span style="color: #7a0874; font-weight: bold;">history</span>, even after executing <span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">times</span> <span style="color: #c20cb9; font-weight: bold;">as</span> shown above<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">58</span>  <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-4</span></pre></div></div>

<p><strong>使用 HISTCONTROL 清除整个命令历史中的重复条目</strong></p>
<p>上例中的 ignoredups 只能剔除连续的重复条目。要清除整个命令历史中的重复条目，可以将 HISTCONTROL 设置成 erasedups：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># export HISTCONTROL=erasedups</span>
<span style="color: #666666; font-style: italic;"># pwd</span>
<span style="color: #666666; font-style: italic;"># service httpd stop</span>
<span style="color: #666666; font-style: italic;"># history | tail -3</span>
<span style="color: #000000;">38</span>  <span style="color: #7a0874; font-weight: bold;">pwd</span>
<span style="color: #000000;">39</span>  service httpd stop
<span style="color: #000000;">40</span>  <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-3</span>
<span style="color: #666666; font-style: italic;"># ls -ltr</span>
<span style="color: #666666; font-style: italic;"># service httpd stop</span>
<span style="color: #666666; font-style: italic;"># history | tail -6</span>
<span style="color: #000000;">35</span>  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTCONTROL</span>=erasedups
<span style="color: #000000;">36</span>  <span style="color: #7a0874; font-weight: bold;">pwd</span>
<span style="color: #000000;">37</span>  <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-3</span>
<span style="color: #000000;">38</span>  <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-ltr</span>
<span style="color: #000000;">39</span>  service httpd stop
<span style="color: #7a0874; font-weight: bold;">&#91;</span>Note that the previous service httpd stop after <span style="color: #7a0874; font-weight: bold;">pwd</span> got erased<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">40</span>  <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-6</span></pre></div></div>

<p><strong>使用 HISTCONTROL 强制 history 不记住特定的命令</strong></p>
<p>将 HISTCONTROL 设置为 ignorespace，并在不想被记住的命令前面输入一个空格：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># export HISTCONTROL=ignorespace</span>
<span style="color: #666666; font-style: italic;"># ls -ltr</span>
<span style="color: #666666; font-style: italic;"># pwd</span>
<span style="color: #666666; font-style: italic;">#  service httpd stop [Note that there is a space at the beginning of service, to ignore this command from history]</span>
<span style="color: #666666; font-style: italic;"># history | tail -3</span>
<span style="color: #000000;">67</span>  <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-ltr</span>
<span style="color: #000000;">68</span>  <span style="color: #7a0874; font-weight: bold;">pwd</span>
<span style="color: #000000;">69</span>  <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-3</span></pre></div></div>

<p><strong>使用 -c 选项清除所有的命令历史</strong></p>
<p>如果你想清除所有的命令历史，可以执行：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># history -c</span></pre></div></div>

<p><strong>命令替换</strong></p>
<p>在下面的例子里，!!:$ 将为当前的命令获得上一条命令的参数：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ls anaconda-ks.cfg</span>
anaconda-ks.cfg
<span style="color: #666666; font-style: italic;"># vi !!:$</span>
<span style="color: #c20cb9; font-weight: bold;">vi</span> anaconda-ks.cfg</pre></div></div>

<p><strong>补充</strong>：使用 !$ 可以达到同样的效果，而且更简单。[感谢 wanzigunzi 读者补充]</p>
<p>下例中，!^ 从上一条命令获得第一项参数：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cp anaconda-ks.cfg anaconda-ks.cfg.bak</span>
anaconda-ks.cfg
<span style="color: #666666; font-style: italic;"># vi -5 !^</span>
<span style="color: #c20cb9; font-weight: bold;">vi</span> anaconda-ks.cfg</pre></div></div>

<p><strong>为特定的命令替换指定的参数</strong></p>
<p>在下面的例子，!cp:2 从命令历史中搜索以 cp 开头的命令，并获取它的第二项参数：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cp ~/longname.txt /really/a/very/long/path/long-filename.txt</span>
<span style="color: #666666; font-style: italic;"># ls -l !cp:2</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>really<span style="color: #000000; font-weight: bold;">/</span>a<span style="color: #000000; font-weight: bold;">/</span>very<span style="color: #000000; font-weight: bold;">/</span>long<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>long-filename.txt</pre></div></div>

<p>下例里，!cp:$ 获取 cp 命令的最后一项参数：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ls -l !cp:$</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>really<span style="color: #000000; font-weight: bold;">/</span>a<span style="color: #000000; font-weight: bold;">/</span>very<span style="color: #000000; font-weight: bold;">/</span>long<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>long-filename.txt</pre></div></div>

<p><strong>使用 HISTSIZE 禁用 history</strong></p>
<p>如果你想禁用 history，可以将 HISTSIZE 设置为 0：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># export HISTSIZE=0</span>
<span style="color: #666666; font-style: italic;"># history</span>
<span style="color: #666666; font-style: italic;"># [Note that history did not display anything]</span></pre></div></div>

<p><strong>使用 HISTIGNORE 忽略历史中的特定命令</strong></p>
<p>下面的例子，将忽略 pwd、ls、ls -ltr 等命令：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># export HISTIGNORE=”pwd:ls:ls -ltr:”</span>
<span style="color: #666666; font-style: italic;"># pwd</span>
<span style="color: #666666; font-style: italic;"># ls</span>
<span style="color: #666666; font-style: italic;"># ls -ltr</span>
<span style="color: #666666; font-style: italic;"># service httpd stop</span>
<span style="color: #666666; font-style: italic;"># history | tail -3</span>
<span style="color: #000000;">79</span>  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTIGNORE</span>=”<span style="color: #7a0874; font-weight: bold;">pwd</span>:<span style="color: #c20cb9; font-weight: bold;">ls</span>:<span style="color: #c20cb9; font-weight: bold;">ls</span> -ltr:”
<span style="color: #000000;">80</span>  service httpd stop
<span style="color: #000000;">81</span>  <span style="color: #7a0874; font-weight: bold;">history</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>Note that <span style="color: #7a0874; font-weight: bold;">history</span> did not record <span style="color: #7a0874; font-weight: bold;">pwd</span>, <span style="color: #c20cb9; font-weight: bold;">ls</span> and <span style="color: #c20cb9; font-weight: bold;">ls</span> -ltr<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>原文地址：</p>
<p>http://www.javaeye.com/topic/835928</p>
<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/unixshellbian-cheng-di-san-ban.html" title="Unix.Shell编程(第三版)">Unix.Shell编程(第三版)</a></li><li><a href="http://www.linuxbyte.org/yong-shc-jiami-shell.html" title="用shc 加密shell">用shc 加密shell</a></li><li><a href="http://www.linuxbyte.org/shel-fang-zhi-wu-cao-zuo.html" title="用 !$ 防止误操作">用 !$ 防止误操作</a></li><li><a href="http://www.linuxbyte.org/fun-unix-shell.html" title="一些奇怪的unix指令名字的由来">一些奇怪的unix指令名字的由来</a></li><li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合">几个有用的bash shell组合</a></li></ul><hr />
<p><small>© xiao H for <a href="http://www.linuxbyte.org">LinuxByte</a>, 2011<br />
Source: <a href="http://www.linuxbyte.org/history-ming-ling-jing-dian-yong-fa-15li.html">History 命令经典用法15例</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/history" rel="tag">History</a>, <a href="http://www.linuxbyte.org/tag/shell" rel="tag">shell</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/history" title="History" rel="tag">History</a>, <a href="http://www.linuxbyte.org/tag/shell" title="shell" rel="tag">shell</a></p>

<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxbyte.org/history-ming-ling-jing-dian-yong-fa-15li.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unix.Shell编程(第三版)</title>
		<link>http://www.linuxbyte.org/unixshellbian-cheng-di-san-ban.html</link>
		<comments>http://www.linuxbyte.org/unixshellbian-cheng-di-san-ban.html#comments</comments>
		<pubDate>Fri, 17 Jul 2009 11:49:50 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[系统管理]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[编程]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=458</guid>
		<description><![CDATA[Unix.Shell编程(第三版) 下载：PDF 文件 for douban doubanclaimc002b5a031b69e8a 与本文关系暧昧的文字History 命令经典用法15例用shc 加密shell用 !$ 防止误操作一些奇怪的unix指令名字的由来几个有用的bash shell... ]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.linuxbyte.org/uploads/2009/07/unix-shell.png" alt="unix-shell" title="unix-shell" width="399" height="543" class="alignnone size-full wp-image-459" /><br />
<span id="more-458"></span><br />
Unix.Shell编程(第三版)<br />
下载：<a href="http://www.linuxbyte.org/uploads/2009/07/Unix-Shell.pdf">PDF 文件</a></p>
<p>for douban<br />
doubanclaimc002b5a031b69e8a</p>
<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/history-ming-ling-jing-dian-yong-fa-15li.html" title="History 命令经典用法15例">History 命令经典用法15例</a></li><li><a href="http://www.linuxbyte.org/yong-shc-jiami-shell.html" title="用shc 加密shell">用shc 加密shell</a></li><li><a href="http://www.linuxbyte.org/shel-fang-zhi-wu-cao-zuo.html" title="用 !$ 防止误操作">用 !$ 防止误操作</a></li><li><a href="http://www.linuxbyte.org/fun-unix-shell.html" title="一些奇怪的unix指令名字的由来">一些奇怪的unix指令名字的由来</a></li><li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合">几个有用的bash shell组合</a></li></ul><hr />
<p><small>© xiao H for <a href="http://www.linuxbyte.org">LinuxByte</a>, 2009<br />
Source: <a href="http://www.linuxbyte.org/unixshellbian-cheng-di-san-ban.html">Unix.Shell编程(第三版)</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/shell" rel="tag">shell</a>, <a href="http://www.linuxbyte.org/tag/%e7%bc%96%e7%a8%8b" rel="tag">编程</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/shell" title="shell" rel="tag">shell</a>, <a href="http://www.linuxbyte.org/tag/%e7%bc%96%e7%a8%8b" title="编程" rel="tag">编程</a></p>

<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxbyte.org/unixshellbian-cheng-di-san-ban.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>用shc 加密shell</title>
		<link>http://www.linuxbyte.org/yong-shc-jiami-shell.html</link>
		<comments>http://www.linuxbyte.org/yong-shc-jiami-shell.html#comments</comments>
		<pubDate>Thu, 09 Apr 2009 13:32:00 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[日常桌面]]></category>
		<category><![CDATA[shc]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[加密]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=405</guid>
		<description><![CDATA[Shell 在Linux 系统中的强大有目共睹，每个管理员都是自己写的一组shell 来简化自己的工作，有时我们会把自己写的shell 让别人用，但这时有一个麻烦的地方，就是shell 里包含一些敏感信息如帐... ]]></description>
			<content:encoded><![CDATA[<p>Shell 在Linux 系统中的强大有目共睹，每个管理员都是自己写的一组shell 来简化自己的工作，有时我们会把自己写的shell 让别人用，但这时有一个麻烦的地方，就是shell 里包含一些敏感信息如帐号密码等，这时我们需要一个工具&#8211;shc 把我们的shell 加密。</p>
<p>shc是一个脚本编译工具, 使用RC4加密算法, 它能够把shell程序转换成二进制可执行文件(支持静态链接和动态链接)。<br />
shc主页:</p>
<p>http://www.datsi.fi.upm.es/%7Efrosal/</p>
<p><span id="more-405"></span><br />
<strong>安装shc</strong><br />
大部分的系统都在自己的源中提供shc 的二进制安装包，如果不幸你的系统中没有则可以去软件主页下载源码包自己安装。<br />
源码安装：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.datsi.fi.upm.es<span style="color: #000000; font-weight: bold;">/%</span>7Efrosal<span style="color: #000000; font-weight: bold;">/</span>sources<span style="color: #000000; font-weight: bold;">/</span>shc-3.8.6.tgz
 <span style="color: #c20cb9; font-weight: bold;">tar</span> vxf shc-3.8.6.tgz
 <span style="color: #7a0874; font-weight: bold;">cd</span> shc-3.8.6
 <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #7a0874; font-weight: bold;">test</span>
 <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">strings</span>
 <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p><strong>shc的使用方法:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">shc <span style="color: #660033;">-v</span> <span style="color: #660033;">-f</span> myshell.sh  <span style="color: #666666; font-style: italic;">#-f 为要加密的shell</span></pre></div></div>

<p>运行后会生成两个文件: myshell.sh.x 和 myshell.sh.x.c<br />
shc -r -f.x 为可执行的二进制文件，myshell.sh.x.c为该文件的C原文件。</p>
<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/history-ming-ling-jing-dian-yong-fa-15li.html" title="History 命令经典用法15例">History 命令经典用法15例</a></li><li><a href="http://www.linuxbyte.org/firegpg-fei-chang-hao-yong-de-gpg-gong-ju.html" title="FireGPG-非常好用的GPG工具">FireGPG-非常好用的GPG工具</a></li><li><a href="http://www.linuxbyte.org/unixshellbian-cheng-di-san-ban.html" title="Unix.Shell编程(第三版)">Unix.Shell编程(第三版)</a></li><li><a href="http://www.linuxbyte.org/linux-xia-de-wen-jian-jia-mi.html" title="Linux 下的文件加密">Linux 下的文件加密</a></li><li><a href="http://www.linuxbyte.org/wo-de-gnupg-shi-yong-bi-ji.html" title="我的GnuPG 使用笔记">我的GnuPG 使用笔记</a></li><li><a href="http://www.linuxbyte.org/yong-cryptkeeperhe-encfs-wan-cheng-mu-lu-jia-mi.html" title="用Cryptkeeper和EncFS 完成目录加密">用Cryptkeeper和EncFS 完成目录加密</a></li><li><a href="http://www.linuxbyte.org/cryptsetup-luks-jiami.html" title="用Cryptsetup LUKS 加密目录">用Cryptsetup LUKS 加密目录</a></li><li><a href="http://www.linuxbyte.org/shel-fang-zhi-wu-cao-zuo.html" title="用 !$ 防止误操作">用 !$ 防止误操作</a></li><li><a href="http://www.linuxbyte.org/fun-unix-shell.html" title="一些奇怪的unix指令名字的由来">一些奇怪的unix指令名字的由来</a></li><li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合">几个有用的bash shell组合</a></li></ul><hr />
<p><small>© xiao H for <a href="http://www.linuxbyte.org">LinuxByte</a>, 2009<br />
Source: <a href="http://www.linuxbyte.org/yong-shc-jiami-shell.html">用shc 加密shell</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/shc" rel="tag">shc</a>, <a href="http://www.linuxbyte.org/tag/shell" rel="tag">shell</a>, <a href="http://www.linuxbyte.org/tag/%e5%8a%a0%e5%af%86" rel="tag">加密</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/shc" title="shc" rel="tag">shc</a>, <a href="http://www.linuxbyte.org/tag/shell" title="shell" rel="tag">shell</a>, <a href="http://www.linuxbyte.org/tag/%e5%8a%a0%e5%af%86" title="加密" rel="tag">加密</a></p>

<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxbyte.org/yong-shc-jiami-shell.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用 !$ 防止误操作</title>
		<link>http://www.linuxbyte.org/shel-fang-zhi-wu-cao-zuo.html</link>
		<comments>http://www.linuxbyte.org/shel-fang-zhi-wu-cao-zuo.html#comments</comments>
		<pubDate>Sat, 01 Nov 2008 05:26:57 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=325</guid>
		<description><![CDATA[作者：galeki 原文地址：http://www.linuxgem.org/posts/5769.html shell 的通配符匹配非常强大，不过也非常危险，不少同学都碰到这样的问题，比如 rm a*，结果一个手抖，a 和星号之间多了个空格，结果目... ]]></description>
			<content:encoded><![CDATA[<p>作者：galeki 原文地址：http://www.linuxgem.org/posts/5769.html</p>
<p>shell 的通配符匹配非常强大，不过也非常危险，不少同学都碰到这样的问题，比如 rm a*，结果一个手抖，a 和星号之间多了个空格，结果目录下的文件都灰飞烟灭了……</p>
<p>bash 支持一个特殊的变量 !$，永远保存着前一条命令的最后一个参数，例如：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> hello world
hello world
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">!</span>$
world</pre></div></div>

<p><span id="more-325"></span><br />
那么，这和防止误操作有什么关系呢？</p>
<p>比如你要删除以 a 打头的文件，可以先通过 ls 确定一下：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> a<span style="color: #000000; font-weight: bold;">*</span>
a1.txt  a2.txt  a3.txt  a4.txt</pre></div></div>

<p>如果确认无误，之后只要：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">rm</span>  <span style="color: #000000; font-weight: bold;">!</span>$</pre></div></div>

<p>!$ 自动替换为上个命令的 a*，就可以把这些文件干掉了～  不会再出现手抖打错的情况了，如果通配符确实出了问题，第一步 ls 就可以发现   。</p>
<p>还可以通过快捷键 Esc +  .  快速输入上个命令的最后一个参数，免去了输入 !$ 的麻烦 ～ ( 多谢 druggo 补充 :)</p>
<p>如果你想一次删除多个项目，还可以使用 !* ( 多谢 qt 补充 : )。</p>
<p>!* 保存着上一条命令的所有参数，例如：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> a<span style="color: #000000; font-weight: bold;">*</span> b<span style="color: #000000; font-weight: bold;">*</span>
a1.txt  a2.txt  b1.txt  b2.txt</pre></div></div>

<p>确认无误后，通过 !* 来删除：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">rm</span>  <span style="color: #000000; font-weight: bold;">!*</span></pre></div></div>

<p>限制就是前面的 ls 命令，不能带有参数，否则参数也会传给 rm。</p>
<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/history-ming-ling-jing-dian-yong-fa-15li.html" title="History 命令经典用法15例">History 命令经典用法15例</a></li><li><a href="http://www.linuxbyte.org/unixshellbian-cheng-di-san-ban.html" title="Unix.Shell编程(第三版)">Unix.Shell编程(第三版)</a></li><li><a href="http://www.linuxbyte.org/yong-shc-jiami-shell.html" title="用shc 加密shell">用shc 加密shell</a></li><li><a href="http://www.linuxbyte.org/fun-unix-shell.html" title="一些奇怪的unix指令名字的由来">一些奇怪的unix指令名字的由来</a></li><li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合">几个有用的bash shell组合</a></li></ul><hr />
<p><small>© xiao H for <a href="http://www.linuxbyte.org">LinuxByte</a>, 2008<br />
Source: <a href="http://www.linuxbyte.org/shel-fang-zhi-wu-cao-zuo.html">用 !$ 防止误操作</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/shell" rel="tag">shell</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/shell" title="shell" rel="tag">shell</a></p>

<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxbyte.org/shel-fang-zhi-wu-cao-zuo.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>一些奇怪的unix指令名字的由来</title>
		<link>http://www.linuxbyte.org/fun-unix-shell.html</link>
		<comments>http://www.linuxbyte.org/fun-unix-shell.html#comments</comments>
		<pubDate>Tue, 26 Aug 2008 15:38:33 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[日常桌面]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=230</guid>
		<description><![CDATA[awk = “Aho Weinberger and Kernighan” 这个语言以作者 Al Aho, Peter Weinberger 和 Brian Kernighan 的 姓来命名。 grep = “Global Regular Expression Print” grep 源自 ed。用来打印所有符合某 pattern 的指令 g/re/p “re” ... ]]></description>
			<content:encoded><![CDATA[<p>awk = “Aho Weinberger and Kernighan”<br />
这个语言以作者 Al Aho, Peter Weinberger 和 Brian Kernighan 的 姓来命名。</p>
<p>grep = “Global Regular Expression Print”<br />
grep 源自 ed。用来打印所有符合某 pattern 的指令<br />
g/re/p</p>
<p><span id="more-230"></span></p>
<p>“re” 代表 regular expression</p>
<p>fgrep = “Fixed GREP”.<br />
fgrep 祇找固定的字符串。 “f” 不是代表 “fast” &#8211; 事实上 “fgrep foobar *.c” 通常比 “egrep foobar *.c” 来得慢(有点意外吧，不信 的话，自己试试喽)。<br />
尽管如此，fgrep 仍然有可取之处，在档案中搜寻字符串时， fgrep 能处理的字符串数目较 egrep 多。</p>
<p>egrep = “Extended GREP”<br />
egrep 用比 grep 更 fancy 的 regular rexpression。许多人只用 egrep， 因为它用的 algorithm 比 grep 或 fgrep 用的要好一些， 而且通常是三个 程序中最快的。</p>
<p>cat = “CATenate”<br />
catenate 是一个满暧昧的字，在这里的意思是”把它连成一串”, 这就是 “cat” 这个指令对一个或多个档案所做的处理。<br />
请不要跟 C/A/T 混淆了，C/A/T 是指计算机辅助排版系统 (Computer Aided Typesetter)。</p>
<p>gecos = “General Electric Comprehensive Operating Supervisor”<br />
不过，通用电器的大型系统部门卖给 Honeywell 后， Honeywell 就把 GECOS 的 E 拿掉了。<br />
目前 Unix 的密码文件里面仍保有 “pw_gecos” 这个字段。这个名字是 从古早的年代沿用过来的。</p>
<p>Dennis Ritchie 曾经说过：”有时候我们会把印表输出或整批工作丢到 GCOS 机器。密码文件里 面的 gcos 字段是用来隐藏 $IDENT 卡片上的信息，这样做不够优雅”。</p>
<p>nroff = “New ROFF”<br />
troff = “Typesetter new ROFF”<br />
这些字都是从”roff”衍生的, roff 是重写 Multics 上的 runoff 程序得来 的 (runoff 的意思就是”印出文件”)。</p>
<p>tee = T<br />
这是管线工人的术语，代表 T 型的管线分叉器。</p>
<p>bss = “Block Started by Symbol” (由符号启始的区块）<br />
Dennis Ritchie 曾说过：这个缩写也许有其它说法，但事实上我们采用这个缩写的本意是 “Block Started by Symbol”。它是 FAP 上的伪指令，FAP (Fortran Assembly [-er?] Program) 是指 IBM 704-709-7090-7094 这种机型的组译器。这个指令可定义自己的标号，并且预留一定数目 的字组空间。还有另一个伪指令 BES，是 “Block Ended by Symbol”，跟 BSS 指令几乎一样，不同点在于标号是定义在预留字组 空间尾端的地址 + 1 的地方。在这些机器上，Fortran 的数组是以反 方向储存，而且数组的索引是从 1 算起。<br />
这种用法是合理的，因为这跟 UNIX 上标准的程序加载器一样，程序 码当中并非真的放入这一整块预留空间，而是先用一个数目表示，在 载入时才真的把所需的预留空间定出来。</p>
<p>biff = “BIFF”<br />
这个指令是用来设定当您有新邮件进来时，是否要通知您。这是柏克 莱大学校园内一只狗的名字。<br />
我可以确定这个名称的起源，如果您有兴趣的话，Biff 是 Heidi Stettner 养的宠物，想当年 Heidi (还有我，跟 Bill Joy) 都还是 UCB 的研究生时，早期的 BSD 版本还在发展中。Biff 受到流连于 Evans Halls 这些人的喜爱，也因为它会对前来的邮差吠叫而闻名；因 此就以 biff 当作指令的名称。 (这是卡内基美浓大学的 Eric Cooper 证实的）</p>
<p>rc (像是 “.cshrc” 或 “/etc/rc” 中的 rc 这两个字母) = “RunCom”<br />
“rc” 源自麻省理工学院在 1965 年发展的 CTSS 系统中的 “runcom”。 Brian Kernighan 与 Dennis Ritchie 告诉 Vicki Brown 说:<br />
相关文献写着这么一段话: &#8216;CTSS 具有从档案中取出一系列命令 来执行的功能；这功能称为 “run commands” 又称为 “runcom”， 而这种档案称为一个 runcom (a runcom)。&#8217;<br />
Unix 中的 “rc” 就是这种用法的残迹。</p>
<p>此外 “rc” 也是Plan 9 操作系统 shell 的名字。<br />
Perl = “Practical Extraction and Report Language”<br />
Perl = “Pathologically Eclectic Rubbish Lister”<br />
Perl是 Larry Wall 所发展的一种相当受欢迎的语言，Perl 在处文字， process，与档案时非常便利，可以说是兼得 shell 与 C 之长。想知道 更多关于 Perl 的讯息，请看 Usenet newsgroup comp.lang.perl。<br />
Don Libes 的 “Life with Unix” 一书里有更多这类的珍闻轶事。<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Next: “comp.unix.questions” 和 “info-unix” mailing Up: 一般性的问题 Previous: 当有人提及 &#8216;rn(1)&#8217; 或 &#8216;ctime(3)&#8217;</p>
<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/history-ming-ling-jing-dian-yong-fa-15li.html" title="History 命令经典用法15例">History 命令经典用法15例</a></li><li><a href="http://www.linuxbyte.org/unixshellbian-cheng-di-san-ban.html" title="Unix.Shell编程(第三版)">Unix.Shell编程(第三版)</a></li><li><a href="http://www.linuxbyte.org/yong-shc-jiami-shell.html" title="用shc 加密shell">用shc 加密shell</a></li><li><a href="http://www.linuxbyte.org/shel-fang-zhi-wu-cao-zuo.html" title="用 !$ 防止误操作">用 !$ 防止误操作</a></li><li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合">几个有用的bash shell组合</a></li></ul><hr />
<p><small>© xiao H for <a href="http://www.linuxbyte.org">LinuxByte</a>, 2008<br />
Source: <a href="http://www.linuxbyte.org/fun-unix-shell.html">一些奇怪的unix指令名字的由来</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/shell" rel="tag">shell</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/shell" title="shell" rel="tag">shell</a></p>

<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxbyte.org/fun-unix-shell.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>几个有用的bash shell组合</title>
		<link>http://www.linuxbyte.org/fun-bash-shell.html</link>
		<comments>http://www.linuxbyte.org/fun-bash-shell.html#comments</comments>
		<pubDate>Fri, 07 Mar 2008 14:29:59 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[Bash]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/%e5%87%a0%e4%b8%aa%e6%9c%89%e7%94%a8%e7%9a%84bash-shell%e7%bb%84%e5%90%88</guid>
		<description><![CDATA[ps aux &#124; awk '{ if ($3 &#38;gt; 8 ) print $2}' 这个是列出cpu 占有率高于 8% 的进程的PID cat /proc/net/arp &#124; awk '{print $4 $1}' &#38;gt;&#38;gt;/etc/ethers 读取当前机器arp 表并把得到的mac 地址和相应的ip 地址添... ]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ps</span> aux <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ if ($3 &amp;gt; 8 ) print $2}'</span></pre></div></div>

<p>这个是列出cpu 占有率高于 8% 的进程的PID</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>arp <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4 $1}'</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ethers</pre></div></div>

<p>读取当前机器arp 表并把得到的mac 地址和相应的ip 地址添加到/etc/ethers 文件中去</p>
<p><span id="more-50"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>hda1 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; mydata-hda1.gz</pre></div></div>

<p>读取hda1 分区内容并将其打包压缩为mydata-hda1.gz</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #660033;">-dc</span> mydata-hda1.gz <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">dd</span> ō<span style="color: #007800;">f</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>hda1</pre></div></div>

<p>将压缩文件恢复写回hda1 分区<br />
这两个是一组备份和恢复命令，是直接读取写入分区的。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> :<span style="color: #000000; font-weight: bold;">|</span>:<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #7a0874; font-weight: bold;">&#125;</span>; :   </pre></div></div>

<p> <br />
这个是用来让系统死机的（不信的话可以用root 试试 _-!）分两部分，第一个部分是定义函数，第二个部分是调用这个函数<br />
:()定义函数，函数名:<br />
{ :|:&amp; }函数的主体<br />
;两个命令的分割<br />
:调用函数</p>
<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/zui-shou-huan-ying-de-10ge-linux-dan-xing-ming-ling.html" title="最受欢迎的10个 Linux 单行命令">最受欢迎的10个 Linux 单行命令</a></li><li><a href="http://www.linuxbyte.org/history-ming-ling-jing-dian-yong-fa-15li.html" title="History 命令经典用法15例">History 命令经典用法15例</a></li><li><a href="http://www.linuxbyte.org/bash-shell-kuai-jie-jian.html" title="Bash Shell 快捷键">Bash Shell 快捷键</a></li><li><a href="http://www.linuxbyte.org/unixshellbian-cheng-di-san-ban.html" title="Unix.Shell编程(第三版)">Unix.Shell编程(第三版)</a></li><li><a href="http://www.linuxbyte.org/yong-shc-jiami-shell.html" title="用shc 加密shell">用shc 加密shell</a></li><li><a href="http://www.linuxbyte.org/bash-remove-operating-system.html" title="dell 的 Remove Operating System 代码">dell 的 Remove Operating System 代码</a></li><li><a href="http://www.linuxbyte.org/shel-fang-zhi-wu-cao-zuo.html" title="用 !$ 防止误操作">用 !$ 防止误操作</a></li><li><a href="http://www.linuxbyte.org/fun-unix-shell.html" title="一些奇怪的unix指令名字的由来">一些奇怪的unix指令名字的由来</a></li><li><a href="http://www.linuxbyte.org/bash-tips.html" title="我常用的小shell">我常用的小shell</a></li><li><a href="http://www.linuxbyte.org/bash-quick-reference-bash-redirection.html" title="Bash的输入输出重定向">Bash的输入输出重定向</a></li></ul><hr />
<p><small>© xiao H for <a href="http://www.linuxbyte.org">LinuxByte</a>, 2008<br />
Source: <a href="http://www.linuxbyte.org/fun-bash-shell.html">几个有用的bash shell组合</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/bash" rel="tag">Bash</a>, <a href="http://www.linuxbyte.org/tag/shell" rel="tag">shell</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/bash" title="Bash" rel="tag">Bash</a>, <a href="http://www.linuxbyte.org/tag/shell" title="shell" rel="tag">shell</a></p>

<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxbyte.org/fun-bash-shell.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

