<?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>Tue, 22 Jun 2010 15:10:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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 a char
Ctrl + k -... ]]></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>
<h3  class="related_post_title">与本文关系暧昧的文字</h3><ul class="related_post"><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 />
<a href="http://www.linuxbyte.org/bash-shell-kuai-jie-jian.html#comments">4 comments</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>
	标签：<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><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.linuxbyte.org/bash-tips.html" title="我常用的小shell (2008-07-04)">我常用的小shell</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合 (2008-03-07)">几个有用的bash shell组合</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/bash-remove-operating-system.html" title="dell 的 Remove Operating System 代码 (2009-01-01)">dell 的 Remove Operating System 代码</a> (1)</li>
	<li><a href="http://www.linuxbyte.org/bash-quick-reference-bash-redirection.html" title="Bash的输入输出重定向 (2008-03-03)">Bash的输入输出重定向</a> (0)</li>
</ul>


<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>
<h3  class="related_post_title">其他大家爱看的文字</h3><ul class="related_post"><li><a href="http://www.linuxbyte.org/boondog-a-fun-and-challenging-puzzle-game.html" title="Boondog 一个有趣的小游戏">Boondog 一个有趣的小游戏</a></li><li><a href="http://www.linuxbyte.org/linuxdeepin-9-12-final-zheng-shi-ban-fa-bu-liao.html" title="LinuxDeepin 9.12 Final (正式版)发布了">LinuxDeepin 9.12 Final (正式版)发布了</a></li><li><a href="http://www.linuxbyte.org/mozilla-firefox-20013-released.html" title="Mozilla Firefox 2.0.0.13 发布">Mozilla Firefox 2.0.0.13 发布</a></li><li><a href="http://www.linuxbyte.org/wen-quan-dian-zhen-song-ti-1-0-rc1fa-bu.html" title="文泉驿点阵宋体1.0 RC1发布">文泉驿点阵宋体1.0 RC1发布</a></li><li><a href="http://www.linuxbyte.org/my-cnf-master.html" title="mysql master 配置备份">mysql master 配置备份</a></li><li><a href="http://www.linuxbyte.org/fedora-11-zheng-shi-fa-bu.html" title="Fedora 11 正式发布">Fedora 11 正式发布</a></li><li><a href="http://www.linuxbyte.org/ubuntu-9-10-an-zhuang-pei-zhi-xiao-ji.html" title="Ubuntu 9.10 安装配置小记">Ubuntu 9.10 安装配置小记</a></li><li><a href="http://www.linuxbyte.org/ksplice-uptrack-an-zhuang-shi-yong-xiao-ji.html" title="Ksplice Uptrack 安装使用小记">Ksplice Uptrack 安装使用小记</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 />
<a href="http://www.linuxbyte.org/ffmpeg-pi-liang-zhuan-huan-jiao-ben.html#comments">No comment</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>
	标签：<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><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li>无相关日志</li>
	</ul>


<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>0</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:si... ]]></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;"><span style="color: #c20cb9; font-weight: bold;">size</span></span>=<span style="color: #000000;">9</span>
xftfont Sans:<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">size</span></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>

<h3  class="related_post_title">与本文关系暧昧的文字</h3><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 />
<a href="http://www.linuxbyte.org/wo-de-conky-pei-zhi-wen-jian.html#comments">15 comments</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>
	标签：<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><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.linuxbyte.org/super-mrtg_cfg.html" title="一份非常好的mrtg.cfg (2008-10-06)">一份非常好的mrtg.cfg</a> (0)</li>
</ul>


<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>

<h3  class="related_post_title">与本文关系暧昧的文字</h3><ul class="related_post"><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 />
<a href="http://www.linuxbyte.org/iptables%ef%bc%8dtc-wang-ba-mei-ip-xian-su-jiao-ben.html#comments">5 comments</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>
	标签：<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><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.linuxbyte.org/wang-ba-mei-ip-xian-su-bu-chong-squid-xian-su.html" title="网吧每IP 限速补充（squid 限速） (2010-01-31)">网吧每IP 限速补充（squid 限速）</a> (2)</li>
	<li><a href="http://www.linuxbyte.org/linux-iptables-nat-squid-pdnsd.html" title="网吧Linux 网关设置记录 (2008-05-27)">网吧Linux 网关设置记录</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/yong-iptables-er-fei-tc-xian-zhi-liu-liang.html" title="用Iptables 而非tc 限制流量 (2009-04-18)">用Iptables 而非tc 限制流量</a> (5)</li>
	<li><a href="http://www.linuxbyte.org/linux-syn-attack-defense.html" title="LINUX下的SYN攻击防御 (2008-02-12)">LINUX下的SYN攻击防御</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/iptables-command-example.html" title="iptables 基本命令使用举例 (2008-03-03)">iptables 基本命令使用举例</a> (0)</li>
</ul>


<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 re... ]]></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>

<h3  class="related_post_title">与本文关系暧昧的文字</h3><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-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 />
<a href="http://www.linuxbyte.org/bash-remove-operating-system.html#comments">One comment</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>
	标签：<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><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.linuxbyte.org/bash-tips.html" title="我常用的小shell (2008-07-04)">我常用的小shell</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合 (2008-03-07)">几个有用的bash shell组合</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/bash-quick-reference-bash-redirection.html" title="Bash的输入输出重定向 (2008-03-03)">Bash的输入输出重定向</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/bash-shell-kuai-jie-jian.html" title="Bash Shell 快捷键 (2010-06-06)">Bash Shell 快捷键</a> (4)</li>
</ul>


<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 &#8220;-1 day&#8221;
//明日时间
date +%Y%m%d -d &#8220;+1 day&#8221;
//一月之间
date +%Y%m%d -d &#8220;-30... ]]></description>
			<content:encoded><![CDATA[<p>前两天在做为squid 做日志截断时零时学习了一下 date 命令的使用，这里做个小纪录</p>
<p>//昨日时间<br />
date +%Y%m%d -d &#8220;-1 day&#8221;<br />
//明日时间<br />
date +%Y%m%d -d &#8220;+1 day&#8221;<br />
//一月之间<br />
date +%Y%m%d -d &#8220;-30 day&#8221;</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 &#8220;1 days ago&#8221; +&#8221;%Y-%m-%d&#8221;</p>
<h3  class="related_post_title">其他大家爱看的文字</h3><ul class="related_post"><li><a href="http://www.linuxbyte.org/ubuntu-804-beta-released.html" title="Ubuntu 8.04 Beta 发布">Ubuntu 8.04 Beta 发布</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/rescue-my-fedora9-with-ubuntu-livecd.html" title="用ubuntu liveCD 修复fedora9 的grub">用ubuntu liveCD 修复fedora9 的grub</a></li><li><a href="http://www.linuxbyte.org/linuxdeepin-9-12-final-zheng-shi-ban-fa-bu-liao.html" title="LinuxDeepin 9.12 Final (正式版)发布了">LinuxDeepin 9.12 Final (正式版)发布了</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/win-xia-yong-putty-wanchengyijianweihu-linux-zhuji.html" title="win 下用putty 完成一键维护Linux 主机">win 下用putty 完成一键维护Linux 主机</a></li><li><a href="http://www.linuxbyte.org/fedora11zheng-shi-ban-guan-fang-xia-zai.html" title="Fedora11正式版官方下载">Fedora11正式版官方下载</a></li><li><a href="http://www.linuxbyte.org/haiku-os-opensource-beos.html" title="Haiku OS项目要以开源形式促BeOS复兴">Haiku OS项目要以开源形式促BeOS复兴</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 />
<a href="http://www.linuxbyte.org/command-date-tips.html#comments">No comment</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/date" rel="tag">date</a><br/>
</small></p>
	标签：<a href="http://www.linuxbyte.org/tag/date" title="date" rel="tag">date</a><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li>无相关日志</li>
	</ul>


<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>
		<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>
<h3  class="related_post_title">与本文关系暧昧的文字</h3><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/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 />
<a href="http://www.linuxbyte.org/shel-fang-zhi-wu-cao-zuo.html#comments">One comment</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/shell" rel="tag">shell</a><br/>
</small></p>
	标签：<a href="http://www.linuxbyte.org/tag/shell" title="shell" rel="tag">shell</a><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.linuxbyte.org/yong-shc-jiami-shell.html" title="用shc 加密shell (2009-04-09)">用shc 加密shell</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合 (2008-03-07)">几个有用的bash shell组合</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/fun-unix-shell.html" title="一些奇怪的unix指令名字的由来 (2008-08-26)">一些奇怪的unix指令名字的由来</a> (2)</li>
	<li><a href="http://www.linuxbyte.org/unixshellbian-cheng-di-san-ban.html" title="Unix.Shell编程(第三版) (2009-07-17)">Unix.Shell编程(第三版)</a> (3)</li>
</ul>


<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>我常用的小shell</title>
		<link>http://www.linuxbyte.org/bash-tips.html</link>
		<comments>http://www.linuxbyte.org/bash-tips.html#comments</comments>
		<pubDate>Fri, 04 Jul 2008 09:41:56 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[系统管理]]></category>
		<category><![CDATA[Bash]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=173</guid>
		<description><![CDATA[下面是我平常用的一些bash shell 组合，方便我的日常管理。
清除所有arp 缓存

arp -n&#124;awk '/^[1-9]/ {print &#34;arp -d &#34;$1}'&#124;sh

显示打开连接数前10个机子的IP 和连接数

cat /proc/net/ip_conntrack &#124;... ]]></description>
			<content:encoded><![CDATA[<p>下面是我平常用的一些bash shell 组合，方便我的日常管理。<br />
<strong>清除所有arp 缓存</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">arp -n<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'/^[1-9]/ {print &quot;arp -d &quot;$1}'</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">sh</span></pre></div></div>

<p><strong>显示打开连接数前10个机子的IP 和连接数</strong></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>ip_conntrack <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> <span style="color: #660033;">-f</span> <span style="color: #000000;">10</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> <span style="color: #660033;">-f</span> <span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-nr</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">10</span></pre></div></div>

<p><strong>绑定已知机子的arp 地址</strong></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 $1 &quot; &quot; $4}'</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">sort</span> -t. <span style="color: #660033;">-n</span> +<span style="color: #000000;">3</span> <span style="color: #660033;">-4</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ethers</pre></div></div>

<p><strong>批量重命名</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{printf&quot;mv %s file_%06d\n&quot;,$0,i++}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sh</span></pre></div></div>

<p><strong>Per脚本实现eth0挂起后自动重启</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span>
&nbsp;
<span style="color: #0000ff;">$fail_count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$cmd_result</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$cmd_result</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`ping -w 4 61.130.107.193 |grep packet`</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$cmd_result</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/100% packet loss/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #0000ff;">$fail_count</span><span style="color: #339933;">++;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fail_count</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #ff0000;">`ifdown eth0`</span><span style="color: #339933;">;</span>
<span style="color: #ff0000;">`ifup eth0`</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #0000ff;">$fail_count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>自动从apnic记录中分离出网通，电信IP 段</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">FILE</span>=<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>ip.txt
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$FILE</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>ftp.apnic.net<span style="color: #000000; font-weight: bold;">/</span>apnic<span style="color: #000000; font-weight: bold;">/</span>stats<span style="color: #000000; font-weight: bold;">/</span>apnic<span style="color: #000000; font-weight: bold;">/</span>delegated-apnic-latest <span style="color: #660033;">-O</span> <span style="color: #007800;">$FILE</span>
<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'apnic|CN|ipv4|'</span> <span style="color: #007800;">$FILE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">4</span>,<span style="color: #000000;">5</span> <span style="color: #660033;">-d</span><span style="color: #ff0000;">'|'</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/|/ /g'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> ip cnt
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ip</span>:<span style="color: #007800;">$cnt</span>
<span style="color: #007800;">mask</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> EOF <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-1</span>
<span style="color: #007800;">pow</span>=<span style="color: #000000;">32</span>;
define log2<span style="color: #7a0874; font-weight: bold;">&#40;</span>x<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;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>x<span style="color: #000000; font-weight: bold;">&lt;</span>=<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>pow<span style="color: #7a0874; font-weight: bold;">&#41;</span>;
pow--;
<span style="color: #7a0874; font-weight: bold;">return</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>log2<span style="color: #7a0874; font-weight: bold;">&#40;</span>x<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
log2<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$cnt</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
EOF<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ip</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$mask</span><span style="color: #000000; font-weight: bold;">&gt;&gt;</span> cn.net
<span style="color: #007800;">NETNAME</span>=<span style="color: #000000; font-weight: bold;">`</span>whois <span style="color: #007800;">$ip</span><span style="color: #000000; font-weight: bold;">@</span>whois.apnic.net <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/./{H;$!d;}'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'x;/netnum/!d'</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> ^netname <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/.*:      \(.*\)/\1/g'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/-.*//g'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$NETNAME</span> <span style="color: #000000; font-weight: bold;">in</span>
CNC<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ip</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$mask</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> CNCGROUP
<span style="color: #000000; font-weight: bold;">;;</span>
CHINANET<span style="color: #000000; font-weight: bold;">|</span>CNCGROUP<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ip</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$mask</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$NETNAME</span>
<span style="color: #000000; font-weight: bold;">;;</span>
CHINANET<span style="color: #000000; font-weight: bold;">|</span>CNCGROUP<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ip</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$mask</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$NETNAME</span>
<span style="color: #000000; font-weight: bold;">;;</span>
CHINATELECOM<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ip</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$mask</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> CHINANET
<span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ip</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$mask</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> OTHER
<span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p><strong>去掉文件中的注释和空格</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> filename <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'^$'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'^#'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> newfile</pre></div></div>

<h3  class="related_post_title">与本文关系暧昧的文字</h3><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/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>, 2008<br />
Source: <a href="http://www.linuxbyte.org/bash-tips.html">我常用的小shell</a><br />
<a href="http://www.linuxbyte.org/bash-tips.html#comments">No comment</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/bash" rel="tag">Bash</a><br/>
</small></p>
	标签：<a href="http://www.linuxbyte.org/tag/bash" title="Bash" rel="tag">Bash</a><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.linuxbyte.org/fun-bash-shell.html" title="几个有用的bash shell组合 (2008-03-07)">几个有用的bash shell组合</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/bash-remove-operating-system.html" title="dell 的 Remove Operating System 代码 (2009-01-01)">dell 的 Remove Operating System 代码</a> (1)</li>
	<li><a href="http://www.linuxbyte.org/bash-quick-reference-bash-redirection.html" title="Bash的输入输出重定向 (2008-03-03)">Bash的输入输出重定向</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/bash-shell-kuai-jie-jian.html" title="Bash Shell 快捷键 (2010-06-06)">Bash Shell 快捷键</a> (4)</li>
</ul>


<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-tips.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sed 总结</title>
		<link>http://www.linuxbyte.org/sed-tips.html</link>
		<comments>http://www.linuxbyte.org/sed-tips.html#comments</comments>
		<pubDate>Tue, 13 May 2008 10:09:05 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[精品文档]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/?p=144</guid>
		<description><![CDATA[作者：zleil
################################################################
#[0]:  基础                                                                                            #
###... ]]></description>
			<content:encoded><![CDATA[<p>作者：zleil<br />
################################################################<br />
#[0]:  基础                                                                                            #<br />
################################################################<br />
**sed执行过程:<br />
   a. 如果已到达文件尾,goto e;否则,用当前行内容替换模式空间的内容(即缓冲区,还有一个缓冲区:后备空间);<br />
   b. 执行命令序列,命令只对模式空间有效;<br />
   c. 当前行号加1<br />
   d. goto a;<br />
   e. 退出<br />
注: 当前行号可由命令N或n更改,当前行号最初为第1行<br />
    执行命令时,如果该命令有地址前缀,那么看*当前行号*是否与地址前缀相符,相符则执行,否则不执行<br />
<span id="more-144"></span><br />
例子:<br />
$sed -e &#8216;p;p;i \<br />
my-inserted-text<br />
p;<br />
a \<br />
my-appended-text<br />
p;&#8217; filename<br />
这个例子中有6条命令:4个p命令,1个i命令,1个a命令;<br />
$sed -e &#8216;2p;3,5p;6~10i \<br />
my-inserted-text<br />
p;<br />
7a \<br />
my-appended-text<br />
/AA/p;&#8217; filename<br />
这个例子类似上个,仅加入了地址前缀<br />
((详情请参考下文))</p>
<p>**常用方法:<br />
命令:<br />
sed &#8216;commands&#8217; targetfile<br />
echo &#8220;string&#8221; |sed &#8216;commands&#8217;<br />
脚本:<br />
#!/bin/sed -f<br />
command1<br />
command2<br />
&#8230;</p>
<p>**选项:<br />
-V<br />
&#8211;version<br />
          提示版本信息<br />
-h<br />
&#8211;help<br />
          提示帮助信息<br />
-n<br />
&#8211;quite<br />
&#8211;silent<br />
          默认情形,sed在执行完用户提交的命令列表后,会执行p命令,这3个选项能屏蔽这个默认功能<br />
-e<br />
&#8211;exception=script<br />
          增加script命令列表到当前命令列表<br />
-f<br />
&#8211;file=script-file<br />
          增加script-file文件内的命令列表到当前命令列表<br />
初始时,当前命令列表为空;如果没有-e,&#8211;exception,-f,&#8211;file选项,那么命令行的第一个非选项参数被<br />
当作命令列表添加到当前命令列表中</p>
<p>**常见命令:<br />
可带范围地址前缀的命令(11个):<br />
d         删除模式空间的内容,goto c<br />
D         删除模式空间内的第一行,如果模式空间内还有内容,goto b,否则,goto c<br />
p         将模式空间中的内容输出到标准输出<br />
P         将模式空间中的第一行内容输出到标准输出<br />
N         读入下一行,将其*追加*到模式空间尾,当前行号加1,如果没有可读的行了,goto e<br />
n         读入下一行,用它*替换*模式空间内容,当前行好加1,如果没有可读的行了,goto e<br />
h         用模式空间内容*替换*后备空间内容<br />
H         将模式空键内容*追加*到后备空间尾<br />
g/G       同h/H,但方向相反,后备空间-&gt;模式空间<br />
x         交换模式空间和后备空间内容<br />
l         输出模式空间内容到标准输出,以更人性话的方式输出<br />
          例子:<br />
          $echo -ne &#8220;AA BBBB\nCCCDDDD\nFDSAFDSA\n&#8221;|sed -n &#8216;l&#8217;<br />
          AA BBBB$<br />
          CCCDDDD$<br />
          FDSAFDSA$<br />
{         命令块的开始,以 } 结束<br />
b label   跳转到标签label处,如同c语言的goto语句<br />
t label   从最近一次从标准输入读入一行开始 到 现在,如果执行了替换命令,且替换成功了,<br />
          那么跳转到label处,继续执行;否则执行下一条命令.<br />
          相当于条件跳转<br />
s/regexp/replacement/<br />
          对模式空间内容进行替换,只替换与regexp匹配的部分;<br />
          只对第一次匹配的进行替换<br />
s/regexp/replacement/g<br />
          对模式空间内容          对模式空间内容进行全局替换<br />
y/source/dest/<br />
          逐个字符替换,其中source的长度必须与dest相等<br />
          如:source为ABC,dest为abc,那么模式空间内的所有A字符被换成a,B换成b,C换成c<br />
          以最后一对替换为标准,<br />
          如:source为ABA,dest为abc,那么模式空间内的所有A字符被换成c(而不是a),B换成b<br />
          例子:<br />
          $echo ABCD |sed -n &#8216;y/ABA/abc/;p&#8217;<br />
          cbCD<br />
w file    把模式空间的内容写到file文件内<br />
          sed在它开始执行前,如果在当前命令序列中发现了这条命令,先将文件file清空(如果存在的话;不存在则创建),<br />
          之后所有的写入都是被追加到文件file尾</p>
<p>不带地址前缀的命令(3个):<br />
#comments 注释<br />
: label   设置标签<br />
}         与}匹配</p>
<p>最多能带一个地址的命令(5个):<br />
=         输出当前行号到标准输出<br />
a \<br />
text      执行完所有命令后,输出text到标准输出<br />
i \<br />
text      输出text到标准输出<br />
q         如果没有 -n 选项,则goto e;否则,先输出模式空间内容到标准输出,然后goto e;<br />
r file    file表示一个文件,如果这是最后一条命令,则输出文件file的内容到标准输出,然后goto c;<br />
          否则,goto c;</p>
<p>**地址格式(数字代表行号,从1开始):<br />
例子:<br />
单地址:   1   第一行<br />
          /string/   与string匹配的行<br />
          $   最后一行<br />
范围地址: 单地址,单地址<br />
          例子：<br />
          1,2     或     1~2<br />
          1,$  所有行<br />
多行:     /regexp/      代表与正则表达式regexp匹配的行<br />
          \cregexpc     代表与正则表达式regexp匹配的行,其中c可为任意字符</p>
<p>**带地址前缀的命令:<br />
例子:<br />
1p<br />
1,3p    或     1~3p</p>
<p>################################################################<br />
#[1]:  元字符 * + ? { } ( )  &lt; &gt;                                                                   #<br />
################################################################<br />
* 在当前模式内*前有匹配字符时,表示个数(&gt;=0个);<br />
例子:<br />
$echo &#8216;aaabbbbcdddd&#8217; |sed &#8217;s/\(a*\)/|\1|/&#8217;<br />
|aaa|bbbbcdddd</p>
<p>* 在当前模式内*前无匹配字符时,表示字符&#8217;*';<br />
例子:<br />
$echo &#8216;a*abbbbcdddd&#8217; |sed &#8217;s/a\(*\)/|\1|/&#8217;<br />
|*|abbbbcdddd<br />
$echo &#8216;a*abbbbcdddd&#8217; |sed &#8217;s/*/|z|/&#8217;<br />
a|z|abbbbcdddd</p>
<p>\* 表示字符&#8217;*';<br />
例子:<br />
$echo &#8216;a*abbbbcdddd&#8217; |sed &#8217;s/\(a\*\)/|\1|/&#8217;<br />
|a*|abbbbcdddd</p>
<p>? 表示字符&#8217;?';<br />
例子:<br />
$echo &#8216;a?abbbbcdddd&#8217; |sed &#8217;s/?/|z|/&#8217;<br />
a|z|abbbbcdddd</p>
<p>\? 在当前模式内?前有匹配字符时,表示个数(0或者1个);<br />
例子:<br />
$echo &#8216;aa?bbbbcdddd&#8217; |sed &#8217;s/\(a\?\)/|\1|/&#8217;<br />
|a|a?bbbbcdddd</p>
<p>\? 在当前模式内?前无匹配字符时,表示字符&#8217;?';<br />
例子:<br />
$echo &#8216;aa?bbbbcdddd&#8217; |sed &#8217;s/\(\?\)/|\1|/&#8217;<br />
aa|?|bbbbcdddd</p>
<p>+ \+ 的意义类似 ? \?,只不过表示数字时为&gt;=1个</p>
<p>{ 表示字符&#8217;{&#8216;<br />
} 表示字符&#8217;}&#8217;</p>
<p>\{ \} 用于表示出现次数,出现\{时,必须出现\}.<br />
单个\}出现时,表示字符&#8217;}&#8217;<br />
例子:<br />
$echo &#8216;({(aabbb}d&#8217; |sed &#8217;s/b\{1,\}\}/|z|/&#8217;<br />
({(aa|z|d<br />
成对\{ \}的3种格式: \{1\}   \{1,\}   \{1,9\}, 如上例</p>
<p>( 表示字符&#8217;(&#8216;<br />
) 表示字符&#8217;)&#8217;</p>
<p>\( \) 必须成对出现,表示子模式<br />
例子:<br />
$echo &#8216;a*abbbbcdddd&#8217; |sed &#8217;s/\(a\*\)/|\1|/&#8217;<br />
|a*|abbbbcdddd</p>
<p>\&lt; \&gt; 表示完全匹配一个单词<br />
[zleil@ZLEIL shApp]$ echo &#8220;abc&#8221; | sed &#8216;/b/s/\&lt;ab\&gt;/AB/g&#8217;<br />
abc<br />
[zleil@ZLEIL shApp]$ echo &#8220;ab c&#8221; | sed &#8216;/b/s/\&lt;ab\&gt;/AB/g&#8217;<br />
AB c</p>
<p>&lt; &gt; 表示普通字符 &lt; &gt;</p>
<p>**关于label的例子<br />
这有几个关于label的例子，<br />
[zleil@ZLEIL shApp]$ echo &#8220;aBBbc&#8221; | sed -n &#8216;p;b label;p;:label;p&#8217;;<br />
aBBbc<br />
aBBbc<br />
[zleil@ZLEIL shApp]$ echo &#8220;aBBbc&#8221; | sed -n &#8217;s/B/k/;t label;p;:label;p&#8217;;<br />
akBbc<br />
[zleil@ZLEIL shApp]$ echo &#8220;aBBbc&#8221; | sed -n &#8217;s/D/k/;t label;p;:label;p&#8217;;<br />
aBBbc<br />
aBBbc</p>
<h3  class="related_post_title">与本文关系暧昧的文字</h3><ul class="related_post"><li><a href="http://www.linuxbyte.org/sed-mini-howto.html" title="Sed学习笔记">Sed学习笔记</a></li><li><a href="http://www.linuxbyte.org/sedsi-wei-dao-tu.html" title="sed思维导图">sed思维导图</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/sed-tips.html">sed 总结</a><br />
<a href="http://www.linuxbyte.org/sed-tips.html#comments">No comment</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/sed" rel="tag">sed</a><br/>
</small></p>
	标签：<a href="http://www.linuxbyte.org/tag/sed" title="sed" rel="tag">sed</a><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.linuxbyte.org/sedsi-wei-dao-tu.html" title="sed思维导图 (2008-03-08)">sed思维导图</a> (1)</li>
	<li><a href="http://www.linuxbyte.org/sed-mini-howto.html" title="Sed学习笔记 (2008-05-05)">Sed学习笔记</a> (0)</li>
</ul>


<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/sed-tips.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux下用批量convert管理图片</title>
		<link>http://www.linuxbyte.org/linux-convert-mini-howto.html</link>
		<comments>http://www.linuxbyte.org/linux-convert-mini-howto.html#comments</comments>
		<pubDate>Mon, 05 May 2008 04:42:17 +0000</pubDate>
		<dc:creator>xiao H</dc:creator>
				<category><![CDATA[shell]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://www.linuxbyte.org/linux-convert-mini-howto</guid>
		<description><![CDATA[今天在整理妮妮在医院拍的照片，想挑几张放到妮妮的blog 上去，结果发现原图都好大2240&#215;1488 的分辨率，文件大小都在1M 左右，这样的图放上去显然是太大了，并且所有的图都是横着的每次... ]]></description>
			<content:encoded><![CDATA[<p>今天在整理妮妮在医院拍的照片，想挑几张放到妮妮的blog 上去，结果发现原图都好大2240&#215;1488 的分辨率，文件大小都在1M 左右，这样的图放上去显然是太大了，并且所有的图都是横着的每次看都要旋转270°  才行，于是乎就想找个工具批量编辑一下。搜索了一圈还是觉得用Image MagicK 是convert 最好。</p>
<p>具体方法如下：</p>
<p><span id="more-129"></span></p>
<p>sudo apt-get install imagemagick<br />
创建一个 img.sh 文件，内容为</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> img <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> nini-pic<span style="color: #000000; font-weight: bold;">/*`</span>
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> sm-nini-pic
convert <span style="color: #660033;">-rotate</span> <span style="color: #000000;">270</span> <span style="color: #660033;">-resize</span> <span style="color: #000000;">30</span><span style="color: #000000; font-weight: bold;">%</span>x30<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #007800;">$img</span> sm-<span style="color: #007800;">$img</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p># sh img.sh (运行 img.sh)<br />
这里nini-pic 是我原文件所在目录，sm-nini-pic新文件的存放目录。 convert -rotate 270 -resize 30%x30% 旋转270° 分辨率缩小为原来的30%。</p>
<p>下面是Ubuntu中文论坛找到的关于Image MagicK的一些资料<br />
<code><br />
Image MagicK 是一个强大的图象处理工具包。它提供了几个非常方便的命令行命令: display, animate,import, montage,mogrify,identify等，可以进行图象的显示，缩放，旋转，调色，加框，加注释等，还能制作GIF动画，图象索引，能自动生 成图象.</code></p>
<p>1. 制作索引图和动画</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">!/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span>
montage <span style="color: #660033;">-bordercolor</span> <span style="color: #c20cb9; font-weight: bold;">red</span> <span style="color: #660033;">-borderwidth</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-label</span> <span style="color: #ff0000;">&quot;%f&quot;</span> <span style="color: #660033;">-tile</span> 5x3 <span style="color: #000000; font-weight: bold;">*</span>.JPG montage.jpg
mogrify <span style="color: #660033;">-format</span> gif <span style="color: #000000; font-weight: bold;">*</span>.JPG
display montage.jpg
animate <span style="color: #000000; font-weight: bold;">*</span>.JPG</pre></div></div>

<p>2. 缩放 convert -sample 80&#215;40 input.jpg output.jpg #注意：缩放后图像保持原来的长宽比例 convert -sample 25%x25% input.jpg output.jpg<br />
3. 为当前目录的所有图像生成缩略图</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> img <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">*</span>.jpg<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">do</span>
convert <span style="color: #660033;">-sample</span> <span style="color: #000000;">25</span><span style="color: #000000; font-weight: bold;">%</span>x25<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #007800;">$img</span> thumb-<span style="color: #007800;">$img</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>4. 获取文件信息 libtiff</p>
<p>tiffinfo filename.tiff<br />
pnginfo filename.png</p>
<p>5. 可以使用 ImageMagick 的 identify</p>
<p>identify -verbose sample.png<br />
identify -format &#8220;%wx%h&#8221; sample.png</p>
<p>6. 旋转图像</p>
<p>convert -rotate 90 input.jpg output.jpg</p>
<p>7. 更改文件类型</p>
<p>convert input.jpg output.png</p>
<p>8. 为图像增加注释文字</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">convert <span style="color: #660033;">-font</span> helvetica <span style="color: #660033;">-fill</span> white <span style="color: #660033;">-pointsize</span> <span style="color: #000000;">36</span> \
<span style="color: #660033;">-draw</span> <span style="color: #ff0000;">'text 10,50 &quot;Floriade 2002, Canberra, Australia&quot;'</span> \
floriade.jpg comment.jpg
convert <span style="color: #660033;">-font</span> fonts<span style="color: #000000; font-weight: bold;">/</span>1900805.ttf <span style="color: #660033;">-fill</span> white <span style="color: #660033;">-pointsize</span> <span style="color: #000000;">36</span> \
<span style="color: #660033;">-draw</span> <span style="color: #ff0000;">'text 10,475 &quot;stillhq.com&quot;'</span> \
floriade.jpg stillhq.jpg</pre></div></div>

<p>9. 特殊效果</p>
<p>convert -charcoal 2 input.jpg output.jpg #炭笔<br />
convert -colorize 255 input.jpg output.jpg #着色 可以指定三种颜色 red/green/blue<br />
convert -implode 4 input.jpg output.jpg #内爆效果<br />
convert -solarize 42 input.jpg output.jpg #曝光，模拟胶片曝光<br />
convert -spread 5 input.jpg output.jpg #随机移动，参数是位移大小</p>
<p>10. 一次执行多个操作</p>
<p>convert -sample 25%x25% -spread 4 -charcoal 4 input.jpg output.jpg</p>
<h3  class="related_post_title">与本文关系暧昧的文字</h3><ul class="related_post"><li><a href="http://www.linuxbyte.org/selinux-howto.html" title=" SELinux 的howto文档下载"> SELinux 的howto文档下载</a></li><li><a href="http://www.linuxbyte.org/svn-howto.html" title="SVN 使用入门 ">SVN 使用入门 </a></li><li><a href="http://www.linuxbyte.org/howto-do-linux-kernel-development.html" title="HOWTO do Linux kernel development ">HOWTO do Linux kernel development </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/linux-convert-mini-howto.html">Linux下用批量convert管理图片</a><br />
<a href="http://www.linuxbyte.org/linux-convert-mini-howto.html#comments">No comment</a><br />
Post tags: <a href="http://www.linuxbyte.org/tag/convert" rel="tag">convert</a>, <a href="http://www.linuxbyte.org/tag/howto" rel="tag">howto</a><br/>
</small></p>
	标签：<a href="http://www.linuxbyte.org/tag/convert" title="convert" rel="tag">convert</a>, <a href="http://www.linuxbyte.org/tag/howto" title="howto" rel="tag">howto</a><br />

	<h4>相关日志</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.linuxbyte.org/svn-howto.html" title="SVN 使用入门 (2008-04-08)">SVN 使用入门</a> (2)</li>
	<li><a href="http://www.linuxbyte.org/howto-do-linux-kernel-development.html" title="HOWTO do Linux kernel development (2008-03-04)">HOWTO do Linux kernel development</a> (0)</li>
	<li><a href="http://www.linuxbyte.org/selinux-howto.html" title="SELinux 的howto文档下载 (2008-07-12)">SELinux 的howto文档下载</a> (0)</li>
</ul>


<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/linux-convert-mini-howto.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
