<?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/category/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>一条很酷的 vim 技巧</title>
		<link>http://www.linuxbyte.org/yi-tiao-hen-ku-de-vim-ji-qiao.html</link>
		<comments>http://www.linuxbyte.org/yi-tiao-hen-ku-de-vim-ji-qiao.html#comments</comments>
		<pubDate>Wed, 16 Feb 2011 06:05:13 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[技巧]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=609</guid>
		<description><![CDATA[Vim 中截取部分内容保存到其他文件。 按 Escape进入命令模式，然后输入 :start,endw file，其中的 start 是当前文件中要保存的第一行，end 是要保存的最后一行，w 表示希望写到另一个文件中（或者... ]]></description>
			<content:encoded><![CDATA[<p><strong>Vim 中截取部分内容保存到其他文件。</strong><br />
按 Escape进入命令模式，然后输入 :start,endw file，其中的 start 是当前文件中要保存的第一行，end 是要保存的最后一行，w 表示希望写到另一个文件中（或者覆盖现有的文件），file 是指定的部分要保存到的文件。对于最后一行，可以使用 $ 表示文件的末尾。可以在 w 后面使用两个大于号（>>）表示希望把内容附加到文件中而不是覆盖文件。<br />
<span id="more-609"></span><br />
举例：</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">  1 deb http://mirrors.163.com/ubuntu/ lucid main restricted universe multiverse
  2 deb http://mirrors.163.com/ubuntu/ lucid-security main restricted universe multiverse
  3 deb http://mirrors.163.com/ubuntu/ lucid-updates main restricted universe multiverse
  4 deb http://mirrors.163.com/ubuntu/ lucid-proposed main restricted universe multiverse
  5 deb http://mirrors.163.com/ubuntu/ lucid-backports main restricted universe multiverse
  6 # deb-src http://mirrors.163.com/ubuntu/ karmic main restricted universe multiverse
  7 # deb-src http://mirrors.163.com/ubuntu/ karmic-security main restricted universe multiverse
  8 # deb-src http://mirrors.163.com/ubuntu/ karmic-updates main restricted universe multiverse
  9 # deb-src http://mirrors.163.com/ubuntu/ karmic-proposed main restricted universe multiverse
 10 # deb-src http://mirrors.163.com/ubuntu/ karmic-backports main restricted universe multiverse
 11 # deb http://deb.torproject.org/torproject.org karmic main
 12 deb http://archive.ubuntu.com/ubuntu/ lucid multiverse universe
 13 # deb http://mirror.netcologne.de/torproject.org lucid main # 已禁止升级到 lucid
 14 # deb http://ppa.launchpad.net/ibus-dev/ibus-1.2-karmic/ubuntu lucid main # 已禁止升级到 lucid
 15 # deb http://kubuntu-repo.googlecode.com/files /
 16 deb http://download.virtualbox.org/virtualbox/debian lucid contrib
 17 
 18 deb http://getswiftfox.com/builds/debian unstable non-free
~                                                                                                           
~                                                                                                           
~                                                                                                           
~                                                                                                           
~                                                                                                           
~                                                                                                           
:1,5 w ~/163.txt</pre></div></div>

<p>把第一行到第五行复制到 ~/163.txt 。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">  1 deb http://mirrors.163.com/ubuntu/ lucid main restricted universe multiverse
  2 deb http://mirrors.163.com/ubuntu/ lucid-security main restricted universe multiverse
  3 deb http://mirrors.163.com/ubuntu/ lucid-updates main restricted universe multiverse
  4 deb http://mirrors.163.com/ubuntu/ lucid-proposed main restricted universe multiverse
  5 deb http://mirrors.163.com/ubuntu/ lucid-backports main restricted universe multiverse
  6 # deb-src http://mirrors.163.com/ubuntu/ karmic main restricted universe multiverse
  7 # deb-src http://mirrors.163.com/ubuntu/ karmic-security main restricted universe multiverse
  8 # deb-src http://mirrors.163.com/ubuntu/ karmic-updates main restricted universe multiverse
  9 # deb-src http://mirrors.163.com/ubuntu/ karmic-proposed main restricted universe multiverse
 10 # deb-src http://mirrors.163.com/ubuntu/ karmic-backports main restricted universe multiverse
 11 
 12 # deb http://deb.torproject.org/torproject.org karmic main
 13 deb http://archive.ubuntu.com/ubuntu/ lucid multiverse universe 
 14 # deb http://mirror.netcologne.de/torproject.org lucid main # 已禁止升级到 lucid
 15 # deb http://ppa.launchpad.net/ibus-dev/ibus-1.2-karmic/ubuntu lucid main # 已禁止升级到 lucid
 16 # deb http://kubuntu-repo.googlecode.com/files /
 17 deb http://download.virtualbox.org/virtualbox/debian lucid contrib
 18 
 19 deb http://getswiftfox.com/builds/debian unstable non-free
~                                                                                                           
~                                                                                                           
~                                                                                                           
~                                                                                                           
~                                                                                                           
:12,17 w&gt;&gt; ~/163.txt</pre></div></div>

<p>把12到17行追加到 163.txt 。</p>
<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/vimperator-rang-ni-de-firefoxbian-cheng-vim.html" title="Vimperator-让你的Firefox变成Vim	">Vimperator-让你的Firefox变成Vim	</a></li><li><a href="http://www.linuxbyte.org/vim-wallpaper.html" title="vim 学习壁纸">vim 学习壁纸</a></li><li><a href="http://www.linuxbyte.org/ubuntu-8_04-software-optimization.html" title="Ubuntu 8.04 下软件设置和优化">Ubuntu 8.04 下软件设置和优化</a></li><li><a href="http://www.linuxbyte.org/my-ubuntu-8_0_4-tips.html" title="安装ubuntu 8.04 后的一些设置">安装ubuntu 8.04 后的一些设置</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/yi-tiao-hen-ku-de-vim-ji-qiao.html">一条很酷的 vim 技巧</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/vim" rel="tag">vim</a>, <a href="http://www.linuxbyte.org/tag/%e6%8a%80%e5%b7%a7" rel="tag">技巧</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/vim" title="vim" rel="tag">vim</a>, <a href="http://www.linuxbyte.org/tag/%e6%8a%80%e5%b7%a7" 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/yi-tiao-hen-ku-de-vim-ji-qiao.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>最受欢迎的10个 Linux 单行命令</title>
		<link>http://www.linuxbyte.org/zui-shou-huan-ying-de-10ge-linux-dan-xing-ming-ling.html</link>
		<comments>http://www.linuxbyte.org/zui-shou-huan-ying-de-10ge-linux-dan-xing-ming-ling.html#comments</comments>
		<pubDate>Wed, 16 Feb 2011 05:27:28 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[Bash]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=608</guid>
		<description><![CDATA[下面是来自 Commandlinefu 网站由用户投票决出的 10 个最酷的 Linux 单行命令。 sudo !! 以 root 帐户执行上一条命令。 python -m SimpleHTTPServer 利用 Python 搭建一个简单的 Web 服务器，可通过 http://$HOSTNAME:8... ]]></description>
			<content:encoded><![CDATA[<p>下面是来自 <a href="http://commandlinefu.com/">Commandlinefu</a> 网站由用户投票决出的 10 个最酷的 Linux 单行命令。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">sudo !!</pre></div></div>

<p>以 root 帐户执行上一条命令。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">python -m SimpleHTTPServer</pre></div></div>

<p>利用 Python 搭建一个简单的 Web 服务器，可通过 http://$HOSTNAME:8000 访问。<br />
<span id="more-608"></span></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">:w !sudo tee %</pre></div></div>

<p>在 Vim 中无需权限保存编辑的文件。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">cd -</pre></div></div>

<p>更改到上一次访问的目录。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">^foo^bar</pre></div></div>

<p>将上一条命令中的 foo 替换为 bar，并执行。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">cp filename{,.bak}</pre></div></div>

<p>快速备份或复制文件。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">mtr google.com</pre></div></div>

<p>traceroute + ping。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">!whatever:p</pre></div></div>

<p>搜索命令历史，但不执行。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">ssh-copy-id user@host</pre></div></div>

<p>将 ssh keys 复制到 user@host 以启用无密码 SSH 登录。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg</pre></div></div>

<p>把 Linux 桌面录制为视频。</p>
<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><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/bash-remove-operating-system.html" title="dell 的 Remove Operating System 代码">dell 的 Remove Operating System 代码</a></li><li><a href="http://www.linuxbyte.org/bash-tips.html" title="我常用的小shell">我常用的小shell</a></li><li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合">几个有用的bash 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>, 2011<br />
Source: <a href="http://www.linuxbyte.org/zui-shou-huan-ying-de-10ge-linux-dan-xing-ming-ling.html">最受欢迎的10个 Linux 单行命令</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/bash" rel="tag">Bash</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></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/zui-shou-huan-ying-de-10ge-linux-dan-xing-ming-ling.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>正则表达式的操作符说明</title>
		<link>http://www.linuxbyte.org/zheng-ze-biao-da-shi-de-cao-zuo-fu-shuo-ming.html</link>
		<comments>http://www.linuxbyte.org/zheng-ze-biao-da-shi-de-cao-zuo-fu-shuo-ming.html#comments</comments>
		<pubDate>Fri, 28 Jan 2011 05:46:52 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[正则表达式]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=591</guid>
		<description><![CDATA[. 匹配任何单个字符。 ? 之前的项目是可选的，匹配最多一次。 * 匹配出现零次或者多次的先前项目。 + 匹配一次或者多次先前项目。 &#123;N&#125; 精确匹配N次先前的项目。 &#123;N,&#125; 先前的项... ]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.         匹配任何单个字符。
?         之前的项目是可选的，匹配最多一次。
<span style="color: #000000; font-weight: bold;">*</span>         匹配出现零次或者多次的先前项目。
+         匹配一次或者多次先前项目。
<span style="color: #7a0874; font-weight: bold;">&#123;</span>N<span style="color: #7a0874; font-weight: bold;">&#125;</span>         精确匹配N次先前的项目。
<span style="color: #7a0874; font-weight: bold;">&#123;</span>N,<span style="color: #7a0874; font-weight: bold;">&#125;</span>         先前的项目匹配N或者更多次。
<span style="color: #7a0874; font-weight: bold;">&#123;</span>N,M<span style="color: #7a0874; font-weight: bold;">&#125;</span>         先前的项目匹配至少N次，但是不多于M次。
-         表示范围如果不是列表中最先或者最后或者一个范围的结束点。
^        匹配行开始的空字符串；也表示不在列表范围内的字符。
$         匹配行末的空字符串。
\b        匹配词两边的空字符串。
\B        匹配提供的空字符串 
\<span style="color: #000000; font-weight: bold;">&lt;</span> 匹配任何词开头的空字符串。
\<span style="color: #000000; font-weight: bold;">&gt;</span>       匹配任何词结尾的空字符串</pre></div></div>

<p><span id="more-591"></span></p>
<p>备忘一下。</p>
<h2  class="related_post_title">其他大家爱看的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/how-to-use-more-than-2t-block-device.html" title="如何使用大于2T的块设备">如何使用大于2T的块设备</a></li><li><a href="http://www.linuxbyte.org/amarok-20-beta-1-nerrivik.html" title="Amarok 2.0 Beta 1 &#8211; Nerrivik 发布">Amarok 2.0 Beta 1 &#8211; Nerrivik 发布</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/jie-jue-ubuntu-ssh-man-de-wen-ti.html" title="解决 ubuntu ssh 慢的问题">解决 ubuntu ssh 慢的问题</a></li><li><a href="http://www.linuxbyte.org/ubuntu-904-an-zhuang-pei-zhi-you-hua-quan-ji-lu.html" title="ubuntu 9.04 安装配置优化全记录">ubuntu 9.04 安装配置优化全记录</a></li><li><a href="http://www.linuxbyte.org/emacs-vi-joke.html" title="海盗用Emacs，忍者用Vi">海盗用Emacs，忍者用Vi</a></li><li><a href="http://www.linuxbyte.org/fu-wu-qi-zhong-swap-de-hua-fen.html" title="服务器中swap 的划分">服务器中swap 的划分</a></li><li><a href="http://www.linuxbyte.org/hiweed-linux-2_0-beta.html" title="Hiweed Linux 2.0beta 发布">Hiweed Linux 2.0beta 发布</a></li><li><a href="http://www.linuxbyte.org/ubuntu-9-10-xia-tian-jia-xp-yin-dao.html" title="Ubuntu 9.10 下添加XP 引导">Ubuntu 9.10 下添加XP 引导</a></li><li><a href="http://www.linuxbyte.org/gou-mai-vps-hou-de-yi-xie-cao-zuo.html" title="购买VPS 后的一些操作">购买VPS 后的一些操作</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/zheng-ze-biao-da-shi-de-cao-zuo-fu-shuo-ming.html">正则表达式的操作符说明</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f" rel="tag">正则表达式</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f" 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/zheng-ze-biao-da-shi-de-cao-zuo-fu-shuo-ming.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash Shell 快捷键</title>
		<link>http://www.linuxbyte.org/bash-shell-kuai-jie-jian.html</link>
		<comments>http://www.linuxbyte.org/bash-shell-kuai-jie-jian.html#comments</comments>
		<pubDate>Sun, 06 Jun 2010 06:13:46 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[快捷键]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=563</guid>
		<description><![CDATA[CTRL 键 Ctrl + a - Jump to the start of the line Ctrl + b - Move back a char Ctrl + c - Terminate the command //用的最多了吧? Ctrl + d - Delete from under the cursor Ctrl + e - Jump to the end of the line Ctrl + f - Move forward [...... ]]></description>
			<content:encoded><![CDATA[<h4><acronym title="Control">CTRL</acronym> 键</h4>
<pre>Ctrl + a - Jump to the start of the line
Ctrl + b - Move back a char
Ctrl + c - Terminate the command  //用的最多了吧?
Ctrl + d - Delete from under the cursor
Ctrl + e - Jump to the end of the line
Ctrl + f - Move forward a char
Ctrl + k - Delete to EOL
Ctrl + l - Clear the screen  //清屏，类似 clear 命令
Ctrl + r - Search the history backwards  //查找历史命令
Ctrl + R - Search the history backwards with multi occurrence
Ctrl + u - Delete backward from cursor // 密码输入错误的时候比较有用
Ctrl + xx - Move between EOL and current cursor position
Ctrl + x @ - Show possible hostname completions
Ctrl + z - Suspend/ Stop the command <span id="more-563"></span>
补充:
Ctrl + h - 删除当前字符
Ctrl + w - 删除最后输入的单词
</pre>
<h4>ALT  键</h4>
<p>平时很少用。有些和远程登陆工具冲突。</p>
<pre>Alt + &lt; - Move to the first line in the history
Alt + &gt; - Move to the last line in the history
Alt + ? - Show current completion list
Alt + * - Insert all possible completions
Alt + / - Attempt to complete filename
Alt + . - Yank last argument to previous command
Alt + b - Move backward
Alt + c - Capitalize the word
Alt + d - Delete word
Alt + f - Move forward
Alt + l - Make word lowercase
Alt + n - Search the history forwards non-incremental
Alt + p - Search the history backwards non-incremental
Alt + r - Recall command
Alt + t - Move words around
Alt + u - Make word uppercase
Alt + back-space - Delete backward from cursor
// SecureCRT 如果没有配置好，这个就很管用了。</pre>
<h4>其他特定的键绑定:</h4>
<p>输入 bind -P 可以查看所有的键盘绑定。这一系列我觉得更为实用。</p>
<pre>Here "2T" means Press TAB twice
$ 2T - All available commands(common) //命令行补全，我认为是 Bash 最好用的一点
$ (string)2T - All available commands starting with (string)
$ /2T - Entire directory structure including Hidden one
$ ./2T - Only Sub Dirs inside including Hidden one
$ *2T - Only Sub Dirs inside without Hidden one
$ ~2T - All Present Users on system from "/etc/passwd" //第一次见到，很好用
$ $2T - All Sys variables //写Shell脚本的时候很实用
$ @2T - Entries from "/etc/hosts"  //第一次见到
$ =2T - Output like ls or dir //好像还不如 ls 快捷
补充:
Esc + T - 交换光标前面的两个单词</pre>
<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/bash-remove-operating-system.html" title="dell 的 Remove Operating System 代码">dell 的 Remove Operating System 代码</a></li><li><a href="http://www.linuxbyte.org/bash-tips.html" title="我常用的小shell">我常用的小shell</a></li><li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合">几个有用的bash 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>, 2010<br />
Source: <a href="http://www.linuxbyte.org/bash-shell-kuai-jie-jian.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/%e5%bf%ab%e6%8d%b7%e9%94%ae" rel="tag">快捷键</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/%e5%bf%ab%e6%8d%b7%e9%94%ae" 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/bash-shell-kuai-jie-jian.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ffmpeg 批量转换脚本</title>
		<link>http://www.linuxbyte.org/ffmpeg-pi-liang-zhuan-huan-jiao-ben.html</link>
		<comments>http://www.linuxbyte.org/ffmpeg-pi-liang-zhuan-huan-jiao-ben.html#comments</comments>
		<pubDate>Fri, 02 Apr 2010 12:42:36 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[批量转换]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=526</guid>
		<description><![CDATA[从playingforchange.com 下载了好多FLV 文件放到手机上看，不过由于分辨率太高手机放起来一卡一卡的，所以要转换一下分辨率。 #/bin/sh for f in *.flv do ffmpeg -i $f -s 320x240 sm-$f done 检查当前目录下所有.... ]]></description>
			<content:encoded><![CDATA[<p>从playingforchange.com 下载了好多FLV 文件放到手机上看，不过由于分辨率太高手机放起来一卡一卡的，所以要转换一下分辨率。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#/bin/sh</span>
<span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*</span>.flv
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #c20cb9; font-weight: bold;">ffmpeg</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$f</span> <span style="color: #660033;">-s</span> 320x240 sm-<span style="color: #007800;">$f</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>检查当前目录下所有.flv 结尾的文件将其转换为 320&#215;240 分辨率，新文件名为老文件名前加sm- 前缀。<span id="more-526"></span></p>
<p>ffmpeg 是功能强大的多媒体工具组，具体用法参看下面的 ffmepeg 使用语法。</p>
<p><strong>ffmepeg 使用语法</strong>：<br />
ffmpeg [[options][`-i' input_file]]&#8230; {[options] output_file}&#8230;</p>
<p>如果没有输入文件，那么视音频捕捉就会起作用。</p>
<p>作为通用的规则，选项一般用于下一个特定的文件。如果你给 -b 64选项，改选会设置下一个视频速率。对于原始输入文件，格式选项可能是需要的。</p>
<p>缺省情况下，ffmpeg试图尽可能的无损转换，采用与输入同样的音频视频参数来输出。</p>
<p>3．选项</p>
<p>a) 通用选项</p>
<p>-L license</p>
<p>-h 帮助</p>
<p>-fromats 显示可用的格式，编解码的，协议的。。。</p>
<p>-f fmt 强迫采用格式fmt</p>
<p>-I filename 输入文件</p>
<p>-y 覆盖输出文件</p>
<p>-t duration 设置纪录时间 hh:mm:ss[.xxx]格式的记录时间也支持</p>
<p>-ss position 搜索到指定的时间 [-]hh:mm:ss[.xxx]的格式也支持</p>
<p>-title string 设置标题</p>
<p>-author string 设置作者</p>
<p>-copyright string 设置版权</p>
<p>-comment string 设置评论</p>
<p>-target type 设置目标文件类型(vcd,svcd,dvd) 所有的格式选项（比特率，编解码以及缓冲区大小）自动设置，只需要输入如下的就可以了：<br />
ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg</p>
<p>-hq 激活高质量设置</p>
<p>-itsoffset offset 设置以秒为基准的时间偏移，该选项影响所有后面的输入文件。该偏移被加到输入文件的时戳，定义一个正偏移意味着相应的流被延迟了 offset秒。 [-]hh:mm:ss[.xxx]的格式也支持</p>
<p>b) 视频选项</p>
<p>-b bitrate 设置比特率，缺省200kb/s</p>
<p>-r fps 设置帧频 缺省25</p>
<p>-s size 设置帧大小 格式为WXH 缺省160X128.下面的简写也可以直接使用：<br />
Sqcif 128X96 qcif 176X144 cif 252X288 4cif 704X576</p>
<p>-aspect aspect 设置横纵比 4:3 16:9 或 1.3333 1.7777</p>
<p>-croptop size 设置顶部切除带大小 像素单位</p>
<p>-cropbottom size -cropleft size -cropright size</p>
<p>-padtop size 设置顶部补齐的大小 像素单位</p>
<p>-padbottom size -padleft size -padright size -padcolor color 设置补齐条颜色(hex,6个16进制的数，红:绿:兰排列，比如 000000代表黑色)</p>
<p>-vn 不做视频记录</p>
<p>-bt tolerance 设置视频码率容忍度kbit/s</p>
<p>-maxrate bitrate设置最大视频码率容忍度</p>
<p>-minrate bitreate 设置最小视频码率容忍度</p>
<p>-bufsize size 设置码率控制缓冲区大小</p>
<p>-vcodec codec 强制使用codec编解码方式。如果用copy表示原始编解码数据必须被拷贝。</p>
<p>-sameq 使用同样视频质量作为源（VBR）</p>
<p>-pass n 选择处理遍数（1或者2）。两遍编码非常有用。第一遍生成统计信息，第二遍生成精确的请求的码率</p>
<p>-passlogfile file 选择两遍的纪录文件名为file</p>
<p>c)高级视频选项</p>
<p>-g gop_size 设置图像组大小</p>
<p>-intra 仅适用帧内编码</p>
<p>-qscale q 使用固定的视频量化标度(VBR)</p>
<p>-qmin q 最小视频量化标度(VBR)</p>
<p>-qmax q 最大视频量化标度(VBR)</p>
<p>-qdiff q 量化标度间最大偏差 (VBR)</p>
<p>-qblur blur 视频量化标度柔化(VBR)</p>
<p>-qcomp compression 视频量化标度压缩(VBR)</p>
<p>-rc_init_cplx complexity 一遍编码的初始复杂度</p>
<p>-b_qfactor factor 在p和b帧间的qp因子</p>
<p>-i_qfactor factor 在p和i帧间的qp因子</p>
<p>-b_qoffset offset 在p和b帧间的qp偏差</p>
<p>-i_qoffset offset 在p和i帧间的qp偏差</p>
<p>-rc_eq equation 设置码率控制方程 默认tex^qComp</p>
<p>-rc_override override 特定间隔下的速率控制重载</p>
<p>-me method 设置运动估计的方法 可用方法有 zero phods log x1 epzs(缺省) full</p>
<p>-dct_algo algo 设置dct的算法 可用的有 0 FF_DCT_AUTO 缺省的DCT 1 FF_DCT_FASTINT 2 FF_DCT_INT 3 FF_DCT_MMX 4 FF_DCT_MLIB 5 FF_DCT_ALTIVEC</p>
<p>-idct_algo algo 设置idct算法。可用的有 0 FF_IDCT_AUTO 缺省的IDCT 1 FF_IDCT_INT 2 FF_IDCT_SIMPLE 3 FF_IDCT_SIMPLEMMX 4 FF_IDCT_LIBMPEG2MMX 5 FF_IDCT_PS2 6 FF_IDCT_MLIB 7 FF_IDCT_ARM 8 FF_IDCT_ALTIVEC 9 FF_IDCT_SH4 10 FF_IDCT_SIMPLEARM</p>
<p>-er n 设置错误残留为n 1 FF_ER_CAREFULL 缺省 2 FF_ER_COMPLIANT 3 FF_ER_AGGRESSIVE 4 FF_ER_VERY_AGGRESSIVE</p>
<p>-ec bit_mask 设置错误掩蔽为bit_mask,该值为如下值的位掩码 1 FF_EC_GUESS_MVS (default=enabled) 2 FF_EC_DEBLOCK (default=enabled)</p>
<p>-bf frames 使用frames B 帧，支持mpeg1,mpeg2,mpeg4</p>
<p>-mbd mode 宏块决策 0 FF_MB_DECISION_SIMPLE 使用mb_cmp 1 FF_MB_DECISION_BITS 2 FF_MB_DECISION_RD</p>
<p>-4mv 使用4个运动矢量 仅用于mpeg4</p>
<p>-part 使用数据划分 仅用于mpeg4</p>
<p>-bug param 绕过没有被自动监测到编码器的问题</p>
<p>-strict strictness 跟标准的严格性</p>
<p>-aic 使能高级帧内编码 h263+</p>
<p>-umv 使能无限运动矢量 h263+</p>
<p>-deinterlace 不采用交织方法</p>
<p>-interlace 强迫交织法编码仅对mpeg2和mpeg4有效。当你的输入是交织的并且你想要保持交织以最小图像损失的时候采用该选项。可选的方法是不交织，但是损失更大</p>
<p>-psnr 计算压缩帧的psnr</p>
<p>-vstats 输出视频编码统计到vstats_hhmmss.log</p>
<p>-vhook module 插入视频处理模块 module 包括了模块名和参数，用空格分开</p>
<p>D)音频选项</p>
<p>-ab bitrate 设置音频码率</p>
<p>-ar freq 设置音频采样率</p>
<p>-ac channels 设置通道 缺省为1</p>
<p>-an 不使能音频纪录</p>
<p>-acodec codec 使用codec编解码</p>
<p>E)音频/视频捕获选项</p>
<p>-vd device 设置视频捕获设备。比如/dev/video0</p>
<p>-vc channel 设置视频捕获通道 DV1394专用</p>
<p>-tvstd standard 设置电视标准 NTSC PAL(SECAM)</p>
<p>-dv1394 设置DV1394捕获</p>
<p>-av device 设置音频设备 比如/dev/dsp</p>
<p>F)高级选项</p>
<p>-map file:stream 设置输入流映射</p>
<p>-debug 打印特定调试信息</p>
<p>-benchmark 为基准测试加入时间</p>
<p>-hex 倾倒每一个输入包</p>
<p>-bitexact 仅使用位精确算法 用于编解码测试</p>
<p>-ps size 设置包大小，以bits为单位</p>
<p>-re 以本地帧频读数据，主要用于模拟捕获设备</p>
<p>-loop 循环输入流。只工作于图像流，用于ffserver测试</p>
<h2  class="related_post_title">其他大家爱看的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/apache-url-rewrite.html" title="Apache Url Rewrite(mod_rewrite)">Apache Url Rewrite(mod_rewrite)</a></li><li><a href="http://www.linuxbyte.org/nginx-xian-zhi-bing-fa-lian-jie-shu.html" title="Nginx 限制并发连接数">Nginx 限制并发连接数</a></li><li><a href="http://www.linuxbyte.org/svn-howto.html" title="SVN 使用入门 ">SVN 使用入门 </a></li><li><a href="http://www.linuxbyte.org/sheng-ji-wordpress.html" title="升级WordPress">升级WordPress</a></li><li><a href="http://www.linuxbyte.org/ubuntu-kao-lv-yong-lightdm-qu-dai-gdm.html" title="Ubuntu 考虑用 LightDM 取代 GDM ">Ubuntu 考虑用 LightDM 取代 GDM </a></li><li><a href="http://www.linuxbyte.org/squid-havp-clamav.html" title="squid+havp+clamav搭建防毒代理">squid+havp+clamav搭建防毒代理</a></li><li><a href="http://www.linuxbyte.org/kde-4-02.html" title="KDE 4.0.2 发布">KDE 4.0.2 发布</a></li><li><a href="http://www.linuxbyte.org/sed-tips.html" title="sed 总结">sed 总结</a></li><li><a href="http://www.linuxbyte.org/pclinuxos-2009-beta-3.html" title="PCLinuxOS 2009 Beta 3 发布">PCLinuxOS 2009 Beta 3 发布</a></li><li><a href="http://www.linuxbyte.org/magiclinux-2-6-x86_64-de-di-yi-ge-yuan-xing-iso.html" title="Magiclinux 2.6(x86_64) 的第一个原型iso">Magiclinux 2.6(x86_64) 的第一个原型iso</a></li></ul><hr />
<p><small>© xiao H for <a href="http://www.linuxbyte.org">LinuxByte</a>, 2010<br />
Source: <a href="http://www.linuxbyte.org/ffmpeg-pi-liang-zhuan-huan-jiao-ben.html">ffmpeg 批量转换脚本</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/ffmpeg" rel="tag">ffmpeg</a>, <a href="http://www.linuxbyte.org/tag/%e6%89%b9%e9%87%8f%e8%bd%ac%e6%8d%a2" rel="tag">批量转换</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/ffmpeg" title="ffmpeg" rel="tag">ffmpeg</a>, <a href="http://www.linuxbyte.org/tag/%e6%89%b9%e9%87%8f%e8%bd%ac%e6%8d%a2" 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/ffmpeg-pi-liang-zhuan-huan-jiao-ben.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>我的 Conky 配置文件</title>
		<link>http://www.linuxbyte.org/wo-de-conky-pei-zhi-wen-jian.html</link>
		<comments>http://www.linuxbyte.org/wo-de-conky-pei-zhi-wen-jian.html#comments</comments>
		<pubDate>Mon, 11 May 2009 21:02:58 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[日常桌面]]></category>
		<category><![CDATA[Conky]]></category>
		<category><![CDATA[系统监控]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=423</guid>
		<description><![CDATA[虽然监控系统状况的软件很多，但现在最受欢迎的该是Conky，Conky 小巧，漂亮，且配置方便简单。 CPU 温度读取部分用了sensors，硬盘温度读取用hddtemp。 background yes override_utf8_locale yes font Sans:size=... ]]></description>
			<content:encoded><![CDATA[<p>虽然监控系统状况的软件很多，但现在最受欢迎的该是Conky，Conky 小巧，漂亮，且配置方便简单。<br />
CPU 温度读取部分用了sensors，硬盘温度读取用hddtemp。<br />
<a rel="lightbox" href="http://www.linuxbyte.org/uploads/2009/05/screenshot.png" target="_blank"><img class="alignnone size-medium wp-image-424" title="conky" src="http://www.linuxbyte.org/uploads/2009/05/screenshot-320x200.png" alt="conky" width="320" height="200" /></a><br />
<span id="more-423"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">background <span style="color: #c20cb9; font-weight: bold;">yes</span>
override_utf8_locale <span style="color: #c20cb9; font-weight: bold;">yes</span>
font Sans:<span style="color: #007800;">size</span>=<span style="color: #000000;">9</span>
xftfont Sans:<span style="color: #007800;">size</span>=<span style="color: #000000;">9</span>
use_xft <span style="color: #c20cb9; font-weight: bold;">yes</span>
xftalpha <span style="color: #000000;">0.1</span>
&nbsp;
update_interval <span style="color: #000000;">1.0</span>
total_run_times <span style="color: #000000;">0</span>
own_window <span style="color: #c20cb9; font-weight: bold;">yes</span>
own_window_type override
<span style="color: #666666; font-style: italic;">#own_window_type override</span>
own_window_transparent <span style="color: #c20cb9; font-weight: bold;">yes</span>
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer <span style="color: #c20cb9; font-weight: bold;">yes</span>
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
minimum_size <span style="color: #000000;">170</span> <span style="color: #000000;">5</span>
maximum_width <span style="color: #000000;">170</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#alignment top_left</span>
alignment top_right
<span style="color: #666666; font-style: italic;">#alignment bottom_left</span>
<span style="color: #666666; font-style: italic;">#alignment bottom_right</span>
<span style="color: #666666; font-style: italic;">#alignment none</span>
gap_x <span style="color: #000000;">10</span>
gap_y <span style="color: #000000;">50</span>
no_buffers <span style="color: #c20cb9; font-weight: bold;">yes</span>
cpu_avg_samples <span style="color: #000000;">2</span>
override_utf8_locale <span style="color: #c20cb9; font-weight: bold;">yes</span>
uppercase no <span style="color: #666666; font-style: italic;"># set to yes if you want all text to be in uppercase</span>
use_spacer none
out_to_console no
&nbsp;
default_color white
default_shade_color black
default_outline_color white
&nbsp;
TEXT
<span style="color: #800000;">${color }</span><span style="color: #800000;">${font Agency FB size=20}</span>Time: <span style="color: #800000;">${time %H:%M}</span>
<span style="color: #800000;">${color }</span><span style="color: #800000;">${font }</span>Day: <span style="color: #800000;">${time %Y-%m-%d}</span>
<span style="color: #800000;">${color }</span>UpTime:<span style="color: #007800;">$alignr</span><span style="color: #800000;">${color }</span><span style="color: #007800;">$uptime</span>
<span style="color: #800000;">${color }</span>Kernel:<span style="color: #007800;">$alignr</span><span style="color: #800000;">${color }</span><span style="color: #007800;">$kernel</span>
&nbsp;
<span style="color: #800000;">${color  #dcff82}</span>Intel E2180:
<span style="color: #800000;">${color white}</span><span style="color: #007800;">$stippled_hr</span>
<span style="color: #800000;">${color white}</span>CPU0 Temp:<span style="color: #007800;">$alignr</span><span style="color: #800000;">${color }</span> <span style="color: #800000;">${execi 20 sensors | grep -A 0 'Core 0' | cut -c15-16}</span>°C
<span style="color: #800000;">${color white}</span>CPU1 Temp:<span style="color: #007800;">$alignr</span><span style="color: #800000;">${color }</span> <span style="color: #800000;">${execi 20 sensors | grep -A 0 'Core 1' | cut -c15-16}</span>°C
<span style="color: #800000;">${color white}</span>CPU us:<span style="color: #007800;">$alignr</span><span style="color: #800000;">${color }</span> <span style="color: #007800;">$cpu</span><span style="color: #000000; font-weight: bold;">%</span> 
&nbsp;
<span style="color: #800000;">${color  #dcff82}</span>TOP Processes:
<span style="color: #800000;">${color }</span><span style="color: #007800;">$stippled_hr</span>
<span style="color: #800000;">${color }</span>Processes:<span style="color: #007800;">$alignr</span><span style="color: #800000;">${color }</span><span style="color: #007800;">$processes</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$running_processes</span> running<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #800000;">${color }</span>Highest CPU:<span style="color: #007800;">$alignr</span>  PID   CPU<span style="color: #000000; font-weight: bold;">%</span>
<span style="color: #800000;">${color #ddaa00}</span><span style="color: #800000;">${top name 1}</span><span style="color: #007800;">$alignr</span><span style="color: #800000;">${top pid 1}</span>  <span style="color: #800000;">${top cpu 1}</span>
<span style="color: #800000;">${color lightgrey}</span><span style="color: #800000;">${top name 2}</span><span style="color: #007800;">$alignr</span><span style="color: #800000;">${top pid 2}</span>  <span style="color: #800000;">${top cpu 2}</span>
<span style="color: #800000;">${color lightgrey}</span><span style="color: #800000;">${top name 3}</span><span style="color: #007800;">$alignr</span><span style="color: #800000;">${top pid 3}</span>  <span style="color: #800000;">${top cpu 3}</span>
&nbsp;
<span style="color: #800000;">${color }</span>Highest MEM:<span style="color: #007800;">$alignr</span>  PID   MEM<span style="color: #000000; font-weight: bold;">%</span>
<span style="color: #800000;">${color #ddaa00}</span><span style="color: #800000;">${top_mem name 1}</span><span style="color: #007800;">$alignr</span><span style="color: #800000;">${top_mem pid 1}</span>  <span style="color: #800000;">${top_mem mem 1}</span>
<span style="color: #800000;">${color lightgrey}</span><span style="color: #800000;">${top_mem name 2}</span><span style="color: #007800;">$alignr</span><span style="color: #800000;">${top_mem pid 2}</span>  <span style="color: #800000;">${top_mem mem 2}</span>
<span style="color: #800000;">${color lightgrey}</span><span style="color: #800000;">${top_mem name 3}</span><span style="color: #007800;">$alignr</span><span style="color: #800000;">${top_mem pid 3}</span>  <span style="color: #800000;">${top_mem mem 3}</span>
&nbsp;
<span style="color: #800000;">${color }</span>MEM:<span style="color: #800000;">${color}</span> <span style="color: #007800;">$memperc</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #007800;">$alignr</span><span style="color: #007800;">$mem</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$memmax</span>
<span style="color: #800000;">${membar 3,160}</span>
<span style="color: #800000;">${color white}</span>SWAP:<span style="color: #800000;">${color}</span> <span style="color: #007800;">$swapperc</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #007800;">$alignr</span><span style="color: #007800;">$swap</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$swapmax</span>
<span style="color: #800000;">${swapbar 3,160}</span>
&nbsp;
<span style="color: #800000;">${color  #dcff82}</span>SAMSUNG SP0802N:
<span style="color: #800000;">${color }</span><span style="color: #007800;">$stippled_hr</span>
<span style="color: #800000;">${color }</span>Hard Drive Temp: <span style="color: #007800;">$alignr</span><span style="color: #800000;">${execi 300 nc localhost 7634 | cut -c27-28;}</span> °C
<span style="color: #800000;">${color }</span>ROOT:<span style="color: #007800;">$alignr</span><span style="color: #800000;">${color}</span><span style="color: #800000;">${fs_free /}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${fs_size /}</span>
<span style="color: #800000;">${fs_bar 3,160 /}</span>
<span style="color: #800000;">${color }</span>HOME:<span style="color: #007800;">$alignr</span><span style="color: #800000;">${color}</span><span style="color: #800000;">${fs_free /home}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${fs_size /home}</span>
<span style="color: #800000;">${fs_bar 3,160 /home}</span>
<span style="color: #800000;">${color }</span>Disk Read:<span style="color: #800000;">${alignr}</span><span style="color: #800000;">${color}</span><span style="color: #007800;">$diskio_read</span>
<span style="color: #800000;">${color}</span><span style="color: #800000;">${diskiograph_read /dev/sda 10,160 000000 ffffff}</span>
<span style="color: #800000;">${color }</span>Disk Write:<span style="color: #800000;">${alignr}</span><span style="color: #800000;">${color}</span><span style="color: #007800;">$diskio_write</span>
<span style="color: #800000;">${color}</span><span style="color: #800000;">${diskiograph_write /dev/sda 10,160 000000 ffffff}</span></pre></div></div>

<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/super-mrtg_cfg.html" title="一份非常好的mrtg.cfg">一份非常好的mrtg.cfg</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/wo-de-conky-pei-zhi-wen-jian.html">我的 Conky 配置文件</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/conky" rel="tag">Conky</a>, <a href="http://www.linuxbyte.org/tag/%e7%b3%bb%e7%bb%9f%e7%9b%91%e6%8e%a7" rel="tag">系统监控</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/conky" title="Conky" rel="tag">Conky</a>, <a href="http://www.linuxbyte.org/tag/%e7%b3%bb%e7%bb%9f%e7%9b%91%e6%8e%a7" 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/wo-de-conky-pei-zhi-wen-jian.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Iptables＋tc 网吧每IP 限速脚本</title>
		<link>http://www.linuxbyte.org/iptables%ef%bc%8dtc-wang-ba-mei-ip-xian-su-jiao-ben.html</link>
		<comments>http://www.linuxbyte.org/iptables%ef%bc%8dtc-wang-ba-mei-ip-xian-su-jiao-ben.html#comments</comments>
		<pubDate>Sat, 09 May 2009 12:32:43 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[htb]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[tc]]></category>
		<category><![CDATA[限速]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=421</guid>
		<description><![CDATA[网吧以前是没做限速的，但最近遇到几个狂爱看A片的哥们，用不知什么东西下载的，好几次把带宽占个精光，所以不得不做了限速。 总体思想很简单，为每个IP 打标，然后归入各自的tc 限速规... ]]></description>
			<content:encoded><![CDATA[<p>网吧以前是没做限速的，但最近遇到几个狂爱看A片的哥们，用不知什么东西下载的，好几次把带宽占个精光，所以不得不做了限速。<br />
总体思想很简单，为每个IP 打标，然后归入各自的tc 限速规则中去。<br />
<span id="more-421"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># xiaoh www.linuxbyte.org</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#  定义进出设备(eth0 内网，eth1外网)</span>
<span style="color: #007800;">IDEV</span>=<span style="color: #ff0000;">&quot;eth0&quot;</span>
<span style="color: #007800;">ODEV</span>=<span style="color: #ff0000;">&quot;eth1&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#  定义总的上下带宽</span>
<span style="color: #007800;">UP</span>=<span style="color: #ff0000;">&quot;50mbit&quot;</span>
<span style="color: #007800;">DOWN</span>=<span style="color: #ff0000;">&quot;50mbit&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#  定义每个受限制的IP上下带宽</span>
＃rate 起始带宽
<span style="color: #007800;">UPLOAD</span>=<span style="color: #ff0000;">&quot;4mbit&quot;</span>
<span style="color: #007800;">DOWNLOAD</span>=<span style="color: #ff0000;">&quot;5mbit&quot;</span>
＃ceil 最大带宽
<span style="color: #007800;">MUPLOAD</span>=<span style="color: #ff0000;">&quot;5mbit&quot;</span>
<span style="color: #007800;">MDOWNLOAD</span>=<span style="color: #ff0000;">&quot;10mbit&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#内网IP段</span>
<span style="color: #007800;">INET</span>=<span style="color: #ff0000;">&quot;192.168.0.&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># 受限IP范围，IPS 起始IP，IPE 结束IP。</span>
<span style="color: #007800;">IPS</span>=<span style="color: #ff0000;">&quot;1&quot;</span> 
<span style="color: #007800;">IPE</span>=<span style="color: #ff0000;">&quot;114&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># 清除网卡原有队列规则</span>
tc qdisc del dev <span style="color: #007800;">$ODEV</span> root <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
tc qdisc del dev <span style="color: #007800;">$IDEV</span> root <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
&nbsp;
<span style="color: #666666; font-style: italic;"># 定义最顶层(根)队列规则，并指定 default 类别编号</span>
tc qdisc add dev <span style="color: #007800;">$ODEV</span> root handle <span style="color: #000000;">10</span>: htb default <span style="color: #000000;">256</span>
tc qdisc add dev <span style="color: #007800;">$IDEV</span> root handle <span style="color: #000000;">10</span>: htb default <span style="color: #000000;">256</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># 定义第一层的 10:1 类别 (上行/下行 总带宽)</span>
tc class add dev <span style="color: #007800;">$ODEV</span> parent <span style="color: #000000;">10</span>: classid <span style="color: #000000;">10</span>:<span style="color: #000000;">1</span> htb rate <span style="color: #007800;">$UP</span> ceil <span style="color: #007800;">$UP</span>
tc class add dev <span style="color: #007800;">$IDEV</span> parent <span style="color: #000000;">10</span>: classid <span style="color: #000000;">10</span>:<span style="color: #000000;">1</span> htb rate <span style="color: #007800;">$DOWN</span> ceil <span style="color: #007800;">$DOWN</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#开始iptables 打标和设置具体规则</span>
<span style="color: #007800;">i</span>=<span style="color: #007800;">$IPS</span>;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$i</span> <span style="color: #660033;">-le</span> <span style="color: #007800;">$IPE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
tc class add dev <span style="color: #007800;">$ODEV</span> parent <span style="color: #000000;">10</span>:<span style="color: #000000;">1</span> classid <span style="color: #000000;">10</span>:<span style="color: #000000;">2</span><span style="color: #007800;">$i</span> htb rate <span style="color: #007800;">$UPLOAD</span> ceil <span style="color: #007800;">$MUPLOAD</span> prio <span style="color: #000000;">1</span>
tc qdisc add dev <span style="color: #007800;">$ODEV</span> parent <span style="color: #000000;">10</span>:<span style="color: #000000;">2</span><span style="color: #007800;">$i</span> handle <span style="color: #000000;">100</span><span style="color: #007800;">$i</span>: pfifo
tc filter add dev <span style="color: #007800;">$ODEV</span> parent <span style="color: #000000;">10</span>: protocol ip prio <span style="color: #000000;">100</span> handle <span style="color: #000000;">2</span><span style="color: #007800;">$i</span> fw classid <span style="color: #000000;">10</span>:<span style="color: #000000;">2</span><span style="color: #007800;">$i</span>
tc class add dev <span style="color: #007800;">$IDEV</span> parent <span style="color: #000000;">10</span>:<span style="color: #000000;">1</span> classid <span style="color: #000000;">10</span>:<span style="color: #000000;">2</span><span style="color: #007800;">$i</span> htb rate <span style="color: #007800;">$DOWNLOAD</span> ceil <span style="color: #007800;">$MDOWNLOAD</span> prio <span style="color: #000000;">1</span>
tc qdisc add dev <span style="color: #007800;">$IDEV</span> parent <span style="color: #000000;">10</span>:<span style="color: #000000;">2</span><span style="color: #007800;">$i</span> handle <span style="color: #000000;">100</span><span style="color: #007800;">$i</span>: pfifo
tc filter add dev <span style="color: #007800;">$IDEV</span> parent <span style="color: #000000;">10</span>: protocol ip prio <span style="color: #000000;">100</span> handle <span style="color: #000000;">2</span><span style="color: #007800;">$i</span> fw classid <span style="color: #000000;">10</span>:<span style="color: #000000;">2</span><span style="color: #007800;">$i</span>
iptables <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-s</span> <span style="color: #007800;">$INET</span><span style="color: #007800;">$i</span> <span style="color: #660033;">-j</span> MARK <span style="color: #660033;">--set-mark</span> <span style="color: #000000;">2</span><span style="color: #007800;">$i</span>
iptables <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-s</span> <span style="color: #007800;">$INET</span><span style="color: #007800;">$i</span> <span style="color: #660033;">-j</span> RETURN
iptables <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-d</span> <span style="color: #007800;">$INET</span><span style="color: #007800;">$i</span> <span style="color: #660033;">-j</span> MARK <span style="color: #660033;">--set-mark</span> <span style="color: #000000;">2</span><span style="color: #007800;">$i</span>
iptables <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-d</span> <span style="color: #007800;">$INET</span><span style="color: #007800;">$i</span> <span style="color: #660033;">-j</span> RETURN
<span style="color: #007800;">i</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$i</span> + <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<h2  class="related_post_title">与本文关系暧昧的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/wang-ba-linux-wang-guan-she-zhi-ji-lu-bu-chong.html" title="网吧Linux 网关设置记录补充">网吧Linux 网关设置记录补充</a></li><li><a href="http://www.linuxbyte.org/wang-ba-mei-ip-xian-su-bu-chong-squid-xian-su.html" title="网吧每IP 限速补充（squid 限速）">网吧每IP 限速补充（squid 限速）</a></li><li><a href="http://www.linuxbyte.org/yong-iptables-er-fei-tc-xian-zhi-liu-liang.html" title="用Iptables 而非tc 限制流量">用Iptables 而非tc 限制流量</a></li><li><a href="http://www.linuxbyte.org/linux-iptables-nat-squid-pdnsd.html" title="网吧Linux 网关设置记录">网吧Linux 网关设置记录</a></li><li><a href="http://www.linuxbyte.org/iptables-command-example.html" title="iptables 基本命令使用举例">iptables 基本命令使用举例</a></li><li><a href="http://www.linuxbyte.org/linux-syn-attack-defense.html" title="LINUX下的SYN攻击防御">LINUX下的SYN攻击防御</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/iptables%ef%bc%8dtc-wang-ba-mei-ip-xian-su-jiao-ben.html">Iptables＋tc 网吧每IP 限速脚本</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/htb" rel="tag">htb</a>, <a href="http://www.linuxbyte.org/tag/iptables" rel="tag">iptables</a>, <a href="http://www.linuxbyte.org/tag/tc" rel="tag">tc</a>, <a href="http://www.linuxbyte.org/tag/%e9%99%90%e9%80%9f" rel="tag">限速</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/htb" title="htb" rel="tag">htb</a>, <a href="http://www.linuxbyte.org/tag/iptables" title="iptables" rel="tag">iptables</a>, <a href="http://www.linuxbyte.org/tag/tc" title="tc" rel="tag">tc</a>, <a href="http://www.linuxbyte.org/tag/%e9%99%90%e9%80%9f" 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/iptables%ef%bc%8dtc-wang-ba-mei-ip-xian-su-jiao-ben.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>dell 的 Remove Operating System 代码</title>
		<link>http://www.linuxbyte.org/bash-remove-operating-system.html</link>
		<comments>http://www.linuxbyte.org/bash-remove-operating-system.html#comments</comments>
		<pubDate>Thu, 01 Jan 2009 10:21:40 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[dell]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=347</guid>
		<description><![CDATA[在公社看到 WeiMingzhi 贴的Dell 预装SLED10机子上提供的删除OS 脚本，觉得蛮好特留一个备份。 title Remove Operating System root &#40;hd0,2&#41; kernel /vmlinuz root=/dev/disk/by-label/root ro init=/sbin/remove-os.sh resume=/dev... ]]></description>
			<content:encoded><![CDATA[<p>在公社看到 WeiMingzhi 贴的Dell 预装SLED10机子上提供的删除OS 脚本，觉得蛮好特留一个备份。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">title Remove Operating System
    root <span style="color: #7a0874; font-weight: bold;">&#40;</span>hd0,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    kernel <span style="color: #000000; font-weight: bold;">/</span>vmlinuz <span style="color: #007800;">root</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>disk<span style="color: #000000; font-weight: bold;">/</span>by-label<span style="color: #000000; font-weight: bold;">/</span>root ro <span style="color: #007800;">init</span>=<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>remove-os.sh <span style="color: #007800;">resume</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda5 <span style="color: #007800;">splash</span>=silent showopts
    initrd <span style="color: #000000; font-weight: bold;">/</span>initrd</pre></div></div>

<p><span id="more-347"></span><br />
<strong>remove-os.sh </strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dell:<span style="color: #000000; font-weight: bold;">/</span>sbin <span style="color: #666666; font-style: italic;"># cat remove-os.sh</span>
<span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
abort<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: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OS removal ABORTED. System will reboot in 30 seconds.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;NO CHANGES HAVE BEEN MADE TO THE HARD DISKS.&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">30</span>
    <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>reboot
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Initializing keyboard...&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PREVLEVEL</span>=N
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">RUNLEVEL</span>=S
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>earlykbd start
&nbsp;
<span style="color: #007800;">CORRECT_ANSWER</span>=<span style="color: #ff0000;">&quot;REMOVE OPERATING SYSTEM&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'WARNING!    WARNING!   WARNING!'</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;This operation will remove the Operating System (OS) from your computer&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;All personal files on this system will be lost.&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;The information will not be recoverable.&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;ALL DATA ON YOUR HARD DRIVES WILL BE PERMANENTLY AND IRRETRIEVABLY DESTROYED IF YOU CONTINUE.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;To proceed with the Operating System removal, please type: <span style="color: #007800;">$CORRECT_ANSWER</span>&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span>      <span style="color: #ff0000;">&quot;Type any other text to abort: &quot;</span> answer
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$answer</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CORRECT_ANSWER</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    abort
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Hard Drive erasure begins in 10 seconds. Power off system to abort (last chance)...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">10</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Remove all parts save N1</span>
<span style="color: #007800;">DRIVE</span>=<span style="color: #000000; font-weight: bold;">`</span>fdisk <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">&quot;Disk&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span><span style="color: #ff0000;">':'</span> -f1<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DRIVE = &quot;</span><span style="color: #007800;">$DRIVE</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$DRIVE</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;">break</span>; <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;0,0,0,-&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> sfdisk <span style="color: #660033;">-uS</span> <span style="color: #660033;">-N2</span> <span style="color: #660033;">--force</span> <span style="color: #660033;">--no-reread</span> <span style="color: #007800;">$DRIVE</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;0,0,0,-&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> sfdisk <span style="color: #660033;">-uS</span> <span style="color: #660033;">-N3</span> <span style="color: #660033;">--force</span> <span style="color: #660033;">--no-reread</span> <span style="color: #007800;">$DRIVE</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;0,0,0,-&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> sfdisk <span style="color: #660033;">-uS</span> <span style="color: #660033;">-N4</span> <span style="color: #660033;">--force</span> <span style="color: #660033;">--no-reread</span> <span style="color: #007800;">$DRIVE</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Operating System has been removed. The system is now unbootable. You must reinstall an operating system for the computer.&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">600000</span></pre></div></div>

<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/bash-shell-kuai-jie-jian.html" title="Bash Shell 快捷键">Bash Shell 快捷键</a></li><li><a href="http://www.linuxbyte.org/bash-tips.html" title="我常用的小shell">我常用的小shell</a></li><li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合">几个有用的bash 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>, 2009<br />
Source: <a href="http://www.linuxbyte.org/bash-remove-operating-system.html">dell 的 Remove Operating System 代码</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/bash" rel="tag">Bash</a>, <a href="http://www.linuxbyte.org/tag/dell" rel="tag">dell</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/dell" title="dell" rel="tag">dell</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/bash-remove-operating-system.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>date 命令使用小技巧</title>
		<link>http://www.linuxbyte.org/command-date-tips.html</link>
		<comments>http://www.linuxbyte.org/command-date-tips.html#comments</comments>
		<pubDate>Mon, 24 Nov 2008 11:45:19 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[date]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=330</guid>
		<description><![CDATA[前两天在做为squid 做日志截断时零时学习了一下 date 命令的使用，这里做个小纪录 //昨日时间 date +%Y%m%d -d “-1 day” //明日时间 date +%Y%m%d -d “+1 day” //一月之间 date +%Y%m%d -d “-30 day” Linux&#8211;... ]]></description>
			<content:encoded><![CDATA[<p>前两天在做为squid 做日志截断时零时学习了一下 date 命令的使用，这里做个小纪录</p>
<p>//昨日时间<br />
date +%Y%m%d -d “-1 day”<br />
//明日时间<br />
date +%Y%m%d -d “+1 day”<br />
//一月之间<br />
date +%Y%m%d -d “-30 day”</p>
<p><span id="more-330"></span></p>
<p>Linux&#8211;date命令用法：</p>
<p>date命令<br />
date命令的功能是显示和设置系统日期和时间。<br />
该命令的一般格式为： date [选项] 显示时间格式（以+开头，后面接格式）<br />
date 设置时间格式<br />
命令中各选项的含义分别为：<br />
-d datestr, &#8211;date datestr 显示由datestr描述的日期<br />
-s datestr, &#8211;set datestr 设置datestr 描述的日期<br />
-u, &#8211;universal 显示或设置通用时间<br />
时间域<br />
% H 小时（00..23）<br />
% I 小时（01..12）<br />
% k 小时（0..23）<br />
% l 小时（1..12）<br />
% M 分（00..59）<br />
% p 显示出AM或PM<br />
% r 时间（hh：mm：ss AM或PM），12小时<br />
% s 从1970年1月1日00：00：00到目前经历的秒数<br />
% S 秒（00..59）<br />
<span style="color: #00f000;"><strong> % T 时间（24小时制）（hh:mm:ss</strong></span><span style="color: #00f000;"><strong>）<br />
</strong></span> % X 显示时间的格式（％H:％M:％S）<br />
% Z 时区 日期域<br />
% a 星期几的简称（ Sun..Sat）<br />
% A 星期几的全称（ Sunday..Saturday）<br />
% b 月的简称（Jan..Dec）<br />
% B 月的全称（January..December）<br />
% c 日期和时间（ Mon Nov 8 14：12：46 CST 1999）<br />
<strong><span style="color: #00f000;">% d 一个月的第几天（01..31）</span></strong><br />
% D 日期（mm／dd／yy）<br />
% h 和%b选项相同<br />
% j 一年的第几天（001..366）<br />
<strong><span style="color: #00f000;">% m 月（01..12）</span></strong><br />
% w 一个星期的第几天（0代表星期天）<br />
% W 一年的第几个星期（00..53，星期一为第一天）<br />
% x 显示日期的格式（mm/dd/yy）<br />
% y 年的最后两个数字（ 1999则是99）<br />
<strong><span style="color: #00f000;">% Y 年（例如：1970，1996等）</span></strong><br />
需要特别说明的是，只有超级用户才能用date命令设置时间，一般用户只能用date命令显示时间。<br />
例1：用指定的格式显示时间。<br />
$ date ‘+This date now is =&gt;%x ，time is now =&gt;%X ，thank you !&#8217;<br />
This date now is =&gt;11/12/99 ，time is now =&gt;17:53:01 ，thank you !<br />
例2：用预定的格式显示当前的时间。<br />
# date<br />
Fri Nov 26 15：20：18 CST 1999<br />
例3：设置时间为下午14点36分。<br />
# date -s 14:36:00<br />
Fri Nov 26 14：15：00 CST 1999<br />
例4：设置时间为1999年11月28号。<br />
# date -s 991128<br />
Sun Nov 28 00：00：00 CST 1999<br />
例5：设置一天前<br />
date &#8211;date “1 days ago” +”%Y-%m-%d”</p>
<h2  class="related_post_title">其他大家爱看的文字</h2><ul class="related_post"><li><a href="http://www.linuxbyte.org/ri-li-ming-ling-cal.html" title="日历命令 cal">日历命令 cal</a></li><li><a href="http://www.linuxbyte.org/magiclinux-2-6-x86_64-de-di-yi-ge-yuan-xing-iso.html" title="Magiclinux 2.6(x86_64) 的第一个原型iso">Magiclinux 2.6(x86_64) 的第一个原型iso</a></li><li><a href="http://www.linuxbyte.org/a-free-vpn.html" title="一个免费的VPN">一个免费的VPN</a></li><li><a href="http://www.linuxbyte.org/ubuntu-8-04-alpha-6.html" title="Ubuntu 8.04 Alpha 6 released">Ubuntu 8.04 Alpha 6 released</a></li><li><a href="http://www.linuxbyte.org/yi-ge-bu-cuo-de-firfox-bei-fen-cha-jian-febe.html" title="一个不错的firfox备份插件 &#8211;FEBE">一个不错的firfox备份插件 &#8211;FEBE</a></li><li><a href="http://www.linuxbyte.org/mandriva-2011-alpha-1-fa-bu.html" title="Mandriva 2011 Alpha 1 发布">Mandriva 2011 Alpha 1 发布</a></li><li><a href="http://www.linuxbyte.org/wang-ba-mei-ip-xian-su-bu-chong-squid-xian-su.html" title="网吧每IP 限速补充（squid 限速）">网吧每IP 限速补充（squid 限速）</a></li><li><a href="http://www.linuxbyte.org/ylmf-os-4-0-zheng-shi-ban-fa-bu.html" title="Ylmf OS 4.0 正式版发布">Ylmf OS 4.0 正式版发布</a></li><li><a href="http://www.linuxbyte.org/kde-359-announce.html" title="KDE 3.5.9发布公告">KDE 3.5.9发布公告</a></li><li><a href="http://www.linuxbyte.org/open-source-times-no1.html" title=" ChinaUnix《开源时代》电子杂志第一期（9月刊）下载"> ChinaUnix《开源时代》电子杂志第一期（9月刊）下载</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/command-date-tips.html">date 命令使用小技巧</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/date" rel="tag">date</a><br/>
</small></p>
	<p style="margin:3px 0 0 0;">标签：<a href="http://www.linuxbyte.org/tag/date" title="date" rel="tag">date</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/command-date-tips.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

