﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-我的编程乐园-文章分类-Linux/Unix</title><link>http://www.cppblog.com/deercoder/category/12591.html</link><description>&lt;P&gt;&lt;FONT style="FONT-SIZE: 20px" color=#ff0000&gt;积累，坚持！&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT style="FONT-SIZE: 20px" color=#ff0000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ---------我是一只IT小小鸟&lt;/FONT&gt;&lt;/P&gt;</description><language>zh-cn</language><lastBuildDate>Fri, 18 Nov 2011 06:09:17 GMT</lastBuildDate><pubDate>Fri, 18 Nov 2011 06:09:17 GMT</pubDate><ttl>60</ttl><item><title>Linux下面利用命令批量抓取图片</title><link>http://www.cppblog.com/deercoder/articles/160399.html</link><dc:creator>刘畅</dc:creator><author>刘畅</author><pubDate>Thu, 17 Nov 2011 16:17:00 GMT</pubDate><guid>http://www.cppblog.com/deercoder/articles/160399.html</guid><wfw:comment>http://www.cppblog.com/deercoder/comments/160399.html</wfw:comment><comments>http://www.cppblog.com/deercoder/articles/160399.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/deercoder/comments/commentRss/160399.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/deercoder/services/trackbacks/160399.html</trackback:ping><description><![CDATA[<div><p>批量下载图片（一般是某个相册的图片）</p>  <p>首先先得到一张图片的地址如：www.example.com/pic/001.jpg</p>  <p>同相册的图片地址会有一定的规律，可以用：</p>  <p>&nbsp;</p>  <div "="" id="highlighter_412356"><div><div alt1"=""><table><tbody><tr><td><code>1</code></td><td><code>$: </code><code>echo</code>&nbsp; <code>www.example.com/pic/{001..020}.jpg&nbsp;&gt;url.txt</code></td></tr></tbody></table></div></div></div>  <p>得到二十张图片的地址是用空格分开的,再用vim编辑url文件，把空格替换成回车（\r）</p>  <p>&nbsp;</p>  <div "="" id="highlighter_31922"><div><div alt1"=""><table><tbody><tr><td><code>1</code></td><td><code>：s/ /\r/g</code></td></tr></tbody></table></div></div></div>结果：  <p>&nbsp;</p>  <div "="" id="highlighter_9254"><div><div alt1"=""><table><tbody><tr><td><code>01</code></td><td><code>www.example.com/pic/001.jpg </code></td></tr></tbody></table></div><div alt2"=""><table><tbody><tr><td><code>02</code></td><td><code>www.example.com/pic/002.jpg</code></td></tr></tbody></table></div><div alt1"=""><table><tbody><tr><td><code>03</code></td><td><code>www.example.com/pic/003.jpg</code></td></tr></tbody></table></div><div alt2"=""><table><tbody><tr><td><code>04</code></td><td><code>www.example.com/pic/004.jpg</code></td></tr></tbody></table></div><div alt1"=""><table><tbody><tr><td><code>05</code></td><td><code>www.example.com/pic/005.jpg</code></td></tr></tbody></table></div><div alt2"=""><table><tbody><tr><td><code>06</code></td><td><code>www.example.com/pic/006.jpg</code></td></tr></tbody></table></div><div alt1"=""><table><tbody><tr><td><code>07</code></td><td><code>www.example.com/pic/007.jpg</code></td></tr></tbody></table></div><div alt2"=""><table><tbody><tr><td><code>08</code></td><td><code>www.example.com/pic/008.jpg</code></td></tr></tbody></table></div><div alt1"=""><table><tbody><tr><td><code>09</code></td><td><code>www.example.com/pic/009.jpg</code></td></tr></tbody></table></div><div alt2"=""><table><tbody><tr><td><code>10</code></td><td><code>www.example.com/pic/010.jpg</code></td></tr></tbody></table></div><div alt1"=""><table><tbody><tr><td><code>11</code></td><td><code>www.example.com/pic/011.jpg</code></td></tr></tbody></table></div><div alt2"=""><table><tbody><tr><td><code>12</code></td><td><code>www.example.com/pic/012.jpg</code></td></tr></tbody></table></div><div alt1"=""><table><tbody><tr><td><code>13</code></td><td><code>www.example.com/pic/013.jpg</code></td></tr></tbody></table></div><div alt2"=""><table><tbody><tr><td><code>14</code></td><td><code>www.example.com/pic/014.jpg</code></td></tr></tbody></table></div><div alt1"=""><table><tbody><tr><td><code>15</code></td><td><code>www.example.com/pic/015.jpg</code></td></tr></tbody></table></div><div alt2"=""><table><tbody><tr><td><code>16</code></td><td><code>www.example.com/pic/016.jpg</code></td></tr></tbody></table></div><div alt1"=""><table><tbody><tr><td><code>17</code></td><td><code>www.example.com/pic/017.jpg</code></td></tr></tbody></table></div><div alt2"=""><table><tbody><tr><td><code>18</code></td><td><code>www.example.com/pic/018.jpg</code></td></tr></tbody></table></div><div alt1"=""><table><tbody><tr><td><code>19</code></td><td><code>www.example.com/pic/019.jpg</code></td></tr></tbody></table></div><div alt2"=""><table><tbody><tr><td><code>20</code></td><td><code>www.example.com/pic/020.jpg</code></td></tr></tbody></table></div></div></div>  <p>在用wget命令批量下载：</p>  <p>&nbsp;</p>  <div "="" id="highlighter_622472"><div><div alt1"=""><table><tbody><tr><td><code>1</code></td><td><code>$: wget -i url.txt -P ./Photo</code></td></tr></tbody></table></div></div></div>  <p>wget命令的-i参数是从指定的文件读取地址，-P参数是把下载的文件放到指定的路径下。</p>  <p>&nbsp;</p>  <p>问题：</p>  <p>现在图片的地址一般规律不明显，但可以用穷举法来下载。<br /><br /><br /><br /><br /><br /><br /><br /></p></div><div class="vimiumHUD" style="right: 150px; opacity: 0; display: none; "></div><img src ="http://www.cppblog.com/deercoder/aggbug/160399.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/deercoder/" target="_blank">刘畅</a> 2011-11-18 00:17 <a href="http://www.cppblog.com/deercoder/articles/160399.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux常用命令之find和grep</title><link>http://www.cppblog.com/deercoder/articles/159357.html</link><dc:creator>刘畅</dc:creator><author>刘畅</author><pubDate>Sun, 30 Oct 2011 09:10:00 GMT</pubDate><guid>http://www.cppblog.com/deercoder/articles/159357.html</guid><wfw:comment>http://www.cppblog.com/deercoder/comments/159357.html</wfw:comment><comments>http://www.cppblog.com/deercoder/articles/159357.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/deercoder/comments/commentRss/159357.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/deercoder/services/trackbacks/159357.html</trackback:ping><description><![CDATA[<div><span style="color: #333333; font-family: Georgia,'Times New Roman',Times,san-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;"><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">man文档中给出的find命令的一般形式为：</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">其实[-H] [-L] [-P] [-D debugopts] [-Olevel]这几个选项并不常用（至少在我的日常工作中，没有用到过），上面的find命令的常用形式可以简化为：</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span size="3" style="font-size: small; color: red;">find [path...] [expression]</span></p><li>path：find命令所查找的目录路径。例如用.来表示当前目录，用/来表示系统根目录</li><li>expression：expression可以分为&#8212;&#8212;&#8220;-options [-print -exec -ok ...]&#8221;</li><li>-options，指定find命令的常用选项，下节详细介绍</li><li>-print，find命令将匹配的文件输出到标准输出</li><li><span style="color: red;">-exec，find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' {&nbsp; } \;，注意{&nbsp;&nbsp; }和\；之间的空格&nbsp;</span><br />find ./ -size 0 -exec rm {} \; 删除文件大小为零的文件 （还可以以这样做：rm -i `find ./ -size 0`&nbsp; 或 find ./ -size 0 | xargs rm -f &amp;）&nbsp;<br />为了用ls -l命令列出所匹配到的文件，可以把ls -l命令放在find命令的-exec选项中：find . -type f -exec ls -l {&nbsp; } \;&nbsp;<br />在/logs目录中查找更改时间在5日以前的文件并删除它们：find /logs -type f -mtime +5 -exec rm {&nbsp; } \;</li><li>-ok，和-exec的作用相同，只不过以一种更为安全的模式来执行该参数所给出的shell命令，在执行每一个命令之前，都会给出提示，让用户来确定是否执行。&nbsp;<br />find . -name "*.conf"&nbsp; -mtime +5 -ok rm {&nbsp; } \; 在当前目录中查找所有文件名以.LOG结尾、更改时间在5日以上的文件，并删除它们，只不过在删除之前先给出提示</li><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">也有人这样总结find命令的结构：</p><pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; "><span size="3" style="font-size: small; ">find <span color="#d16349" style="color: #d16349; ">start_directory</span> test <br />     <span color="#d16349" style="color: #d16349; ">options</span> <br />     <span color="#d16349" style="color: #d16349; ">criteria_to_match</span> <br />     <span color="#d16349" style="color: #d16349; ">action_to_perform_on_results</span><br /></span></pre><h2>1.2、find命令的常用选项及实例</h2><li>-name&nbsp;<br /><span style="color: red;">按照文件名查找文件。&nbsp;</span><br /><span style="color: red;">find /dir -name filename&nbsp; 在/dir目录及其子目录下面查找名字为filename的文件&nbsp;</span><br /><span style="color: red;">find . -name "*.c" 在当前目录及其子目录（用&#8220;.&#8221;表示）中查找任何扩展名为&#8220;c&#8221;的文件</span></li><li>-perm&nbsp;<br />按照文件权限来查找文件。&nbsp;<br />find . -perm 755 &#8211;print 在当前目录下查找文件权限位为755的文件，即文件属主可以读、写、执行，其他用户可以读、执行的文件</li><li>-prune&nbsp;<br />使用这一选项可以使find命令<span style="color: red;">不在当前指定的目录中查找</span>，如果同时使用-depth选项，那么-prune将被find命令忽略。&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find /apps -path "/apps/bin" -prune -o &#8211;print</span>&nbsp;在/apps目录下查找文件，但不希望在/apps/bin目录下查找&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find /usr/sam -path "/usr/sam/dir1" -prune -o &#8211;print</span>&nbsp;在/usr/sam目录下查找不在dir1子目录之内的所有文件</li><li>-user&nbsp;<br />按照文件属主来查找文件。&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find ~ -user sam &#8211;print</span>&nbsp;在$HOME目录中查找文件属主为sam的文件</li><li>-group&nbsp;<br />按照文件所属的组来查找文件。&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find /apps -group gem &#8211;print</span>&nbsp;在/apps目录下查找属于gem用户组的文件&nbsp;</li><li>-mtime -n +n&nbsp;<br />按照文件的更改时间来查找文件， <span style="color: red;">- n表示文件更改时间距现在n天以内，+ n表示文件更改时间距现在n天以前。&nbsp;</span><br /><span color="#d16349" style="color: #d16349; ">find / -mtime -5 &#8211;print</span>&nbsp;在系统根目录下查找更改时间在5日以内的文件&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find /var/adm -mtime +3 &#8211;print</span>&nbsp;在/var/adm目录下查找更改时间在3日以前的文件</li><li>-nogroup&nbsp;<br />查找无有效所属组的文件，即该文件所属的组在/etc/groups中不存在。&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find / &#8211;nogroup -print</span></li><li>-nouser&nbsp;<br />查找无有效属主的文件，即该文件的属主在/etc/passwd中不存在。&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find /home -nouser &#8211;print</span></li><li>-newer file1 ! file2&nbsp;<br />查找更改时间比文件file1新但比文件file2旧的文件。</li><li>-type&nbsp;<br /><span style="color: red;">查找某一类型的文件，诸如：&nbsp;</span><br />b - 块设备文件。&nbsp;<br />d - 目录。&nbsp;<br />c - 字符设备文件。&nbsp;<br />p - 管道文件。&nbsp;<br />l - 符号链接文件。&nbsp;<br />f - 普通文件。&nbsp;<br /><span color="#d16349" style="color: red;">find /etc -type d &#8211;print</span><span style="color: red;">&nbsp;在/etc目录下查找所有的目录&nbsp;</span><br /><span color="#d16349" style="color: #d16349; ">find . ! -type d &#8211;print</span>&nbsp;在当前目录下查找除目录以外的所有类型的文件&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find /etc -type l &#8211;print</span>&nbsp;在/etc目录下查找所有的符号链接文件</li><li>-size n：[c] 查找文件长度为n块的文件，带有c时表示文件长度以字节计。&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find . -size +1000000c &#8211;print</span>&nbsp;在当前目录下查找文件长度大于1 M字节的文件&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find /home/apache -size 100c &#8211;print</span>&nbsp;在/home/apache目录下查找文件长度恰好为100字节的文件&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find . -size +10 &#8211;print</span>&nbsp;在当前目录下查找长度超过10块的文件（一块等于512字节）</li><li>-depth：在查找文件时，首先查找当前目录中的文件，然后再在其子目录中查找。&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find / -name "CON.FILE" -depth &#8211;print</span>&nbsp;它将首先匹配所有的文件然后再进入子目录中查找&nbsp;</li><li>-mount：在查找文件时不跨越文件系统mount点。&nbsp;&nbsp;<br /><span color="#d16349" style="color: #d16349; ">find . -name "*.XC" -mount &#8211;print</span>&nbsp;从当前目录开始查找位于本文件系统中文件名以XC结尾的文件（不进入其他文件系统）</li><li>-follow：如果find命令遇到符号链接文件，就跟踪至链接所指向的文件。</li><h2>1.3、find与xargs</h2><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">在使用find命令的-exec选项处理匹配到的文件时， find命令将所有匹配到的文件一起传递给exec执行。但有些系统对能够传递给exec的命令长度有限制，这样在find命令运行几分钟之后，就会出现溢出错误。错误信息通常是&#8220;参数列太长&#8221;或&#8220;参数列溢出&#8221;。这就是xargs命令的用处所在，特别是与find命令一起使用。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">find命令把匹配到的文件传递给xargs命令，而xargs命令每次只获取一部分文件而不是全部，不像-exec选项那样。这样它可以先处理最先获取的一部分文件，然后是下一批，并如此继续下去。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">在有些系统中，使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程，并非将匹配到的文件全部作为参数一次执行；这样在有些情况下就会出现进程过多，系统性能下降的问题，因而效率不高；</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">而使用xargs命令则只有一个进程。另外，<span size="3" style="font-size: small; ">在使用xargs命令时，究竟是一次获取所有的参数，还是分批取得参数，以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">来看看xargs命令是如何同find命令一起使用的，并给出一些例子。（简单来说就是xargs更安全，实际上和exec相同作用）</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">find . -type f -print | xargs file</span>&nbsp;查找系统中的每一个普通文件，然后使用xargs命令来测试它们分别属于哪类文件</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">find / -name "core" -print | xargs echo "" &gt;/tmp/core.log</span>&nbsp;在整个系统中查找内存信息转储文件(core dump) ，然后把结果保存到/tmp/core.log 文件中：</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">find . -type f -print | xargs grep "hostname"</span>&nbsp;用grep命令在所有的普通文件中搜索hostname这个词</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">find ./ -mtime +3 -print|xargs rm -f &#8211;r</span>&nbsp;删除3天以前的所有东西 （find . -ctime +3 -exec rm -rf {} \;）</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">find ./ -size 0 | xargs rm -f &amp;</span>&nbsp;删除文件大小为零的文件</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">find命令配合使用exec和xargs可以使用户对所匹配到的文件执行几乎所有的命令。</p><h1>2、grep命令</h1><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具，它能使用正则表达式搜索文本，并把匹配的行打印出来。</p><h2>2.1、grep命令的一般选项及实例</h2><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span size="3" style="font-size: small; ">grep [OPTIONS] PATTERN [FILE...]&nbsp;<br />grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">grep命令用于搜索由Pattern参数指定的模式，并将每个匹配的行写入标准输出中。这些模式是具有限定的正则表达式，它们使用ed或egrep命令样式。如果在File参数中指定了多个名称，grep命令将显示包含匹配行的文件的名称。对 shell 有特殊含义的字符 ($, *, [, |, ^, (, ), \ ) 出现在 Pattern参数中时必须带双引号。如果 Pattern参数不是简单字符串，通常必须用单引号将整个模式括起来。在诸如 [a-z], 之类的表达式中，-（减号）cml 可根据当前正在整理的序列来指定一个范围。整理序列可以定义等价的类以供在字符范围中使用。如果未指定任何文件，grep会假定为标准输入。</p><h2>2.2、grep正则表达式元字符集(基本集)</h2><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">^&nbsp; 锚定行的开始 如：'^grep'匹配所有以grep开头的行。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">$&nbsp; 锚定行的结束 如：'grep$'匹配所有以grep结尾的行。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">.&nbsp;&nbsp; 匹配一个非换行符的字符 如：'gr.p'匹配gr后接一个任意字符，然后是p。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">*&nbsp; 匹配零个或多个先前字符 如：'*grep'匹配所有一个或多个空格后紧跟grep的行。</span><span size="3" style="font-size: small; color: red;">&nbsp;.*一起用代表任意字符</span><span style="color: red;">。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">[] 匹配一个指定范围内的字符，如'[Gg]rep'匹配Grep和grep。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">[^]&nbsp; 匹配一个不在指定范围内的字符，如：'[^A-FH-Z]rep'匹配不包含A-R和T-Z的一个字母开头，紧跟rep的行。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">\(..\)&nbsp; 标记匹配字符，如：'\(love\)'，love被标记为1。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">\&lt;&nbsp; 锚定单词的开始，如：'\&lt;grep'匹配包含以grep开头的单词的行。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">\&gt;&nbsp; 锚定单词的结束，如'grep\&gt;'匹配包含以grep结尾的单词的行。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">x\{m\} 连续重复字符x，m次，如：'o\{5\}'匹配包含连续5个o的行。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">x\{m,\} 连续重复字符x,至少m次，如：'o\{5,\}'匹配至少连续有5个o的行。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">x\{m,n\} 连续重复字符x，至少m次，不多于n次，如：'o\{5,10\}'匹配连续5--10个o的行。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">\w&nbsp; 匹配一个文字和数字字符，也就是[A-Za-z0-9]，如：'G\w*p'匹配以G后跟零个或多个文字或数字字符，然后是p。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">\W&nbsp; w的反置形式，匹配一个非单词字符，如点号句号等。\W*则可匹配多个。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span style="color: red;">\b&nbsp; 单词锁定符，如: '\bgrep\b'只匹配grep，即只能是grep这个单词，两边均为空格。</span></p><h2>2.3、grep命令的常用选项及实例</h2><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-?</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">同时显示匹配行上下的？行，如：grep -2 pattern filename同时显示匹配行的上下2行。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-b，--byte-offset</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">打印匹配行前面打印该行所在的块号码。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-c,--count</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">只打印匹配的行数，不显示匹配的内容。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-f File，--file=File</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">从文件中提取模板。空文件中包含0个模板，所以什么都不匹配。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-h，--no-filename</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">当搜索多个文件时，不显示匹配文件名前缀。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-i，--ignore-case</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">忽略大小写差别。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-q，--quiet</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">取消显示，只返回退出状态。0则表示找到了匹配的行。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-l，--files-with-matches</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">打印匹配模板的文件清单。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-L，--files-without-match</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">打印不匹配模板的文件清单。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-n，--line-number</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">在匹配的行前面打印行号。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-s，--silent</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">不显示关于不存在或者无法读取文件的错误信息。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-v，--revert-match</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">反检索，只显示不匹配的行。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-w，--word-regexp</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">如果被\&lt;和\&gt;引用，就把表达式做为一个单词搜索。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">-V，--version</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">显示软件版本信息。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">=====</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">ls -l | grep '^a'</span>&nbsp;通过管道过滤ls -l输出的内容，只显示以a开头的行。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">grep 'test' d*</span>&nbsp;显示所有以d开头的文件中包含test的行。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: red;">grep 'test' aa bb cc</span><span style="color: red;">&nbsp;显示在aa，bb，cc文件中匹配test的行。</span></p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">grep '[a-z]' aa</span>&nbsp;显示所有包含每个字符串至少有5个连续小写字符的字符串的行。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">grep 'w(es)t.*' aa</span>&nbsp;如果west被匹配，则es就被存储到内存中，并标记为1，然后搜索任意个字符(.*)，这些字符后面紧跟着另外一个es()，找到就显示该行。如果用egrep或grep -E，就不用""号进行转义，直接写成'w(es)t.*'就可以了。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">grep -i pattern files</span>&nbsp;：不区分大小写地搜索。默认情况区分大小写</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">grep -l pattern files</span>&nbsp;：只列出匹配的文件名，</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">grep -L pattern files</span>&nbsp;：列出不匹配的文件名，</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">grep -w pattern files</span>&nbsp;：只匹配整个单词，而不是字符串的一部分(如匹配&#8216;magic&#8217;，而不是&#8216;magical&#8217;)，</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">grep -C number pattern files</span>&nbsp;：匹配的上下文分别显示[number]行，</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">grep pattern1 | pattern2 files</span>&nbsp;：显示匹配 pattern1 或 pattern2 的行，</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; "><span color="#d16349" style="color: #d16349; ">grep pattern1 files | grep pattern2</span>&nbsp;：显示既匹配 pattern1 又匹配 pattern2 的行。</p><p style="line-height: 25px; margin-top: 12px; margin-right: auto; margin-bottom: 12px; margin-left: auto; text-indent: 0px; ">&nbsp;</p><p style="line-height: 25px; margin: 12px auto; text-indent: 0px;">参考文献：</p></span></div><div><span style="color: #333333; font-family: Georgia, 'Times New Roman', Times, san-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">关于Linux Grep命令使用的详细介绍，<a href="http://fanqiang.chinaunix.net/system/linux/2007-03-15/5110.shtml" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; ">http://fanqiang.chinaunix.net/system/linux/2007-03-15/5110.shtml</a></span></div><div><span style="color: #333333; font-family: Georgia, 'Times New Roman', Times, san-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">Linux文件查找命令find,xargs详述，<a href="http://www.linuxsir.org/main/?q=node/137#1.1" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #3d81ee; ">http://www.linuxsir.org/main/?q=node/137#1.1</a></span></div><div><span style="color: #333333; font-family: Georgia, 'Times New Roman', Times, san-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">man文档（man find、man grep）</span></div><div><a href="http://www.cnblogs.com/skynet/archive/2010/12/25/1916873.html">原文地址： http://www.cnblogs.com/skynet/archive/2010/12/25/1916873.html</a></div><br /><br /><br /><img src ="http://www.cppblog.com/deercoder/aggbug/159357.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/deercoder/" target="_blank">刘畅</a> 2011-10-30 17:10 <a href="http://www.cppblog.com/deercoder/articles/159357.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ubuntu下如何修改文件的权限------chmod的妙用［zz］</title><link>http://www.cppblog.com/deercoder/articles/110129.html</link><dc:creator>刘畅</dc:creator><author>刘畅</author><pubDate>Fri, 19 Mar 2010 12:30:00 GMT</pubDate><guid>http://www.cppblog.com/deercoder/articles/110129.html</guid><wfw:comment>http://www.cppblog.com/deercoder/comments/110129.html</wfw:comment><comments>http://www.cppblog.com/deercoder/articles/110129.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/deercoder/comments/commentRss/110129.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/deercoder/services/trackbacks/110129.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 很多时候，在Ubuntu下，使用文件的权限都有严格的区分，很麻烦，如果是到root权限下面的话，总觉得不安全，所以，在其它用户的时候，总是存在读写的权限需要修改的问题，那么如何解决呢？<br>&nbsp;&nbsp;&nbsp;&nbsp; 方法之一就是注销后到root下面修改权限，不过这个方法不太好。使用命令行的方式不错。<br><br>==================================================================================<br><br>
<p style="text-indent: 2em;">查看文件权限的命令： </p>
<p style="text-indent: 2em;">在终端输入: </p>
<p style="text-indent: 2em;">ls -l xxx.xxx （xxx.xxx是文件名） </p>
<p style="text-indent: 2em;">那么就会出现相类似的信息，主要都是这些： </p>
<p style="text-indent: 2em;">-rw-rw-r--&nbsp;&nbsp;</p>
<p style="text-indent: 2em;">一共有10位数 </p>
<p style="text-indent: 2em;">其中： 最前面那个 - 代表的是类型 </p>
<p style="text-indent: 2em;">中间那三个 rw- 代表的是所有者（user） </p>
<p style="text-indent: 2em;">然后那三个 rw- 代表的是组群（group） </p>
<p style="text-indent: 2em;">最后那三个 r-- 代表的是其他人（other） </p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">然后我再解释一下后面那9位数： </p>
<p style="text-indent: 2em;">r 表示文件可以被读（read） </p>
<p style="text-indent: 2em;">w 表示文件可以被写（write） </p>
<p style="text-indent: 2em;">x 表示文件可以被执行（如果它是程序的话） </p>
<p style="text-indent: 2em;">- 表示相应的权限还没有被授予 </p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">现在该说说修改文件权限了 </p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">在终端输入： </p>
<p style="text-indent: 2em;">chmod o+w xxx.xxx </p>
<p style="text-indent: 2em;">表示给其他人授予写xxx.xxx这个文件的权限 </p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">chmod go-rw xxx.xxx </p>
<p style="text-indent: 2em;">表示删除xxx.xxx中组群和其他人的读和写的权限 </p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">其中： </p>
<p style="text-indent: 2em;">u 代表所有者（user） </p>
<p style="text-indent: 2em;">g 代表所有者所在的组群（group） </p>
<p style="text-indent: 2em;">o 代表其他人，但不是u和g （other） </p>
<p style="text-indent: 2em;">a 代表全部的人，也就是包括u，g和o </p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">r 表示文件可以被读（read） </p>
<p style="text-indent: 2em;">w 表示文件可以被写（write） </p>
<p style="text-indent: 2em;">x 表示文件可以被执行（如果它是程序的话） </p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">其中：rwx也可以用数字来代替 </p>
<p style="text-indent: 2em;">r ------------4 </p>
<p style="text-indent: 2em;">w -----------2 </p>
<p style="text-indent: 2em;">x ------------1 </p>
<p style="text-indent: 2em;">- ------------0 </p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">行动： </p>
<p style="text-indent: 2em;">+ 表示添加权限 </p>
<p style="text-indent: 2em;">- 表示删除权限 </p>
<p style="text-indent: 2em;">= 表示使之成为唯一的权限 </p>
<p style="text-indent: 2em;">&nbsp;</p>
<p style="text-indent: 2em;">当大家都明白了上面的东西之后，那么我们常见的以下的一些权限就很容易都明白了： </p>
<p style="text-indent: 2em;">-rw------- (600) 只有所有者才有读和写的权限 </p>
<p style="text-indent: 2em;">-rw-r--r-- (644) 只有所有者才有读和写的权限，组群和其他人只有读的权限 </p>
<p style="text-indent: 2em;">-rwx------ (700) 只有所有者才有读，写，执行的权限 </p>
<p style="text-indent: 2em;">-rwxr-xr-x (755) 只有所有者才有读，写，执行的权限，组群和其他人只有读和执行的权限 </p>
<p style="text-indent: 2em;">-rwx--x--x (711) 只有所有者才有读，写，执行的权限，组群和其他人只有执行的权限 </p>
<p style="text-indent: 2em;">-rw-rw-rw- (666) 每个人都有读写的权限 </p>
<p style="text-indent: 2em;">-rwxrwxrwx (777) 每个人都有读写和执行的权限 <br></p>
<p style="text-indent: 2em;"><br></p>
转载自：http://www.linuxsky.org/doc/newbie/200801/220.html
<br><br><br>============================================================================<br>经过本人的亲身体会受用，终于知道了更多的用法和需要注意的事项：<br>1.如果向体验将一个文件夹下面的所有的文件都更改为可以读写的话，那么使用chmod a-rw 文件夹的绝对路径/*<br>注意后面的那个*表示通配符，也就是使得所有的文件都是这个权限。但是注意，文件夹的话还是前面的那样，没有更改属性和权限，如果需要更改，再次更改就是了。<br><br>2.权限滥用有坏处，仅在某些场合使用命令行比较方便，而不需要切换。<br><br>理解上面命令的含义很有作用！<br><br> <img src ="http://www.cppblog.com/deercoder/aggbug/110129.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/deercoder/" target="_blank">刘畅</a> 2010-03-19 20:30 <a href="http://www.cppblog.com/deercoder/articles/110129.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>安装Win 7后无法进入Ubuntu系统解决</title><link>http://www.cppblog.com/deercoder/articles/109824.html</link><dc:creator>刘畅</dc:creator><author>刘畅</author><pubDate>Tue, 16 Mar 2010 06:46:00 GMT</pubDate><guid>http://www.cppblog.com/deercoder/articles/109824.html</guid><wfw:comment>http://www.cppblog.com/deercoder/comments/109824.html</wfw:comment><comments>http://www.cppblog.com/deercoder/articles/109824.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/deercoder/comments/commentRss/109824.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/deercoder/services/trackbacks/109824.html</trackback:ping><description><![CDATA[     最近装过Win 7后，Ubuntu系统无法进入，出现问题。原因是，如果先装Win 7后装Ubuntu的话，采用grub方式启动，这样就可以进入菜单选择，可是，现在装完Win 7后，无法采用grub启动，所以，无法启动，导致直接进入Win 7的系统。<br />下面是解决方案：<br /><br /><div class="blog_content"><p>1 用livecd（就是ubuntu9.10 安装盘）进去，打开console。</p><p>2 查看硬盘情况:sudo fdisk -l </p><p>3 挂载 原先安装的ubuntu9.10 的分区</p><p>sudo mount /dev/sda6 /mnt </p><p>4 安装grub</p><p>sudo grub-install --root-directory=/dev/sda6</p><p>5 因重装windows后，windows安装分区的uuid会变， 故要修改grub.cfg。</p><p>5.1 查看uuid :sudo blkid<br />
5.2 修改grub.cfg其中引导windows 那个部分,改变其中uuid</p></div>上面的方法是可以成功的，经过的实验，没有问题。关键是，能够上网，重新安装grub2（对于Ubuntu 9.10是这个版本的）。<br /><br />下面还摘引了某些人的解决方案：（xp下面的解决，不过都类似的方法）<br /><br /><span style="font-size: large;">重装xp后，mbr被xp写入信息导致grub无法工作解决方法
<br />从CD-ROM启动,从Live CD启动进入桌面。
<br />打开终端或者切换到一个tty（Ctrl+Alt+F1）。
<br />输入:sudo grub
<br />输入:find /boot/grub/stage1     ##有人说这一步不用,不过个人感觉还是应该加上这一步
<br />输入:root (hd0,x)                      ##输入find命令反馈的数据
<br />输入:setup (hd0)                      ##如果想用xp进行多系统引导就写(hd0,x)
<br />输入:quit                                  ##退出grub。
<br />重新启动,不出意外的话,那么恭喜,呵呵,可以看到XP和<span class="hilite1">UBUNTU</span>的双系统引导咯^_^
<br /><br />---------------------------------------------------------------------------
<br /><br />重装windows XP 后怎样找回<span class="hilite1">Ubuntu</span><br />首先下载GRUB for Dos
<br />并安装下载Ext3分区访问软件(有Ext2Fsd 或explore2fs)
<br />运行后将<span class="hilite1">ubuntu</span>根目录下的Boot文件夹里全部复制到C盘.
<br />重启后在开机菜单里选择GRUB就可进入<span class="hilite1">ubuntu</span>.
<br />要点:<span class="hilite1">ubuntu</span> linux 需要GRUB for Dos来引导，所以C:\BOOT.INI里，会有这一行:
<br />C:\GRLDR="GRUB"ext3
<br />分区下的boot文件夹里面放了可以引导的文件,需将其放在c盘根目录.
<br /><br />-------------------------------------------------------------------------------------------------------
<br /><br />1.用livecd（强烈推荐）
<br />2.用安裝cd
<br />3.使用grub4dos
<br />4.使用grub軟盤
<br /><br />1，使用livecd（强烈推荐）
<br />使用任何你喜歡的linux livecd（比如，<span class="hilite1">ubuntu</span> 6.06的desktop cd）
<br />在终端下输入：
<br />代码:
<br /><br />sudo su
<br />grub
<br /><br />代码:grub&gt;
<br />接着输入：
<br />代码:
<br /><br />root (hdx,y)
<br />setup (hdx)
<br /><br />请不要完全照样输入！请弄懂这些命令的含义。
<br />hd表示硬盘，格式是
<br />(hd硬盘号,分区号)
<br />从零开始计算。
<br />所以（按照日常的习惯，从1开始数），
<br />(hd0,0)表示第一个硬盘的第一个分区，
<br />(hd0,1)表示第一个硬盘的第2个分区，
<br />(hd1,4)表示第2个硬盘的第5个分区。
<br />（注意，linux系统里是用hda1表示第一个硬盘的第一个分区，不要把它和grub中的表示混起来。）
<br />root (hdx,y)这里的(hdx,y) 是/boot 目录所在的分区
<br />（通常情况下，也就是你装<span class="hilite1">ubuntu</span>系统的分区，除非你安装的时候把/boot分出去了。）
<br />如果你不知道你把<span class="hilite1">ubuntu</span>装在第几个分区，可以在输入root (hd0, 时按Tab键来补全。
<br />（假设你把<span class="hilite1">ubuntu</span>装在第一块硬盘上）按了tab后，你将看到一些有关各个分区的信息。
<br />通常你可以通过分区的大小和格式看出你把<span class="hilite1">ubuntu</span>系统装在哪里了。
<br />setup (hdx) 通常情况下，是setup (hd0)。（多半你把<span class="hilite1">ubuntu</span>装在第一块硬盘上。）
<br />要注意的是，不要输入setup (hd0,0)。我曾经犯过这个错误。
<br />(如果你没把命令抄下来，凭记忆操作的话，可能会犯这种错误。）
<br />最後，用
<br />代码:
<br /><br />quit
<br /><br />退出grub,重啟系統。
<br />好了，总结一下用到的命令
<br />（建议你把下面的代码抄在纸上。如果你对(hdx,y)表示的含义还感觉模糊，最好把上面几段解释也抄下来。）
<br />代码:
<br /><br />sudo su
<br />grub
<br />root (hdx,y)
<br />setup(hdx)
<br />quit
<br /><br />很简单吧？关键只要理解grub中硬盘分区的表示法就行了。
<br /><br />2,使用<span class="hilite1">ubuntu</span>安裝cd恢复
<br /><span class="hilite1">ubuntu</span> desktop－cd可能用不起来。你可能需要7.10的alternative cd。
<br /><br />1. 用 <span class="hilite1">Ubuntu</span> 安装 CD 开机
<br />2. 在 "boot:" 提示号出现时, 键入 "rescue" 当作开机参数
<br />boot: rescue
<br />3. 顺着屏幕上的指示跟着作
<br />4，例如 假设 /boot 磁碟分区位在 /dev/hda
<br />代码:
<br /><br />#grub-install /dev/hda
<br /><br />下面是另外一种方法。firehare 写道:
<br />1. 启动系统到 <span class="hilite1">Ubuntu</span> 安装CD
<br />2. 沿着屏幕上的命令直到 (千万不要超过这一步)
<br />[!!] Fdisk disks
<br />3. 按 'Ctrl + Alt + F2'
<br />4. 按 'Enter' 进入终端
<br />5.
<br />~ # mkdir /<span class="hilite1">ubuntu</span><br />~ # fdisk -l /dev/discs/disc0/disc
<br />~ # mount &lt;你的<span class="hilite1">Ubuntu</span>根设备所在位置&gt; /<span class="hilite1">ubuntu</span>/
<br />~ # chroot /<span class="hilite1">ubuntu</span>/sh-2.05b#
<br /><br />6. 假设 /dev/hda1 是 /boot 分区的地址
<br />7. sh-2.05b# grub
<br />grub&gt; root (hd0,0)
<br />grub&gt; setup (hd0)
<br />grub&gt; quit
<br /><br />1. 用 <span class="hilite1">Ubuntu</span> 安装 CD 开机
<br />2. 在 "boot:" 提示号出现时, 键入 "rescue" 当作开机参数
<br />boot: rescue
<br />3. 顺着屏幕上的指示跟着作
<br />4，例如 假设 /boot 磁碟分区位在 /dev/hda
<br />代码:
<br />#grub-install /dev/hda
<br /><br />3,使用 grub for dos
<br />在沒有<span class="hilite1">ubuntu</span>安裝盤或livecd的情況下，你可以使用grub4dos重新安裝grub。
<br />你甚至可以用grub4dos代替grub來引導系統。
<br /><br />3.1使用grub4dos重新安裝grub
<br />下載http://www.<span class="hilite1">ubuntu</span>.org.cn/download/installformharddisk/grldr
<br />oneleaf 写道:将 grldr 复制到 C:\,编辑C:\BOOT.INI，加入一行:
<br />C:\GRLDR="GRUB"
<br />再手工输入启动命令
<br />例如:root (hd0,0)
<br />kernel /vmlinuz-2.6.10-5-686 root=/dev/hdb5 ro quiet splash
<br />initrd /initrd.img-2.6.10-5-686
<br />savedefault
<br />boot
<br />进入后，重新安装grub就好了。
<br />重新安裝grub:
<br />例如 假设 /boot 磁碟分区位在 /dev/hda
<br />代码:
<br /><br /># grub-install /dev/hda
<br /><br />3.2用grub4dos代替grub來引導系統
<br />yonsan 写道:
<br />(凭记忆写的,如有不完善请指正)
<br />如果你的系统现在正在使用grub引导方式,请在操作之前查看一下/boot/grub/menu.lst的内容,
<br />建议将/boot/grub/menu.lst拷贝一份以备用(将它拷到fat32分区中存放就可以)!进入window环境下
<br />1) 下载grub020p.zip并解压到C盘根目录下,打开C盘查看一下是否有以下文件
<br /><br />C:\boot (文件夹)
<br />C:\ChangeLog.txt
<br />C:\compile
<br />C:\COPYING
<br />C:\grldr
<br />C:\grub4lin
<br />C:\grub-0.95-patch1-startups
<br />C:\grub-0.95-patch2-findroot
<br />C:\grub-0.95-patch3-ntfs
<br />C:\grub-0.95-patch4-emulation
<br />C:\grub-0.95-patch5-splash
<br />C:\grub-0.95-patch6-scdrom
<br />C:\grub-0.95-patch7-bioscdrom
<br />C:\grub.exe
<br />C:\grub.pif
<br />C:\README.txt
<br />C:\robin.xpm.gz
<br />C:\scratchpad.txt
<br /><br />2) 修改C:\boot\grub\menu.lst ,用你刚才从linux系统中拷贝的menu.lst覆盖C:\boot\grub\menu.lst
<br /><br />3) 进入grub命令行方式 (出现grub引导菜单时按c键)
<br />&gt; root (hd0,0)
<br />&gt; setup (hd0)
<br /><br />4) 重启计算机
<br /><br />4.使用grub軟盤很簡單，只要用grub軟盤啟動机器就行了。
<br />如何制作grub軟盤？
<br />如果你沒做過grub軟盤，想在用安裝cd恢复的時候順便做一個，那就試試下面這個：
<br />youngong 写道:
<br />用安装CD启动电脑，输入rescue回车
<br />启动后执行"grub- install /dev/hda3"重新安装grub到<span class="hilite1">ubuntu</span>分区上
<br />再用"grub-install /dev/fd0"制作一张启动软盘
<br />(如果你打算将grub安装在MBR上可就更简单了，只需要grub-install /dev/hda)。
<br />再用刚才制作的软盘重启电脑，就可以进入<span class="hilite1">ubuntu</span> linux了。
<br />为了还原我原来的NT Loader启动linux的方式，再提取hda3分区的引导记录
<br />即“dd if=/dev/hda3 of=/linux.lnx bs=512 count=1",
<br />并将生成的linux.lnx文件复制到C区根目录下，
<br />修改boot.ini加入“c:\linux.lnx=<span class="hilite1">Ubuntu</span> linux 5.04"，
<br />就可以在硬盘引导时选择启动<span class="hilite1">ubuntu</span>了。
<br />其实整个过程中制作引导软盘只起了个过渡作用，但同时也方便以后维护系统。
<br />zhan 写道:
<br />今天重装了windows系统,将原来的xp装为2003
<br />装完后用<span class="hilite1">ubuntu</span>的安装盘grub-install /dev/hda 将linux恢复了
<br />但是启动时只有一个winxp的选项,进入时说不能识别文件系统,不能启动
<br />然后出现一个GRUB 就停住了，不过linux系统是还可以用.
<br />各位大侠有没有什么好办法,我不想再重装了!!
<br />启动win时的显示见下:
<br />Booting 'microsoft windows xp professional'
<br />root (hd0,0)
<br />Filesystem type unkown ,partition type 0x7
<br />savedefault
<br />makeactive
<br />chainloader+1
<br />GRUB
<br />到这里就不动了,按键基本都没用,不过,ctrl+alt+delete能重启
<br />yonsan 写道:
<br />用以下方式引导windows
<br />代码:
<br /><br /># Windows
<br />title Windows
<br />rootnoverify (hd0,0)
<br />chainloader +1
<br /><br />-------------------------------------------------------------------------------------------------------
<br /><br />重装Windows后 无法进入<span class="hilite1">ubuntu</span> 的修复方法
<br />如果你的电脑是Win和<span class="hilite1">Ubuntu</span>双系统的，可能会遇到这样的问题。
<br />就是重装Win之后将无法进入<span class="hilite1">Ubuntu</span>了。一般情况下遇到这样的问题，我们有两种方法解决！
<br /><br />最简单的方法：
<br />1.利用另外的一个LiveCD盘进入后把所有的盘都挂载。
<br />2.拷贝原<span class="hilite1">Ubuntu</span>下的/boot/grub到Win的C盘。
<br />3.修改Win的C盘里的boot.ini文件。它可能隐藏和只读 需要自己改下属性！
<br />4.在这个文件最后加入一句C:\grldr=<span class="hilite1">ubuntu</span><br />5.重启选择<span class="hilite1">Ubuntu</span>。
<br /><br />第二种方法：
<br />注意此种方法只能在重装WIN之前到<span class="hilite1">Ubuntu</span>下操作！！！
<br />首先确定你的grub正常，并能启动linux
<br />然后启动到<span class="hilite1">Ubuntu</span>如果你的是IDE硬盘
<br />请运行：
<br />sudo dd if=/dev/hda of=/media/linux.lnx bs=512 count=1
<br /><br />如果你硬盘的被识别为sda ，请运行
<br />sudo dd if=/dev/sda of=/media/linux.lnx bs=512 count=1
<br /><br />然后你可以到/media找到linux.lnx这个文件
<br />将它拷贝到你的win根目录，一般是C：\然后重启Win，修改根目录下的boot.ini 文件。
<br />在这个文件最后增加：
<br />C:\linux.lnx=”linux
<br />OK，重启，选择<span class="hilite1">Ubuntu</span>吧。
<br />注意：你需要将这个文件备份，可以备份到网络硬盘或者U盘内。
<br />这样你重装Win之后，只需要将这个文件拷贝到Win的根目录，修改boot.ini 就可以了！
<br /><br />总结：相比较而言，第一种方法更简单一点，但是我觉得第二种方法更一劳永逸。
<br />当然，你可以选择利用重装grub来恢复对<span class="hilite1">Ubuntu</span>的引导。但是我不觉得那对于新手会简单！
<br />感谢提供这两种方法的sun391和enjoyforfun
<br />------------------以上内容转自某个网页------------------------------------
<br />补充： 用GhostXP的安装盘安装Windows 可能不存在这个问题（至少本人用深度白金珍藏版5.7.1是这样的）
<br /><br />-------------------------------------------------------------------------------------------------------
<br /><br />当我们的脆弱的Windows定期瘫痪，无法修复只能重新安装的尴尬时刻，我们发现“霸道”的Windows 在安装时丝毫没有顾及在硬盘的MBR上还存在操作系统的引导程序（grub），直接删除，只写入Windows的引导信息。
<br /><br />不管微软这样是不是有意而为，这都看出Windows的陋习和微软的强盗行径。我们怎么办，放弃Windows？但是我们还要我们心爱的游戏，反正Windows已经是我硬盘上的一个因为游戏还存在的附属系统，我们忍了。
<br /><br />发扬Linux人的DIY精神，我们自己动手找回丢失的Linux引导程序。
<br /><br />1，使用<span class="hilite1">Ubuntu</span> live关盘引导进入 <span class="hilite1">Ubuntu</span> live 模式
<br /><br />2，在<span class="hilite1">Ubuntu</span>中运行终端，执行下列命令：
<br /><br />$sudo grub
<br /><br />其实，grub不仅只在我们引导时候出现在我们眼前，我们平时也可以直接运行grub命令进入模拟grub引导程序。
<br /><br />3，之后，我们在grub 命令行模式下接着执行
<br /><br />root (hdx,y)
<br /><br />注意：其中x为硬盘号，数字 “ 0 ”指我们机器上的第一块硬盘，grub的排列顺序是从 “ 0
”开始的。同理，如果你的系统在第二个硬盘上则是1，依次类推。另外，其中的“ y ”表示前面所指硬盘的 /boot
所在分区号，如果实在不知道，后面信息怎么填，你可以在输入逗号后按Tab键，这样可列出硬盘的分区信息。
<br /><br />4，安装 grub ，执行命令：
<br /><br />setup (hdx)
<br /><br />setup (hdx)就是把GRUB写到"x"硬盘的MBR上。如果成功会有一个successful......
<br /><br />5，安成安装后，退出 grub 。
<br /><br />quit
<br /><br />6，重启机器，重新引导Linux。
<br /><br />$sudo reboot
<br /><br />备注：其实，当我们安装完毕grub之后，还需要检查 grub 的配置文件信息是否正确，方法是在 <span class="hilite1">Ubuntu</span> live 模式下利用 mount 命令加载原来<span class="hilite1">ubuntu</span> 的分区，在原 /boot 目录下的 grub/menu1.st 文件中的信息。</span><br /><img src ="http://www.cppblog.com/deercoder/aggbug/109824.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/deercoder/" target="_blank">刘畅</a> 2010-03-16 14:46 <a href="http://www.cppblog.com/deercoder/articles/109824.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>/sys/module 模块信息与/proc文件----------如何获取模块的各个信息及说明[zz]</title><link>http://www.cppblog.com/deercoder/articles/109274.html</link><dc:creator>刘畅</dc:creator><author>刘畅</author><pubDate>Tue, 09 Mar 2010 05:56:00 GMT</pubDate><guid>http://www.cppblog.com/deercoder/articles/109274.html</guid><wfw:comment>http://www.cppblog.com/deercoder/comments/109274.html</wfw:comment><comments>http://www.cppblog.com/deercoder/articles/109274.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/deercoder/comments/commentRss/109274.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/deercoder/services/trackbacks/109274.html</trackback:ping><description><![CDATA[
		<font style="font-family: 楷体; font-weight: bold;" size="2">在编译模块的时候，如果模块加载成功。在/sys/module目录中又模块的信息。<br />/proc/modules包含所有模块的信息。<br /><br />/sys/module<br />/proc/modules<br />/sys/module
是一个 sysfs 目录层次, 包含当前加载模块的信息. /proc/moudles 是旧式的, 那种信息的单个文件版本.
其中的条目包含了模块名, 每个模块占用的内存数量, 以及使用计数. 另外的字串追加到每行的末尾来指定标志, 对这个模块当前是活动的.<br />wugang@wugang-desktop:~$ cat /proc/modules <br />book 3200 0 - Live 0xe042e000<br />hello 2560 0 - Live 0xe02c3000<br />i915 32512 2 - Live 0xe0417000<br />其中 book(模块名)   3200是模块占用内存的大小。   0是模块加载计数   Live表示模块可用<br />0xe042e000 肯定是模块的起始地址。<br /><br /><br />在/sys/modules模块的信息(新版)<br />来自内核源码目录的目标文件, 描述一个模块为之建立的环境.<br />wugang@wugang-desktop:~$ cd /sys/module/book<br />wugang@wugang-desktop:/sys/module/book$ ls<br />holders  initstate  notes  parameters  refcnt  sections  srcversion<br /><br />holders  持有人，是写本模块的人。但是目录为空。<br />initstate  记录模块活动<br />notes   暂且没有查到，好像是日记，有个隐藏文件，可能就是记录本模块的信息 ＊<br />parameters  使用的变量<br />refcnt   模块的加载计数<br />wugang@wugang-desktop:/sys/module/book/sections$ ls<br />__param  __versions<br />其中sections目录中， __param是参数起始地址。<br />而sections目录中，__versions   好像和版本有关 ＊<br />这两个参数和地址有关。<br />srcversion    BDF6D850ED985425407E440     模块版本号 像模块的ID一样<br /><br /><br />打开/proc/kallsyms目录下文件都是0字节，且打开为空白信息。<br />但是用cat命令，可以查看出里面的信息。<br />最后翻书，操作系统运行时，进程及内核信息(cpu,硬盘分区，内存信息)存放在这里。<br />/proc目录为伪文件系统，proc并不是真正的文件系统，它存在于内存中。<br />而且/sys也是存在内存中。<br />-r--------   1 root       root       528420864 2008-07-17 21:25 kcore<br />我机子上的，/proc文件目录大小几乎全部集中在那个文件中。<br />且无法用命令查看其中的信息.<br /><br />/proc
文件系统是一种特殊的、由程序创建的文件系统，内核使用它向外界输出信息。/proc
下面的每个文件都绑定于一个内核函数，这个函数在文件被读取时，动态地生成文件的"内容",例如，/proc/modules
列出的是当前载入模块的列表。这样可以动态访问其中进程和内核信息。<br /><br />Linux系统对/proc的使用很频繁。现代Linux系统中的很
多工具都是通过 /proc 来获取它们的信息，例如 ps、top 和 uptime。有些设备驱动程序也通过 /proc
输出信息，你的驱动程序当然也可以这么做。因为 /proc 文件系统是动态的，所以驱动程序模块可以在任何时候添加或删除其中的文件项。<br /><br />特征完全的 /proc 文件项相当复杂；在所有的这些特征当中，有一点要指出的是，这些 /proc 文件不仅可以用于读出数据，也可以用于写入数据。不过，大多数时候，/proc 文件项是只读文件。<br /><br /><br />注：＊表示我不确定的问题，有问题请参考  module.h源代码。</font>
<img src ="http://www.cppblog.com/deercoder/aggbug/109274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/deercoder/" target="_blank">刘畅</a> 2010-03-09 13:56 <a href="http://www.cppblog.com/deercoder/articles/109274.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux下面如何的proc文件--------编写Linux资源管理器</title><link>http://www.cppblog.com/deercoder/articles/109231.html</link><dc:creator>刘畅</dc:creator><author>刘畅</author><pubDate>Mon, 08 Mar 2010 14:40:00 GMT</pubDate><guid>http://www.cppblog.com/deercoder/articles/109231.html</guid><wfw:comment>http://www.cppblog.com/deercoder/comments/109231.html</wfw:comment><comments>http://www.cppblog.com/deercoder/articles/109231.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/deercoder/comments/commentRss/109231.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/deercoder/services/trackbacks/109231.html</trackback:ping><description><![CDATA[在Linux下面，编写类似的资源管理器，需要读取proc下面的很多文件，为此，搜寻了下面的资料，以利于学习和保存！<br />
总之，可以使用命令来读取cat /proc/pid/stat(读取进程信息…………)<br /><br />
=============================================================================<br /><p>/<font style="background-color: rgb(255, 255, 255);">proc</font> 是一个伪文件系统, 被用作内核数据结构的接口, 而不仅仅是解释说明 /dev/kmem. /<font style="background-color: rgb(255, 255, 255);">proc</font>里的大多数文件都是只读的, 但也可以通过写一些文件来改变内核变量. </p><p>下面对整个 /<font style="background-color: rgb(255, 255, 255);">proc</font> 目录作一个大略的介绍. 
</p><p></p><dl compact="compact"><dt><i>[number]</i></dt><dd>在 /<font style="background-color: rgb(255, 255, 255);">proc</font> 目录里, 每个正在运行的进程都有一个以该进程 ID 命名的子目录, 其下包括如下的目录和伪文件. 
<dl compact="compact"><dt><br /></dt><dd><dl compact="compact"><dt><i>cmdline</i></dt><dd>该文件保存了进程的完整命令行. 如果该进程已经被交换出内存, 或者该进程已经僵死, 那么就没有任何东西在该文件里, 这时候对该文件的读操作将返回零个字符. 该文件以空字符 null 而不是换行符作为结束标志. 
</dd><dt><i>cwd</i></dt><dd>一个符号连接, 指向进程当前的工作目录. 例如, 要找出进程 20 的 cwd, 你可以: <br />cd /<font style="background-color: rgb(255, 255, 255);">proc</font>/20/cwd; /bin/pwd
</dd></dl><p>请注意 pwd 命令通常是 shell 内置的, 在这样的情况下可能工作得不是很好. 
</p><p></p><dl compact="compact"><dt><i>environ</i></dt><dd>该文件保存进程的环境变量, 各项之间以空字符分隔, 结尾也可能是一个空字符. 因此, 如果要输出进程 1 的环境变量, 你应该: <br />(cat /<font style="background-color: rgb(255, 255, 255);">proc</font>/1/environ; echo) | tr ";\000"; ";\n";
</dd></dl><p>(至于为什么想要这么做, 请参阅 <i><font color="#0000ff">lilo</font></i>(8).) 
</p><dl compact="compact"><dt><i>exe</i></dt><dd>也是一个符号连接, 指向被执行的二进制代码. 
<p>在 Linux 2.0 或者更早的版本下, 对 exe 特殊文件的 <i><font color="#0000ff">readlink</font>(2)</i> 返回一个如下<font style="background-color: rgb(255, 255, 255);">格式</font>的字符串: 
</p><p>[设备号]:节点号 
</p><p>举个例子, [0301]:1502 就是某设备的 1502 节点, 该设备的主设备号为 03 (如 IDE, MFM 等驱动器), 从设备号为 01 (第一个驱动器的第一分区). 
</p><p>而在 Linux 2.2 下, <i><font color="#0000ff">readlink</font>(2) </i>则给出命令的实际路径名. 
</p><p>另外, 该符号连接也可以正常析引用(试图打开 exe 文件实际上将打开一个可执行文件). 你甚至可以键入 <em>/</em><font style="background-color: rgb(255, 255, 255);"><font style="background-color: rgb(255, 255, 255);">proc</font><em>/[number]/exe</em> 来运行 [number] 进程的副本. </font></p><p>带 -inum 选项的 <i><font color="#0000ff">find</font>(1)</i> 命令可以定位该文件. </p></dd><dt><i>fd</i></dt><dd>进程所打开的每个文件都有一个符号连接在该子目录里, 以文件描述符命名, 这个名字实际上是指向真正的文件的符号连接，（和 exe 记录一样）．例如, 0 是标准输入, 1 是标准输出, 2 是标准错误, 等等. 
<p>程序有时可能想要读取一个文件却不想要标准输入，或者想写到一个文件却不想将输出送到标准输出去，那么就可以很有效地用如下的办法骗过(假定 -i 是输入文件的标志, 而 -o 是输出文件的标志): <br /><tt>foobar -i /<font style="background-color: rgb(255, 255, 255);">proc</font>/self/fd/0 -o /<font style="background-color: rgb(255, 255, 255);">proc</font>/self/fd/1 ...</tt><br />这样就是一个能运转的过滤器. 请注意该方法不能用来在文件里搜索, 这是因为 fd 目录里的文件是不可搜索的. 
</p><p>在 UNIX 类的系统下, /<font style="background-color: rgb(255, 255, 255);">proc</font>/self/fd/N 基本上就与 /dev/fd/N 相同. 实际上, 大多数的 Linux MAKEDEV 脚本都将 /dev/fd 符号连接到 [..]/<font style="background-color: rgb(255, 255, 255);">proc</font>/self/fd 上. </p></dd><dt><i><font style="background-color: rgb(255, 255, 255);">maps</font></i></dt><dd>该文件包含当前的映象内存区及他们的访问许可. 
<p><font style="background-color: rgb(255, 255, 255);">格式</font>如下: address           perms offset   dev   inode
00000000-0002f000 r-x-- 00000400 03:03 1401
0002f000-00032000 rwx-p 0002f400 03:03 1401
00032000-0005b000 rwx-p 00000000 00:00 0
60000000-60098000 rwx-p 00000400 03:03 215
60098000-600c7000 rwx-p 00000000 00:00 0
bfffa000-c0000000 rwx-p 00000000 00:00 0
</p></dd></dl><p>address 是进程所占据的地址空间, perms 是权限集: r = read
w = write
x = execute
s = shared
p = private (copy on write)

</p><p>offset 是文件或者别的什么的偏移量, dev 是设备号(主设备号:从设备号), 而 inode 则是设备的节点号. 0 表明没有节点与内存相对应, 就象 bss 的情形. 
</p><p>在 Linux 2.2 下还增加了一个域给可用的路径名. 
</p><dl compact="compact"><dt><i>mem</i></dt><dd>该文件并不是 mem (1:1) 设备, 尽管它们有相同的设备号. /dev/mem 设备是做任何地址转换之前的物理内存, 而这里的 mem 文件是访问它的进程的内存.目前这个 mem 还不能 <i><font color="#0000ff">mmap</font>(2)</i> （内存映射）出去，而且可能一直要等到内核中增加了一个通用的 <i><font color="#0000ff">mmap</font>(2)</i> 以后才能实现． (也许在你读本手册页时这一切已经发生了) 
</dd><dt><i>mmap</i></dt><dd><i><font color="#0000ff">mmap</font>(2)</i> 做的 <font style="background-color: rgb(255, 255, 255);">maps</font> 映射目录，是和 exe, fd/* 等类似的符号连接. 请注意 <font style="background-color: rgb(255, 255, 255);">maps</font> 包含了比 /<font style="background-color: rgb(255, 255, 255);">proc</font>/*/mmap 更多的信息, 所以应该废弃 mmap. 
<p>";0"; 通常指 libc.so.4. 
</p><p>在 linux 内核 1.1.40 里, <i>/<font style="background-color: rgb(255, 255, 255);">proc</font>/*/mmap</i> 被取消了. (现在是 真的 废弃不用了!) </p></dd><dt><i>root</i></dt><dd>依靠系统调用 <i><font color="#0000ff">chroot</font>(2), </i>unix 和 linux 可以让每个进程有各自的文件系统根目录. 由 <i><font color="#0000ff">chroot</font>(2)</i> 系统调用设置．根指向文件系统的根，性质就象 exe, fd/* 等一样． 
</dd><dt><i>stat</i></dt><dd>进程状态信息, 被命令 <i><font color="#0000ff">ps</font>(1)</i> 使用. 
<p>现将该文件里各域, 以及他们的 <i><font color="#0000ff">scanf</font>(3)</i><font style="background-color: rgb(255, 255, 255);">格式</font>说明符, 按顺序分述如下: 
</p><dl compact="compact"><dt><br /></dt><dd><dl compact="compact"><dt><i>pid</i> %d 
</dt><dd>进程标识． 
</dd><dt><i>comm</i> %s 
</dt><dd>可执行文件的文件名, 包括路径. 该文件是否可见取决于该文件是否已被交换出内存. 
</dd><dt><i>state</i> %c 
</dt><dd>";RSDZT"; 中的一个, R 是正在运行, S 是在可中断的就绪态中睡眠, D 是在不可中断的等待或交换态中睡眠, Z 是僵死, T 是被跟踪或被停止(由于收到信号). 
</dd><dt><i>ppid</i> %d 
</dt><dd>父进程 PID. 
</dd><dt><i>pgrp</i> %d 
</dt><dd>进程的进程组 ID. 
</dd><dt><i>session</i> %d 
</dt><dd>进程的会话 ID. 
</dd><dt><i>tty</i> %d 
</dt><dd>进程所使用终端. 
</dd><dt><i>tpgid</i> %d 
</dt><dd>当前拥有该进程所连接终端的进程所在的进程组 ID. 
</dd><dt><i>flags</i> %u 
</dt><dd>进程标志. 目前每个标志都设了数学位, 所以输出里就不包括该位. crt0.s 检查数学仿真这可能是一个臭虫, 因为不是每个进程都是用 c 编译的程序. 数学位应该是十进制的 4, 而跟踪位应该是十进制的 10. 
</dd><dt><i>minflt</i> %u 
</dt><dd>进程所导致的小错误（minor faults）数目, 这样的小错误（minor faults）不需要从磁盘重新载入一个内存页. 
</dd><dt><i>cminflt</i> %u 
</dt><dd>进程及其子进程所导致的小错误（minor faults）数目. 
</dd><dt><i>majflt</i> %u 
</dt><dd>进程所导致的大错误（major faults）数目, 这样的大错误（major faults）需要重新载入内存页. 
</dd><dt><i>cmajflt</i> %u 
</dt><dd>进程及其子进程所导致的大错误（major faults）数目. 
</dd><dt><i>utime</i> %d 
</dt><dd>进程被调度进用户态的时间(以 jiffy 为单位, 1 jiffy=1/100 秒，另外不同硬件体系略有不同). 
</dd><dt><i>stime</i> %d 
</dt><dd>进程被调度进内核态的时间, 以 jiffy 为单位. 
</dd><dt><i>cutime</i> %d 
</dt><dd>进程及其子进程被调度进用户态的时间, 以 jiffy 为单位. 
</dd><dt><i>cstime</i> %d 
</dt><dd>进程及其子进程被调度进内核态的时间, 以 jiffy 为单位. 
</dd><dt><i>counter</i> %d 
</dt><dd>如果进程不是当前正在运行的进程, 就是进程在下个时间片当前可以拥有的最大时间, 以 jiffy 为单位. 如果进程是当前正在运行的进程, 就是当前时间片中所剩下 jiffy 数目. 
</dd><dt><i>priority</i> %d 
</dt><dd>标准优先数只再加上 15, 在内核里该值总是正的. 
</dd><dt><i>timeout</i> %u 
</dt><dd>当前至进程的下一次间歇时间, 以 jiffy 为单位. 
</dd><dt><i>itrealvalue</i> %u 
</dt><dd>由于计时间隔导致的下一个 SIGALRM 发送进程的时延，以 jiffy 为单位. 
</dd><dt><i>starttime</i> %d 
</dt><dd>进程自系统启动以来的开始时间, 以 jiffy 为单位. 
</dd><dt><i>vsize</i> %u 
</dt><dd>虚拟内存大小. 
</dd><dt><i>rss</i> %u 
</dt><dd>Resident Set Size（驻留大小）: 进程所占用的真实内存大小, 以页为单位, 为便于管理而减去了 3. rss 只包括正文, 数据以及堆栈的空间, 但不包括尚未要求装入内存的或已被交换出去的. 
</dd><dt><i>rlim</i> %u 
</dt><dd>当前进程的 rss 限制, 以字节为单位, 通常为 2,147,483,647. 
</dd><dt><i>startcode</i> %u 
</dt><dd>正文部分地址下限. 
</dd><dt><i>endcode</i> %u 
</dt><dd>正文部分地址上限. 
</dd><dt><i>startstack</i> %u 
</dt><dd>堆栈开始地址. 
</dd><dt><i>kstkesp</i> %u 
</dt><dd>esp(32 位堆栈指针) 的当前值, 与在进程的内核堆栈页得到的一致. 
</dd><dt><i>kstkeip</i> %u 
</dt><dd>EIP(32 位指令指针)的当前值. 
</dd><dt><i>signal</i> %d 
</dt><dd>待处理信号的 bitmap(通常为 0). 
</dd><dt><i>blocked</i> %d 
</dt><dd>被阻塞信号的 bitmap(对 shell 通常是 0, 2)． 
</dd><dt><i>sigignore</i> %d 
</dt><dd>被忽略信号的 bitmap. 
</dd><dt><i>sigcatch</i> %d 
</dt><dd>被俘获信号的 bitmap. 
</dd><dt><i>wchan</i> %u 
</dt><dd>进程在其中等待的通道, 实际是一个系统调用的地址. 如果你需要文本<font style="background-color: rgb(255, 255, 255);">格式</font>的, 也可以在名字列表中找到. (如果有最新版本的 /etc/psdatabase, 你可以在 <i>ps -l</i> 的结果中的 WCHAN 域看到) </dd></dl></dd></dl></dd></dl></dd></dl></dd><dt><i>cpuinfo </i></dt><dd>保存了CPU 以及体系架构依赖条目的列表. 对于不同的系统架构有不同的列表, 共有的两项是 <i>cpu</i> 和 <i>BogoMIPS</i>, <i>cpu</i> 可能是当前在用的 CPU, 而 <i>BogoMIPS</i> 则是内核初始化时计算出的一个系统常数. 
</dd><dt><i>devices</i></dt><dd>主设备号及设备组的列表, 文本<font style="background-color: rgb(255, 255, 255);">格式</font>. MAKEDEV 脚本使用该文件来维持内核的一致性. 
</dd><dt><i>dma</i></dt><dd>一个列表, 指出正在使用的<i>ISA</i> DMA (直接内存访问)通道. 
</dd><dt><i>filesystems</i></dt><dd>以文本<font style="background-color: rgb(255, 255, 255);">格式</font>列出了被编译进内核的文件系统. 当没有给 <i><font color="#0000ff">mount</font>(1)</i> 指明哪个文件系统的时候, <i><font color="#0000ff">mount</font>(1)</i> 就依靠该文件遍历不同的文件系统. 
</dd><dt><i>interrupts</i></dt><dd>该文件以 ASCII <font style="background-color: rgb(255, 255, 255);">格式</font>记录了（至少是在 i386 体系上的）每次 IRQ 的中断数目. 
</dd><dt><i>ioports</i></dt><dd>该文件列出了当前在用的已注册 I/O 端口范围. 
</dd><dt><i>kcore</i></dt><dd>该伪文件以 core 文件<font style="background-color: rgb(255, 255, 255);">格式</font>给出了系统的物理内存映象, 再利用未卸载的内核 (/usr/src/linux/tools/zSystem), 我们就可以用 GDB 查探当前内核的任意数据结构. 
<p>该文件的总长度是物理内存 (RAM) 的大小再加上 4KB. </p></dd><dt><i>kmsg</i></dt><dd>可以用该文件取代系统调用 <i><font color="#0000ff">syslog</font>(2)</i> 来记录内核信息. 但是读该文件需要超级用户权限, 并且一次只能有一个进程可以读该文件, 因而如果一个使用了 <i><font color="#0000ff">syslog</font>(2)</i> 系统调用功能来记录内核信息的系统日志进程正在运行的话, 别的进程就不能再去读该伪文件了. 
<p>该文件的内容可以用 <i><font color="#0000ff">dmesg</font>(8)</i> 来察看. </p></dd><dt><i>ksyms</i></dt><dd>该文件保存了内核输出的</dd></dl><br /><img src ="http://www.cppblog.com/deercoder/aggbug/109231.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/deercoder/" target="_blank">刘畅</a> 2010-03-08 22:40 <a href="http://www.cppblog.com/deercoder/articles/109231.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>