﻿<?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++博客-Dark Angle-随笔分类-Linux</title><link>http://www.cppblog.com/niewenlong/category/4232.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 12 Jul 2021 16:40:46 GMT</lastBuildDate><pubDate>Mon, 12 Jul 2021 16:40:46 GMT</pubDate><ttl>60</ttl><item><title>Linux下删除大量文件</title><link>http://www.cppblog.com/niewenlong/archive/2021/07/11/217736.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sun, 11 Jul 2021 07:07:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2021/07/11/217736.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/217736.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2021/07/11/217736.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/217736.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/217736.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Linux下删除大量文件主要参考了http://www.slashroot.in/which-is-the-fastest-method-to-delete-files-in-linux首先建立50万个文件➜  test   for i in $(seq 1 500000);do echo text &gt;&gt;$i.txt;done                 1. &nbsp; rm➜...&nbsp;&nbsp;<a href='http://www.cppblog.com/niewenlong/archive/2021/07/11/217736.html'>阅读全文</a><img src ="http://www.cppblog.com/niewenlong/aggbug/217736.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2021-07-11 15:07 <a href="http://www.cppblog.com/niewenlong/archive/2021/07/11/217736.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于 find grep xargs 命令总结</title><link>http://www.cppblog.com/niewenlong/archive/2017/09/26/215267.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Tue, 26 Sep 2017 09:22:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2017/09/26/215267.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/215267.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2017/09/26/215267.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/215267.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/215267.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial;">1.定义&amp;区别：</p>
<p style="color: #333333; font-family: Arial;">(1)find命令是根据文件的属性进行查找，如文件名，文件大小，所有者，所属组，是否为空，访问时间，修改时间等。&nbsp;</p>
<p style="color: #333333; font-family: Arial;">(2)grep是根据文件的内容进行查找，会对文件的每一行按照给定的模式(patter)进行匹配查找。&nbsp;</p>
<p style="color: #333333; font-family: Arial;">(3)find命令把匹配到的文件传递给xargs命令，而xargs命令每次只获取一部分文 件而不是全部，不&nbsp;像-exec选项那样。这样它可以先处理最先获取的一部分文件，然后是下一批，并如此继续下去。&nbsp;在有些系统中，使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程，并非将匹配&nbsp;到的文件全部作为参数一次执行；这样在有些情况下就会出现进程过多，系统性能下降的问题，&nbsp;因而效率不高；而使用xargs命令则只有一个进程。另外，在使用xargs命令时，究竟是一次获取所有的参数，还&nbsp;是分批取得参数，以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。</p>
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">2.find用法：</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">　　　(1)find /tmp -size +10000c -and -mtime +2 　　#在/tmp目录下查找大于10000字节并在最后2分钟内修改的文件</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp;　　 (2)find / -user fred -or -user george 　　#在/目录下查找用户是fred或者george的文件文件</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp;　　 (3)find /tmp ! -user panda　　#在/tmp目录中查找所有不属于panda用户的文件</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp;</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">3.grep用法：</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">　　(1)grep 'test' d*　　#显示所有以d开头的文件中包含 test的行</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">　　(2)grep &#8216;test&#8217; aa bb cc 　　 #显示在aa，bb，cc文件中包含test的行</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">　　(3)grep &#8216;[a-z]\{5\}&#8217; aa 　　#显示所有包含每行字符串至少有5个连续小写字符的字符串的行</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">　　(4)grep magic /usr/src　　#显示/usr/src目录下的文件(不含子目录)包含magic的行</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">　　(5)grep -r magic /usr/src　　#显示/usr/src目录下的文件(包含子目录)包含magic的行</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">　　(6)grep -w pattern files ：只匹配整个单词，而不是字符串的一部分(如匹配&#8217;magic&#8217;，而不是&#8217;magical&#8217;)，</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; (7)grep 'hello' $(find . -name *.c) &nbsp;-i</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; (8)grep 'hello' ./yuhaojin/*.c -i -n</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp;&nbsp;</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">4.find &amp; grep 使用方法</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; (1).从根目录开始查找所有扩展名为.log的文本文件，并找出包含&#8221;ERROR&#8221;的行</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;find / -type f -name "*.log" | xargs grep "ERROR"</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; (2).例子：从当前目录开始查找所有扩展名为.in的文本文件，并找出包含&#8221;thermcontact&#8221;的行</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; find . -name "*.in" | xargs grep "thermcontact"</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;&nbsp;</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">5.find &amp; xargs使用方法</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; (1).find . -type f -print | xargs file&nbsp;</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;查找系统中的每一个普通文件，然后使用xargs命令来测试它们分别属于哪类文件</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; (2).find / -name &#8220;core&#8221; -print | xargs echo &#8220;&#8221; &gt;/tmp/core.log&nbsp;</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;在整个系统中查找内存信息转储文件(core dump) ，然后把结果保存到/tmp/core.log 文件中：</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; (3).find . -type f -print | xargs grep &#8220;hostname&#8221;&nbsp;</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;用grep命令在所有的普通文件中搜索hostname这个词</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; (4).find ./ -mtime +3 -print|xargs rm -f &#8211;r&nbsp;</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;删除3天以前的所有东西 （find . -ctime +3 -exec rm -rf {} ;）</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; (5)find ./ -size 0 | xargs rm -f &amp;&nbsp;</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;删除文件大小为零的文件</span><br style="color: #333333; font-family: Arial;" />
<span style="color: #333333; font-family: Arial; background-color: #ffffff;">&nbsp; (6)find命令配合使用exec和xargs可以使用户对所匹配到的文件执行几乎所有的命令。</span>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
<div><span style="color: #333333; font-family: Arial; background-color: #ffffff;"><br />
</span></div>
<div><span style="color: #333333; font-family: Arial; background-color: #ffffff;">exp:</span></div>
<div>
<p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: #ffffff;"><span style="font-variant-ligatures: no-common-ligatures">find /opt/public/upload/images/ -name *._*.* |xargs rm -f</span></p>
</div><img src ="http://www.cppblog.com/niewenlong/aggbug/215267.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2017-09-26 17:22 <a href="http://www.cppblog.com/niewenlong/archive/2017/09/26/215267.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>debian下安装denyhosts防止ssh暴力破解配置 </title><link>http://www.cppblog.com/niewenlong/archive/2016/07/27/214055.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Wed, 27 Jul 2016 05:00:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2016/07/27/214055.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/214055.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2016/07/27/214055.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/214055.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/214055.html</trackback:ping><description><![CDATA[<p>denyhosts是一个非常好用的防SSH暴力破解的软件，感觉比fail2ban简单有效。<br />
debian下安装denyhosts非常简单。直接apt安装即可。(debian强大的地方就是什么鸟东西他都可以apt-get安装)<br />
屏蔽的IP会记录在/etc/hosts.deny这个文件里面，可随时查看。</p>
<p>1、清除SSH登录记录，防止装完屏蔽自己。</p>
<p>echo "" &gt; /var/log/auth.log</p>
<p>2、安装denyhosts</p>
<p>apt-get install denyhosts</p>
<p><br />
2、编辑Denyhosts配置文件vi /etc/denyhosts.conf</p>
<p>SECURE_LOG = /var/log/auth.log&nbsp; #SSH日志<br />
PURGE_DENY = 30m&nbsp; #过多久后清除已阻止IP<br />
HOSTS_DENY = /etc/hosts.deny&nbsp; #将阻止IP写入到hosts.deny<br />
BLOCK_SERVICE&nbsp; = sshd&nbsp; #禁止的服务名</p>
<p>DENY_THRESHOLD_INVALID = 1&nbsp; #允许无效用户登录失败的次数<br />
DENY_THRESHOLD_VALID = 3&nbsp; #允许普通用户登录失败的次数<br />
DENY_THRESHOLD_ROOT = 3&nbsp; #允许root登录失败的次数<br />
DENY_THRESHOLD_RESTRICTED = 1&nbsp; #设定 deny host 写入到该资料夹<br />
WORK_DIR = /var/lib/denyhosts&nbsp; #将deny的host或ip纪录到Work_dir中</p>
<p>SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES 
#如果为YES，所有在$WORK_DIR/allowed-host时面的IP地址将会被认为是可疑的，如果设置为NO,所有在allowd-
hosts试图登陆的结果，将不会发送警告邮件！所有不在$WORK_DIR/allowed-host时面的IP地址将会发送警告！ <br />
HOSTNAME_LOOKUP=NO&nbsp; #是否做域名反解,是否将IP地址解析为主机名。 <br />
LOCK_FILE = /var/run/denyhosts.pid&nbsp; #定义PID文件的位置，确保同时只有一个Denyhost进程在运行</p>
<p>&nbsp;############ THESE SETTINGS ARE OPTIONAL ############这里的设置是可选的</p>
<p>ADMIN_EMAIL = root@localhost&nbsp; #当有人试图登录发送邮件。前提是，本机一定要可以发送邮件才行！ <br />
SMTP_HOST = localhost&nbsp; #指定smtp服务器 <br />
SMTP_PORT = 25&nbsp; #指定SMTP端口号 <br />
SMTP_FROM = DenyHosts&nbsp;&nbsp; #指定发件人 <br />
SMTP_SUBJECT = DenyHosts Report&nbsp; #指定邮件主题 <br />
AGE_RESET_VALID=5d&nbsp; #多长时间后，用户登录失败的次数被置为0，这里是指在/etc/passwd里面定义的用户，如果不设置，永远都不会置0</p>
<p>AGE_RESET_ROOT=25d&nbsp; #多长时间后，root用户登录失败的次数置为0，如果不设置，永远都不会置0 <br />
AGE_RESET_RESTRICTED=25d&nbsp; #在$WORK_DIR/hosts-restricted时面定义的用户，多长时间失败次数计数器被置为0 <br />
AGE_RESET_INVALID=10d&nbsp;&nbsp; #无效用户(不在/etc/passwd里面的用户)的失败次数计数器，多长时间被置为0 <br />
RESET_ON_SUCCESS = yes&nbsp; #当某个IP使用某个用户登录成功后，该IP对应的用户失败次数将会被置为0</p>
<p>DAEMON_LOG = /var/log/denyhosts&nbsp; #当denyhost运行在守护进程模式的时候，日志文件存储的位置 <br />
DAEMON_SLEEP = 30s&nbsp;&nbsp; #轮询查看SSHD日志的间隔 <br />
DAEMON_PURGE = 1h&nbsp;&nbsp;&nbsp; #多长时间清空$HOSTS_DENY中的IP地址，如果PURGE_DENY为空，这个设置将无效 <br />
其实默认配置我觉得足够了，修改下root的失败次数，默认的是1，一般修改成3-5就行了，DENY_THRESHOLD_ROOT = 3<br />
HOSTNAME_LOOKUP=NO 关闭反向解析，PURGE_DENY = 30m阻止30分钟！<br />
3、重启/etc/init.d/denyhosts restart<br />
4.设置开机自启动<br />
# vi /etc/rc.local<br />
加入下面这条命令<br />
/usr/share/denyhosts/daemon-control start</p>
<p>注意：如果自己之前登录失败次数很多的话，装DenyHosts前最好先清除下SSH登录记录<br />
echo "" &gt; /var/log/auth.log，不然有可能装完会把自己给封了。<br />
如果你已经被自己屏蔽了，可以使用下面方法给自己解封。</p>
<p>1.关闭denyhosts服务</p>
<p>/etc/init.d/denyhosts stop</p>
<p>2.把系统的登录log给清空</p>
<p>echo "" &gt; /var/log/auth.log</p>
<p>3.进/var/lib/denyhosts目录，把目录下所有文件内容清空一遍（这个是DenyHosts自己的log目录）<br />
4.运行vi /etc/hosts.deny 把里面自己的IP给删除。</p>
<p>5.重启denyhosts</p>
<p>/etc/init.d/denyhosts restart</p>
<p>centos更简单了。</p>
<p>rpm -Uvh http://mirror.metrocast.net/fedora/epel/6/i386/epel-release-6-8.noarch.rpm<br />
yum install denyhosts</p>
<p>chkconfig --add denyhosts<br />
chkconfig denyhosts on</p>
<p>service denyhosts restart</p><img src ="http://www.cppblog.com/niewenlong/aggbug/214055.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2016-07-27 13:00 <a href="http://www.cppblog.com/niewenlong/archive/2016/07/27/214055.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何使用大于16TB的ext4文件系统</title><link>http://www.cppblog.com/niewenlong/archive/2016/06/22/213784.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Wed, 22 Jun 2016 03:53:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2016/06/22/213784.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/213784.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2016/06/22/213784.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/213784.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/213784.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: mke2fs -O 64bit,has_journal,extents,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize -i 4194304 /dev/iscsi/test&nbsp;mke2fs -O 64bit,has_journal,extents,huge_file,flex_bg,uninit_bg,dir_nlink,extra_...&nbsp;&nbsp;<a href='http://www.cppblog.com/niewenlong/archive/2016/06/22/213784.html'>阅读全文</a><img src ="http://www.cppblog.com/niewenlong/aggbug/213784.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2016-06-22 11:53 <a href="http://www.cppblog.com/niewenlong/archive/2016/06/22/213784.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>完美使用remastersys备份和还原系统</title><link>http://www.cppblog.com/niewenlong/archive/2015/12/08/212435.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Tue, 08 Dec 2015 06:35:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2015/12/08/212435.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/212435.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2015/12/08/212435.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/212435.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/212435.html</trackback:ping><description><![CDATA[<span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">Remastersys制作自己的Linux发行版.txt</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">1.系统备份</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">2.打包系统，做成livecd/dvd</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">怎样安装？</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">ubuntu用户1.把下面的源地址加到sources.list</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">deb </span><a rel="nofollow" href="http://www.geekconnection.org/remastersys/repository" target="_blank" style="cursor: pointer; color: #666699; text-decoration: none; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">http://www.geekconnection.org/remastersys/repository</a><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;"> ubuntu/</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">2.sudo apt-get update</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">3.sudo apt-get install remastersys</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">debian用户1.把下面的源地址加到sources.list</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">deb </span><a rel="nofollow" href="http://www.geekconnection.org/remastersys/repository" target="_blank" style="cursor: pointer; color: #666699; text-decoration: none; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">http://www.geekconnection.org/remastersys/repository</a><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;"> debian/</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">2.sudo apt-get update</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">3.sudo apt-get install remastersys</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">怎样使用？</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">sudo remastersys backup|clean|dist [cdfs|iso] [filename.iso]</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">sudo remastersys backup #(to make a livecd/dvd backup of your system制作系统备份livecd)</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">sudo remastersys backup custom.iso #(to make a livecd/dvd backup and call the iso custom.iso制作系统备份livecd,名字是custom.iso)</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">sudo remastersys clean #(to clean up temporary files of remastersys清除制作时产生的临时文件)</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">sudo remastersys dist    # (to make a distributable livecd/dvd of your system制作你现有系统的livecd发行版)</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">sudo remastersys dist cdfs #(to make a distributable livecd/dvd filesystem only 仅制作livecd文件系统cdfs)</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">sudo remastersys dist iso custom.iso #   (to make a distributable iso named custom.iso but only if the cdfs is already</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">present制作livecd，前提是cdfs已经就绪)</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">cdfs and iso options should only be used if you wish to modify something on the cd before the iso is created. An example of this would</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">be to modify the isolinux portion of the livecd/dvd</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">cdfs和iso选项应该只被用于你希望更改一些选项的时候，比如你要更改isolinux部分</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">另外此程序是拥有图形界面的System -&gt;administration -&gt;Remastersys Backup，也是非常不错，很傻瓜:)</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">使用测试～～</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">我的6.4G的跟文件系统做成之后的iso有1.5G，非常不错，使用的是sudo remastersys dist xiaoqiang.iso</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">测试的时候会出现找不到intird.gz的错误，后来进入iso查看了下，发现casper目录中并没有initrd.gz这个文件，于是</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">cd /home/remastersys/remastersys</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">sudo cp /boot/initrd.img-2.6.31-14-generic ISOTMP/casper/initrd.gz</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">sudo rm xiaoqiang.iso</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">sudo remastersys dist iso xiaoqiang.iso</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;" /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 21.06px; white-space: pre-wrap; background-color: #ffffff;">重新打包,再次测试，成功启动，并且包含所有已经安装的软件，包括我的chrome，永中office。太爽了～～ubuntu之小强</span><img src ="http://www.cppblog.com/niewenlong/aggbug/212435.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2015-12-08 14:35 <a href="http://www.cppblog.com/niewenlong/archive/2015/12/08/212435.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>https://wiki.debian.org/iwlwifi</title><link>http://www.cppblog.com/niewenlong/archive/2015/05/25/210743.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Mon, 25 May 2015 14:33:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2015/05/25/210743.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/210743.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2015/05/25/210743.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/210743.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/210743.html</trackback:ping><description><![CDATA[<div>
<div>https://wiki.debian.org/iwlwifi<div><h2>Installation</h2> <p>  </p><h3>Debian 8 "Jessie"</h3> <ol type="1"><li><p>Add a "non-free" component to <tt>/etc/apt/sources.list</tt>, for example: </p><pre># Debian 8 "Jessie" deb http://http.debian.net/debian/ jessie main contrib non-free</pre></li><li><p>Update the list of available packages and install the <a href="https://packages.debian.org/jessie/firmware-iwlwifi" title="DebianPkg">firmware-iwlwifi</a> package: </p><pre># apt-get update &amp;&amp; apt-get install firmware-iwlwifi</pre></li><li><p>As the iwlwifi module is <a href="https://wiki.debian.org/Modules">automatically loaded</a> for supported devices, reinsert this module to access installed firmware: </p><pre># modprobe -r iwlwifi ; modprobe iwlwifi</pre></li><li><p><a href="https://wiki.debian.org/WiFi/HowToUse">Configure</a> your wireless interface as appropriate. </p></li></ol><p>   </p><h3>Debian 7 "Wheezy"</h3> <ol type="1"><li><p>Add a "non-free" component to <tt>/etc/apt/sources.list</tt>, for example: </p><pre># Debian 7 "Wheezy" deb http://http.debian.net/debian/ wheezy main contrib non-free</pre></li><li><p>Update the list of available packages and install the <a href="https://packages.debian.org/wheezy/firmware-iwlwifi" title="DebianPkg">firmware-iwlwifi</a> package: </p><pre># apt-get update &amp;&amp; apt-get install firmware-iwlwifi</pre></li><li><p>As the iwlwifi module is <a href="https://wiki.debian.org/Modules">automatically loaded</a> for supported devices, reinsert this module to access installed firmware: </p><pre># modprobe -r iwlwifi ; modprobe iwlwifi</pre></li><li><p><a href="https://wiki.debian.org/WiFi/HowToUse">Configure</a> your wireless interface as appropriate. </p></li></ol></div></div>
</div><img src ="http://www.cppblog.com/niewenlong/aggbug/210743.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2015-05-25 22:33 <a href="http://www.cppblog.com/niewenlong/archive/2015/05/25/210743.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux c学习笔记----文件的创建与读写(open,read,write) </title><link>http://www.cppblog.com/niewenlong/archive/2015/05/03/Linux_open_read_write.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sun, 03 May 2015 15:35:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2015/05/03/Linux_open_read_write.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/210534.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2015/05/03/Linux_open_read_write.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/210534.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/210534.html</trackback:ping><description><![CDATA[<div><p><strong><span style="font-size: medium;">open(打开文件)</span></strong></p><p>&nbsp;</p><table width="100%" border="0"><tbody><tr><td width="80"><div>相关函数 </div></td><td>read，write，fcntl，close，link，stat，umask，unlink，fopen<br /></td></tr><tr><td width="80"><div>表头文件 </div></td><td>#include&lt;sys/types.h&gt;<br />#include&lt;sys/stat.h&gt;<br />#include&lt;fcntl.h&gt;<br /></td></tr><tr><td width="80"><div>定义函数 </div></td><td>int open( const char * pathname, int flags);<br />int  open( const char * pathname,int flags, mode_t mode);<br /></td></tr><tr><td width="80"><div>函数说明 </div></td><td>参数pathname 指向欲打开的文件路径字符串。下列是参数flags  所能使用的旗标:<br />O_RDONLY 以只读方式打开文件<br />O_WRONLY 以只写方式打开文件<br />O_RDWR  以可读写方式打开文件。上述三种旗标是互斥的，也就是不可同时使用，但可与下列的旗标利用OR(|)运算符组合。<br />O_CREAT  若欲打开的文件不存在则自动建立该文件。<br />O_EXCL 如果O_CREAT  也被设置，此指令会去检查文件是否存在。文件若不存在则建立该文件，否则将导致打开文件错误。此外，若O_CREAT与O_EXCL同时设置，并且欲打开的文件为符号连接，则会打开文件失败。<br />O_NOCTTY  如果欲打开的文件为终端机设备时，则不会将该终端机当成进程控制终端机。<br />O_TRUNC  若文件存在并且以可写的方式打开时，此旗标会令文件长度清为0，而原来存于该文件的资料也会消失。<br />O_APPEND  当读写文件时会从文件尾开始移动，也就是所写入的数据会以附加的方式加入到文件后面。<br />O_NONBLOCK  以不可阻断的方式打开文件，也就是无论有无数据读取或等待，都会立即返回进程之中。<br />O_NDELAY 同O_NONBLOCK。<br />O_SYNC  以同步的方式打开文件。<br />O_NOFOLLOW 如果参数pathname 所指的文件为一符号连接，则会令打开文件失败。<br />O_DIRECTORY  如果参数pathname 所指的文件并非为一目录，则会令打开文件失败。<br />此为Linux2.2以后特有的旗标，以避免一些系统安全问题。参数mode  则有下列数种组合，只有在建立新文件时才会生效，此外真正建文件时的权限会受到umask值所影响，因此该文件权限应该为（mode-umaks）。<br />S_IRWXU00700  权限，代表该文件所有者具有可读、可写及可执行的权限。<br />S_IRUSR  或S_IREAD，00400权限，代表该文件所有者具有可读取的权限。<br />S_IWUSR 或S_IWRITE，00200  权限，代表该文件所有者具有可写入的权限。<br />S_IXUSR 或S_IEXEC，00100 权限，代表该文件所有者具有可执行的权限。<br />S_IRWXG  00070权限，代表该文件用户组具有可读、可写及可执行的权限。<br />S_IRGRP 00040 权限，代表该文件用户组具有可读的权限。<br />S_IWGRP  00020权限，代表该文件用户组具有可写入的权限。<br />S_IXGRP 00010 权限，代表该文件用户组具有可执行的权限。<br />S_IRWXO  00007权限，代表其他用户具有可读、可写及可执行的权限。<br />S_IROTH 00004 权限，代表其他用户具有可读的权限<br />S_IWOTH  00002权限，代表其他用户具有可写入的权限。<br />S_IXOTH 00001 权限，代表其他用户具有可执行的权限。<br /></td></tr><tr><td width="80"><div>返回值 </div></td><td>若所有欲核查的权限都通过了检查则返回0  值，表示成功，只要有一个权限被禁止则返回-1。<br /></td></tr><tr><td width="80"><div>错误代码 </div></td><td>EEXIST 参数pathname  所指的文件已存在，却使用了O_CREAT和O_EXCL旗标。<br />EACCESS 参数pathname所指的文件不符合所要求测试的权限。<br />EROFS  欲测试写入权限的文件存在于只读文件系统内。<br />EFAULT 参数pathname指针超出可存取内存空间。<br />EINVAL 参数mode  不正确。<br />ENAMETOOLONG 参数pathname太长。<br />ENOTDIR 参数pathname不是目录。<br />ENOMEM  核心内存不足。<br />ELOOP 参数pathname有过多符号连接问题。<br />EIO I/O 存取错误。<br /></td></tr><tr><td width="80"><div>附加说明 </div></td><td>使用access()作用户认证方面的判断要特别小心，例如在access()后再作open()空文件可能会造成系统安全上的问题。<br /></td></tr><tr><td width="80"><div>范例 </div></td><td>#include&lt;unistd.h&gt;<br />#include&lt;sys/types.h&gt;<br />#include&lt;sys/stat.h&gt;<br />#include&lt;fcntl.h&gt;<br />main()<br />{<br />int  fd,size;<br />char s [ ]=&#8221;Linux  Programmer!\n&#8221;,buffer[80];<br />fd=open(&#8220;/tmp/temp&#8221;,O_WRONLY|O_CREAT);<br />write(fd,s,sizeof(s));<br />close(fd);<br />fd=open(&#8220;/tmp/temp&#8221;,O_RDONLY);<br />size=read(fd,buffer,sizeof(buffer));<br />close(fd);<br />printf(&#8220;%s&#8221;,buffer);<br />}<br /></td></tr><tr><td width="80"><div>执行 </div></td><td>Linux Programmer!<br /></td></tr></tbody></table><p>&nbsp;</p><p><strong><span style="font-size: medium;">read（由已打开的文件读取数据）</span></strong> </p><p>&nbsp;</p><table width="100%" border="0"><tbody><tr><td><br /></td></tr><tr><td width="80"><div>相关函数 </div></td><td>readdir，write，fcntl，close，lseek，readlink，fread<br /></td></tr><tr><td width="80"><div>表头文件 </div></td><td>#include&lt;unistd.h&gt;<br /></td></tr><tr><td width="80"><div>定义函数 </div></td><td>ssize_t read(int fd,void * buf ,size_t  count);<br /></td></tr><tr><td width="80"><div>函数说明 </div></td><td>read()会把参数fd  所指的文件传送count个字节到buf指针所指的内存中。若参数count为0，则read()不会有作用并返回0。返回值为实际读取到的字节数，如果返回0，表示已到达文件尾或是无可读取的数据，此外文件读写位置会随读取到的字节移动。<br /></td></tr><tr><td width="80"><div>附加说明 </div></td><td>如果顺利read()会返回实际读到的字节数，最好能将返回值与参数count  作比较，若返回的字节数比要求读取的字节数少，则有可能读到了文件尾、从管道(pipe)或终端机读取，或者是read()被信号中断了读取动作。当有错误发生时则返回-1，错误代码存入errno中，而文件读写位置则无法预期。<br /></td></tr><tr><td width="80"><div>错误代码 </div></td><td>EINTR 此调用被信号所中断。<br />EAGAIN 当使用不可阻断I/O  时（O_NONBLOCK），若无数据可读取则返回此值。<br />EBADF 参数fd  非有效的文件描述词，或该文件已关闭。<br /></td></tr><tr><td width="80"><div>范例 </div></td><td>参考open（）。<br /></td></tr></tbody></table><p>&nbsp;</p><p><strong><span style="font-size: medium;">write（将数据写入已打开的文件内）</span></strong></p><p>&nbsp;</p><p>&nbsp;</p><table width="100%" border="0"><tbody><tr><td width="80"><div>相关函数 </div></td><td>open，read，fcntl，close，lseek，sync，fsync，fwrite<br /></td></tr><tr><td width="80"><div>表头文件 </div></td><td>#include&lt;unistd.h&gt;<br /></td></tr><tr><td width="80"><div>定义函数 </div></td><td>ssize_t write (int fd,const void * buf,size_t  count);<br /></td></tr><tr><td width="80"><div>函数说明 </div></td><td>write()会把参数buf所指的内存写入count个字节到参数fd所指的文件内。当然，文件读写位置也会随之移动。<br /></td></tr><tr><td width="80"><div>返回值 </div></td><td>如果顺利write()会返回实际写入的字节数。当有错误发生时则返回-1，错误代码存入errno中。<br /></td></tr><tr><td width="80"><div>错误代码 </div></td><td>EINTR 此调用被信号所中断。<br />EAGAIN 当使用不可阻断I/O  时（O_NONBLOCK），若无数据可读取则返回此值。<br />EADF 参数fd非有效的文件描述词，或该文件已关闭。<br /></td></tr><tr><td width="80"><div>范例 </div></td><td>请参考open（）。<br /></td></tr></tbody></table><p>&nbsp;</p><p>&nbsp;</p><p>拷贝文件实例：</p></div><div style="padding: 4px 5px 4px 4px; border: 1px solid #cccccc; border-image: none; width: 98%; font-size: 13px; word-break: break-all; background-color: #eeeeee;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080;">&nbsp;1</span>&nbsp;<span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">unistd.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;2</span>&nbsp;<span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">fcntl.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;3</span>&nbsp;<span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">stdio.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;4</span>&nbsp;<span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">types.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;5</span>&nbsp;<span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">stat.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;6</span>&nbsp;<span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">errno.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;7</span>&nbsp;<span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;8</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;BUFFER_SIZE&nbsp;1024</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;9</span>&nbsp;<span style="color: #000000;"><br /></span><span style="color: #008080;">10</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;argc,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">**</span><span style="color: #000000;">argv)&nbsp;{<br /></span><span style="color: #008080;">11</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;from_fd,&nbsp;to_fd;<br /></span><span style="color: #008080;">12</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;bytes_read,&nbsp;bytes_write;<br /></span><span style="color: #008080;">13</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;buffer[BUFFER_SIZE];<br /></span><span style="color: #008080;">14</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">ptr;<br /></span><span style="color: #008080;">15</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">)&nbsp;{<br /></span><span style="color: #008080;">16</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">Usage：%s&nbsp;fromfile&nbsp;tofile\n\a</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">0</span><span style="color: #000000;">]);<br /></span><span style="color: #008080;">17</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br /></span><span style="color: #008080;">18</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080;">19</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;打开源文件&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /></span><span style="color: #008080;">20</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;((from_fd&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;open(argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">],&nbsp;O_RDONLY))&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;{<br /></span><span style="color: #008080;">21</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">Open&nbsp;%s&nbsp;Error：%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">],&nbsp;strerror(errno));<br /></span><span style="color: #008080;">22</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br /></span><span style="color: #008080;">23</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080;">24</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;创建目的文件&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /></span><span style="color: #008080;">25</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;((to_fd&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;open(argv[</span><span style="color: #000000;">2</span><span style="color: #000000;">],&nbsp;O_WRONLY&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">&nbsp;O_CREAT,&nbsp;S_IRUSR&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">&nbsp;S_IWUSR))&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;{<br /></span><span style="color: #008080;">26</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">Open&nbsp;%s&nbsp;Error：%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">2</span><span style="color: #000000;">],&nbsp;strerror(errno));<br /></span><span style="color: #008080;">27</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br /></span><span style="color: #008080;">28</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080;">29</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;以下代码是一个经典的拷贝文件的代码&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /></span><span style="color: #008080;">30</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">&nbsp;(bytes_read&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;read(from_fd,&nbsp;buffer,&nbsp;BUFFER_SIZE))&nbsp;{<br /></span><span style="color: #008080;">31</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;一个致命的错误发生了&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /></span><span style="color: #008080;">32</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;((bytes_read&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">&nbsp;(errno&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;EINTR))&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br /></span><span style="color: #008080;">33</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(bytes_read&nbsp;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">)&nbsp;{<br /></span><span style="color: #008080;">34</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;buffer;<br /></span><span style="color: #008080;">35</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">&nbsp;(bytes_write&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;write(to_fd,&nbsp;ptr,&nbsp;bytes_read))&nbsp;{<br /></span><span style="color: #008080;">36</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;一个致命错误发生了&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /></span><span style="color: #008080;">37</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;((bytes_write&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">&nbsp;(errno&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;EINTR))</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br /></span><span style="color: #008080;">38</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;写完了所有读的字节&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /></span><span style="color: #008080;">39</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(bytes_write&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;bytes_read)&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br /></span><span style="color: #008080;">40</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;只写了一部分,继续写&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /></span><span style="color: #008080;">41</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(bytes_write&nbsp;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">)&nbsp;{<br /></span><span style="color: #008080;">42</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr&nbsp;</span><span style="color: #000000;">+=</span><span style="color: #000000;">&nbsp;bytes_write;<br /></span><span style="color: #008080;">43</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bytes_read&nbsp;</span><span style="color: #000000;">-=</span><span style="color: #000000;">&nbsp;bytes_write;<br /></span><span style="color: #008080;">44</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080;">45</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080;">46</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;写的时候发生的致命错误&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br /></span><span style="color: #008080;">47</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(bytes_write&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br /></span><span style="color: #008080;">48</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080;">49</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080;">50</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;close(from_fd);<br /></span><span style="color: #008080;">51</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;close(to_fd);<br /></span><span style="color: #008080;">52</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">0</span><span style="color: #000000;">);<br /></span><span style="color: #008080;">53</span>&nbsp;<span style="color: #000000;">}<br /></span><span style="color: #008080;">54</span>&nbsp;<span style="color: #000000;"></span></div><br /><div style="padding: 4px 5px 4px 4px; border: 1px solid #cccccc; border-image: none; width: 98%; font-size: 13px; word-break: break-all; background-color: #eeeeee;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">unistd.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">fcntl.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">stdio.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">types.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">sys</span><span style="color: #000000;">/</span><span style="color: #000000;">stat.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">errno.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br /></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;BUFFER_SIZE&nbsp;1024</span><span style="color: #000000;"><br /><br /></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;argc,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">**</span><span style="color: #000000;">argv)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;from_fd,&nbsp;to_fd;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;bytes_read,&nbsp;bytes_write;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;buffer[BUFFER_SIZE];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">ptr;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">Usage：%s&nbsp;fromfile&nbsp;tofile\n\a</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">0</span><span style="color: #000000;">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;打开源文件&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;((from_fd&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;open(argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">],&nbsp;O_RDONLY))&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">Open&nbsp;%s&nbsp;Error：%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">],&nbsp;strerror(errno));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;创建目的文件&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;((to_fd&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;open(argv[</span><span style="color: #000000;">2</span><span style="color: #000000;">],&nbsp;O_WRONLY&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">&nbsp;O_CREAT,&nbsp;S_IRUSR&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">&nbsp;S_IWUSR))&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">Open&nbsp;%s&nbsp;Error：%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">2</span><span style="color: #000000;">],&nbsp;strerror(errno));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;以下代码是一个经典的拷贝文件的代码&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">&nbsp;(bytes_read&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;read(from_fd,&nbsp;buffer,&nbsp;BUFFER_SIZE))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;一个致命的错误发生了&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;((bytes_read&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">&nbsp;(errno&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;EINTR))&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(bytes_read&nbsp;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;buffer;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">&nbsp;(bytes_write&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;write(to_fd,&nbsp;ptr,&nbsp;bytes_read))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;一个致命错误发生了&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;((bytes_write&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">&nbsp;(errno&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;EINTR))</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;写完了所有读的字节&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(bytes_write&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;bytes_read)&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;只写了一部分,继续写&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(bytes_write&nbsp;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr&nbsp;</span><span style="color: #000000;">+=</span><span style="color: #000000;">&nbsp;bytes_write;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bytes_read&nbsp;</span><span style="color: #000000;">-=</span><span style="color: #000000;">&nbsp;bytes_write;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;写的时候发生的致命错误&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(bytes_write&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;close(from_fd);<br />&nbsp;&nbsp;&nbsp;&nbsp;close(to_fd);<br />&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">0</span><span style="color: #000000;">);<br />}<br /></span></div><img src ="http://www.cppblog.com/niewenlong/aggbug/210534.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2015-05-03 23:35 <a href="http://www.cppblog.com/niewenlong/archive/2015/05/03/Linux_open_read_write.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> mysql数据库备份及恢复命令mysqldump,source的用法 </title><link>http://www.cppblog.com/niewenlong/archive/2014/08/07/207927.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Wed, 06 Aug 2014 16:52:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2014/08/07/207927.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/207927.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2014/08/07/207927.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/207927.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/207927.html</trackback:ping><description><![CDATA[<div>       <h1>         <span><a href="http://blog.csdn.net/bxbx258/article/details/2945832"></a></span></h1></div><div><div id="article_content"> <p><strong>还原一个数据库:mysql -h localhost -u root -p123456 www&lt;c:/www.sql</strong> </p> <p><strong>备份一个数据库:mysqldump -h localhost -u root -p123456 www &gt; d:/www2008-2-26.sql</strong> </p> <p>&nbsp;</p> <p>&nbsp;</p> <p><strong>//以下是在程序中进行测试</strong> </p> <p><strong>//$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip &gt; $backupFile";<br /> $command="mysqldump -h localhost -u root -p123456 guestbook &gt; guestbook2-29.sql";<br /> system($command);<br /> echo "success";<br /> </strong> </p> <p><strong>************************************************</strong> </p> <p><strong>备份MySQL数据库的命令</strong> </p> <div> <div>mysqldump -hhostname -uusername -ppassword databasename &gt; backupfile.sql</div> </div> <p><strong>备份MySQL数据库为带删除表的格式</strong> <br /> 备份MySQL数据库为带删除表的格式，能够让该备份覆盖已有数据库而不需要手动删除原有数据库。</p> <div> <div>mysqldump -&#8211;add-drop-table -uusername -ppassword databasename &gt; backupfile.sql</div> </div> <p><strong>直接将MySQL数据库压缩备份</strong> </p> <div> <div>mysqldump -hhostname -uusername -ppassword databasename | gzip &gt; backupfile.sql.gz</div> </div> <p><strong>备份MySQL数据库某个(些)表</strong> </p> <div> <div>mysqldump -hhostname -uusername -ppassword databasename specific_table1 specific_table2 &gt; backupfile.sql</div> </div> <p><strong>同时备份多个MySQL数据库</strong> </p> <div> <div>mysqldump -hhostname -uusername -ppassword &#8211;databases databasename1 databasename2 databasename3 &gt; multibackupfile.sql</div> </div> <p><strong>仅仅备份数据库结构</strong> </p> <div> <div>mysqldump &#8211;no-data &#8211;databases databasename1 databasename2 databasename3 &gt; structurebackupfile.sql</div> </div> <p><strong>备份服务器上所有数据库</strong> </p> <div> <div>mysqldump &#8211;all-databases &gt; allbackupfile.sql</div> </div> <p><strong>还原MySQL数据库的命令</strong> </p> <div> <div>mysql -hhostname -uusername -ppassword databasename &lt; backupfile.sql</div> </div> <p><strong>还原压缩的MySQL数据库</strong> </p> <div> <div>gunzip &lt; backupfile.sql.gz | mysql -uusername -ppassword databasename</div> </div> <p><strong>将数据库转移到新服务器</strong> </p> <div> <div>mysqldump -uusername -ppassword databasename | mysql &#8211;host=*.*.*.* -C databasename</div> <div>&nbsp;</div> <div>&nbsp;<strong>几个常用用例：</strong> <p>1.导出整个数据库<br /> mysqldump -u 用户名 -p 数据库名 &gt; 导出的文件名<br /> <span style="font-family: NSimsun;"><code>mysqldump -u root -p dataname &gt;dataname.sql</code> <br /> </span> 这个时候会提示要你输入root用户名的密码,输入密码后dataname数据库就成功备份在mysql/bin/目录中.</p> <p>2.导出一个表<br /> mysqldump -u 用户名 -p 数据库名 表名&gt; 导出的文件名<br /> <code><span style="font-family: 新宋体;">mysqldump -u root -p dataname users&gt; dataname_users.sql</span> </code> </p> <p>3.导出一个数据库结构<br /> <span style="font-family: NSimsun;"><code>mysqldump -u wcnc -p -d &#8211;add-drop-table smgp_apps_wcnc &gt;d:/wcnc_db.sql</code> <br /> </span> -d 没有数据 &#8211;add-drop-table 在每个create语句之前增加一个drop table</p> <p>4.导入数据库<br /> 常用source 命令<br /> 进入mysql数据库控制台，<br /> 如mysql -u root -p</p> <p>mysql&gt;use 数据库</p> <p>然后使用source命令，后面参数为脚本文件（如这里用到的.sql）<br /> mysql&gt;source d:/wcnc_db.sql</p> <p><strong>mysqldump支持下列选项：</strong> <br /> &#8211;add-locks<br /> 在每个表导出之前增加LOCK TABLES并且之后UNLOCK TABLE。(为了使得更快地插入到MySQL)。</p> <p>&#8211;add-drop-table<br /> 在每个create语句之前增加一个drop table。</p> <p>&#8211;allow-keywords<br /> 允许创建是关键词的列名字。这由表名前缀于每个列名做到。</p> <p>-c, &#8211;complete-insert<br /> 使用完整的insert语句(用列名字)。</p> <p>-C, &#8211;compress<br /> 如果客户和服务器均支持压缩，压缩两者间所有的信息。</p> <p>&#8211;delayed<br /> 用INSERT DELAYED命令插入行。</p> <p>-e, &#8211;extended-insert<br /> 使用全新多行INSERT语法。（给出更紧缩并且更快的插入语句）</p> <p>-#, &#8211;debug[=option_string]<br /> 跟踪程序的使用(为了调试)。</p> <p>&#8211;help<br /> 显示一条帮助消息并且退出。</p> <p>&#8211;fields-terminated-by=&#8230;</p> <p>&#8211;fields-enclosed-by=&#8230;</p> <p>&#8211;fields-optionally-enclosed-by=&#8230;</p> <p>&#8211;fields-escaped-by=&#8230;</p> <p>&#8211;fields-terminated-by=&#8230;</p> <p>这些选择与-T选择一起使用，并且有相应的LOAD DATA INFILE子句相同的含义。<br /> LOAD DATA INFILE语法。</p> <p>-F, &#8211;flush-logs<br /> 在开始导出前，洗掉在MySQL服务器中的日志文件。</p> <p>-f, &#8211;force,<br /> 即使我们在一个表导出期间得到一个SQL错误，继续。</p> <p>-h, &#8211;host=..<br /> 从命名的主机上的MySQL服务器导出数据。缺省主机是localhost。</p> <p>-l, &#8211;lock-tables.<br /> 为开始导出锁定所有表。</p> <p>-t, &#8211;no-create-info<br /> 不写入表创建信息(CREATE TABLE语句）</p> <p>-d, &#8211;no-data<br /> 不写入表的任何行信息。如果你只想得到一个表的结构的导出，这是很有用的！</p> <p>&#8211;opt<br /> 同&#8211;quick &#8211;add-drop-table &#8211;add-locks &#8211;extended-insert &#8211;lock-tables。<br /> 应该给你为读入一个MySQL服务器的尽可能最快的导出。</p> <p>-pyour_pass, &#8211;password[=your_pass]<br /> 与服务器连接时使用的口令。如果你不指定&#8220;=your_pass&#8221;部分，mysqldump需要来自终端的口令。</p> <p>-P port_num, &#8211;port=port_num<br /> 与一台主机连接时使用的TCP/IP端口号。（这用于连接到localhost以外的主机，因为它使用 Unix套接字。）</p> <p>-q, &#8211;quick<br /> 不缓冲查询，直接导出至stdout；使用mysql_use_result()做它。</p> <p>-S /path/to/socket, &#8211;socket=/path/to/socket<br /> 与localhost连接时（它是缺省主机)使用的套接字文件。</p> <p>-T, &#8211;tab=path-to-some-directory<br /> 对于每个给定的表，创建一个table_name.sql文件，它包含SQL CREATE 命令，和一个table_name.txt文件，它包含数据。注意：这只有在mysqldump运行在mysqld守护进程运行的同一台机器上的时候才工 作。.txt文件的格式根据&#8211;fields-xxx和 &#8211;lines&#8211;xxx选项来定。</p> <p>-u user_name, &#8211;user=user_name<br /> 与服务器连接时，MySQL使用的用户名。缺省值是你的Unix登录名。</p> <p>-O var=option, &#8211;set-variable var=option<br /> 设置一个变量的值。可能的变量被列在下面。</p> <p>-v, &#8211;verbose<br /> 冗长模式。打印出程序所做的更多的信息。</p> <p>-V, &#8211;version<br /> 打印版本信息并且退出。</p> <p>-w, &#8211;where=&#8217;where-condition&#8217;<br /> 只导出被选择了的记录；注意引号是强制的！<br /> &#8220;&#8211;where=user=&#8217;jimf&#8217;&#8221; &#8220;-wuserid&gt;1&#8243; &#8220;-wuserid&lt;1&#8243;</p> <p>最常见的mysqldump使用可能制作整个数据库的一个备份：<br /> mysqldump &#8211;opt database &gt; backup-file.sql</p> <p>但是它对用来自于一个数据库的信息充实另外一个MySQL数据库也是有用的：<br /> mysqldump &#8211;opt database | mysql &#8211;host=remote-host -C database<br /> 由于mysqldump导出的是完整的SQL语句，所以用mysql客户程序很容易就能把数据导入了：</p> <p>shell&gt; mysqladmin create target_db_name<br /> shell&gt; mysql target_db_name &lt; backup-file.sql<br /> 就是<br /> shell&gt; mysql 库名 &lt; 文件名</p> </div> </div> </div></div><br /><br /><br /><div><div id="article_content">  <div>mysqldump--导出工具</div> <div>&nbsp;</div> <div> <p>mysqldump备份还原和mysqldump导入导出语句大全详解</p> <p><strong>mysqldump备份</strong>：</p> <p>mysqldump -u用户名 -p密码 -h主机 数据库 a -w "sql条件" --lock-all-tables &gt; 路径</p> <p>案例：</p> <p>mysqldump -uroot -p1234 -hlocalhost db1 a -w "id in (select id from b)" --lock-all-tables &gt; c:\aa.txt</p> <p><strong>mysqldump还原</strong>：</p> <p>mysqldump -u用户名 -p密码 -h主机 数据库 &lt; 路径</p> <p>案例：</p> <p>mysql -uroot -p1234 db1 &lt; c:\aa.txt</p> <p><strong>mysqldump按条件导出</strong>：</p> <p>mysqldump -u用户名 -p密码 -h主机 数据库&nbsp; a --where "条件语句" --no-建表&gt; 路径</p> <p>mysqldump -uroot -p1234 dbname a --where "tag='88'" --no-create-info&gt; c:\a.sql</p> <p><strong>mysqldump按导入</strong>：</p> <p>mysqldump -u用户名 -p密码 -h主机 数据库 &lt; 路径</p> <p>案例：</p> <p>mysql -uroot -p1234 db1 &lt; c:\a.txt</p>  <p><strong>mysqldump导出表</strong>：</p> <p>mysqldump -u用户名 -p密码 -h主机 数据库 表</p> <p>案例：</p> <p>mysqldump -uroot -p sqlhk9 a --no-data</p> <p>讲一下 mysqldump 的一些主要参数</p>  <p><strong>--compatible=name </strong><br /> 它告诉 mysqldump，导出的数据将和哪种数据库或哪个旧版本的 MySQL 服务器相兼容。值可以为  ansi、mysql323、mysql40、postgresql、oracle、mssql、db2、maxdb、no_key_options、 no_tables_options、no_field_options  等，要使用几个值，用逗号将它们隔开。当然了，它并不保证能完全兼容，而是尽量兼容。 <br /> <strong>--complete-insert，-c </strong><br /> 导出的数据采用包含字段名的完整 INSERT 方式，也就是把所有的值都写在一行。这么做能提高插入效率，但是可能会受到 max_allowed_packet 参数的影响而导致插入失败。因此，需要谨慎使用该参数，至少我不推荐。 <br /> <strong>--default-character-set=charset </strong><br /> 指定导出数据时采用何种字符集，如果数据表不是采用默认的 latin1 字符集的话，那么导出时必须指定该选项，否则再次导入数据后将产生乱码问题。<br /> <strong>--disable-keys </strong><br /> 告诉 mysqldump 在 INSERT 语句的开头和结尾增加 /*!40000 ALTER TABLE table DISABLE KEYS  */; 和 /*!40000 ALTER TABLE table ENABLE KEYS */;  语句，这能大大提高插入语句的速度，因为它是在插入完所有数据后才重建索引的。该选项只适合 MyISAM 表。<br /> <strong>--extended-insert = true|false <br /> </strong>默认情况下，mysqldump 开启 --complete-insert 模式，因此不想用它的的话，就使用本选项，设定它的值为 false 即可。 <br /> <strong>--hex-blob </strong><br /> 使用十六进制格式导出二进制字符串字段。如果有二进制数据就必须使用本选项。影响到的字段类型有 BINARY、VARBINARY、BLOB。<br /> <strong>--lock-all-tables，-x </strong><br /> 在开始导出之前，提交请求锁定所有数据库中的所有表，以保证数据的一致性。这是一个全局读锁，并且自动关闭 --single-transaction 和 --lock-tables 选项。<br /> <strong>--lock-tables </strong><br /> 它和 --lock-all-tables 类似，不过是锁定当前导出的数据表，而不是一下子锁定全部库下的表。本选项只适用于 MyISAM 表，如果是 Innodb 表可以用 --single-transaction 选项。<br /> <strong>--no-create-info，-t </strong><br /> 只导出数据，而不添加 CREATE TABLE 语句。<br /> <strong>--no-data，-d </strong><br /> 不导出任何数据，只导出数据库表结构。<br /> <strong>--opt </strong><br /> 这只是一个快捷选项，等同于同时添加 --add-drop-tables --add-locking --create-option  --disable-keys --extended-insert --lock-tables --quick --set-charset  选项。本选项能让 mysqldump 很快的导出数据，并且导出的数据能很快导回。该选项默认开启，但可以用 --skip-opt  禁用。注意，如果运行 mysqldump 没有指定 --quick 或 --opt  选项，则会将整个结果集放在内存中。如果导出大数据库的话可能会出现问题。<br /> <strong>--quick，-q </strong><br /> 该选项在导出大表时很有用，它强制 mysqldump 从服务器查询取得记录直接输出而不是取得所有记录后将它们缓存到内存中。<br /> <strong>--routines，-R </strong><br /> 导出存储过程以及自定义函数。<br /> <strong>--single-transaction </strong><br /> 该选项在导出数据之前提交一个 BEGIN SQL语句，BEGIN 不会阻塞任何应用程序且能保证导出时数据库的一致性状态。它只适用于事务表，例如 InnoDB 和 BDB。<br /> 本选项和 --lock-tables 选项是互斥的，因为 LOCK TABLES 会使任何挂起的事务隐含提交。<br /> 要想导出大表的话，应结合使用 --quick 选项。 <br /> <strong>--triggers </strong><br /> 同时导出触发器。该选项默认启用，用 --skip-triggers 禁用它。<br /> 其他参数详情请参考手册，我通常使用以下 SQL 来备份 MyISAM 表：<br /> /usr/local/mysql/bin/mysqldump -uyejr -pyejr "<br /> --default-character-set=utf8 --opt --extended-insert=false "<br /> --triggers -R --hex-blob -x db_name &gt; db_name.sql<br /> 使用以下 SQL 来备份 Innodb 表：<br /> /usr/local/mysql/bin/mysqldump -uyejr -pyejr "<br /> --default-character-set=utf8 --opt --extended-insert=false "<br /> --triggers -R --hex-blob --single-transaction db_name &gt; db_name.sql<br /> 另外，如果想要实现在线备份，还可以使用 --master-data 参数来实现，如下：<br /> <strong>/usr/local/mysql/bin/mysqldump -uyejr -pyejr "</strong><br /> --default-character-set=utf8 --opt --master-data=1 "<br /> --single-transaction --flush-logs db_name &gt; db_name.sql<br /> 它只是在一开始的瞬间请求锁表，然后就刷新binlog了，而后在导出的文件中加入CHANGE MASTER 语句来指定当前备份的binlog位置，如果要把这个文件恢复到slave里去，就可以采用这种方法来做。</p> <p>1.2 还原<br /> 用 mysqldump 备份出来的文件是一个可以直接倒入的 SQL 脚本，有两种方法可以将数据导入。<br /> 直接用 mysql 客户端 <br /> 例如：<br /> <strong>/usr/local/mysql/bin/mysql -uyejr -pyejr db_name &lt; db_name.sql</strong><br /> 用 SOURCE 语法 （实验不成功！！！） <br /> 其实这不是标准的 SQL 语法，而是 mysql 客户端提供的功能，例如：<br /> SOURCE /tmp/db_name.sql;<br /> 这里需要指定文件的绝对路径，并且必须是 mysqld 运行用户(例如 nobody)有权限读取的文件。</p> </div> <div><br /> </div> <div>#导出某个数据库－－结构+数据</div> <div>shell&gt;mysqldump -h192.168.161.124 -uroot -pxxxxxx --opt db_name |gzip -9 &gt; /db_bakup/db_name.gz</div> <div><br /> </div> <div>#导出某个数据库的表－－结构+数据+函数+存储过程</div> <div>shell&gt;mysqldump -h192.168.161.124 -uroot -pxxxxxx --opt -R db_name |gzip -9 &gt; /db_backup/db_name.gz</div> <div><br /> </div> <div>#导出多个数据库</div> <div>shell&gt;mysqldump -h192.168.161.124 -uroot -pxxxxxx --opt  --databases db_name1 db_name2 db_name3 |gzip -9 &gt;  /db_backup/mul_db.gz </div> <div><br /> </div> <div>#导出所有的数据库</div> <div>shell&gt;mysqldump -h192.168.161.124 -uroot -pxxxxxx --opt --all-databases |gzip -9 &gt; /db_bak/all_db.gz</div> <div><br /> </div> <div>#导出某个数据库的结构</div> <div>shell&gt;mysqldump -h192.168.161.124 -uroot -pxxxxxx --opt --no-data db_name|gzip -9 &gt; /db_bak/db_name.strcut.gz</div> <div><br /> </div> <div>#导出某个数据库的数据</div> <div>shell&gt;mysqldump -h192.168.161.124 -uroot -pxxxxxx --opt --no-create-info db_name|gzip -9 &gt; /db_bak/db_naem.data.gz</div> <div><br /> </div> <div>#导出某个数据库的某张表</div> <div>shell&gt;mysqldump -h192.168.161.124 -uroot -pxxxxxx --opt db_name tbl_name |gzip -9 &gt; /db_bak/db_name.tal_name.gz</div> <div><br /> </div> <div># 导出某个数据库的某张表的结构</div> <div>shell&gt;mysqldump -h192.168.161.124 -uroot -pxxxxxx --opt  --no-data db_name tal_name | gzip -9 &gt;  /db_bak/db_name.tal_name.struct.gz</div> <div><br /> </div> <div>#导出某个数据库的某张表的数据</div> <div>shell&gt;mysqldump -h192.168.161.124 -uroot -pxxxxxx --opt  --no-create-info db_name tbl_name | gzip -9 &gt;  /db_bak/db_name.tbl_name.data.gz</div> <div><br /> </div> <div><span style="color:#f00000">##--opt==--add-drop-table + --add-locks  + --create-options + --disables-keys + --extended-insert +  --lock-tables + --quick + --set+charset</span></div> <div><span style="color:#f00000">##默认使用--opt，--skip-opt禁用--opt参数</span></div>  </div></div><img src ="http://www.cppblog.com/niewenlong/aggbug/207927.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2014-08-07 00:52 <a href="http://www.cppblog.com/niewenlong/archive/2014/08/07/207927.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>debian系统root用户登录和root用户自动登录</title><link>http://www.cppblog.com/niewenlong/archive/2014/08/06/207921.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Wed, 06 Aug 2014 06:41:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2014/08/06/207921.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/207921.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2014/08/06/207921.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/207921.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/207921.html</trackback:ping><description><![CDATA[<div><div style="word-wrap: break-word;"> 			<div> <p><span style="font-family: 'courier new', courier; font-size: 14px">Debian默认不允许root登录，所以修改之。</span></p> <p><strong><span style="font-family: 'courier new', courier; color: #ff0000">（1）让Debian以root登录</span></strong></p> <p><span style="font-family: 'courier new', courier">1）、</span><span style="font-family: 'courier new', courier">首先修改gdm3的设定文件（/etc/gdm3/deamon.conf），在[security]</span><span style="font-family: 'courier new', courier">字段后面追加如下一行：</span></p> <p><span style="font-family: 'courier new', courier"><span style="font-family: 'courier new', courier">AllowRoot </span>= ture<br /></span></p> <p><span style="font-family: 'courier new', courier">2）、最后修改gdm3的登录pam文件</span></p> <p><span style="font-family: 'courier new', courier">#vi /etc/pam.d/gdm3</span></p> <p><span style="font-family: 'courier new', courier">将auth required pam_succeed_if.so user != root quiet_success注释掉 //本行前加#</span></p> <p><strong><span style="font-family: 'courier new', courier; color: #ff0000">（2）让Debian以root自动登录。</span></strong></p> <p><span style="font-family: 'courier new', courier">1）、首先修改gdm3的设定文件（/etc/gdm3/deamon.conf），在[daemon]字段后面追加如下两行：<br /></span></p> <p><span style="font-family: 'courier new', courier">AutomaticLogin = false //改为true</span></p> <p><span style="font-family: 'courier new', courier">AutomaticLogin = root //以root自动登录</span></p> <p><span style="font-family: 'courier new', courier">如果想等几秒再登录，可以</span><span style="font-family: 'courier new', courier">在[daemon]字段后面追加如下内容：</span></p> <p><span style="font-family: 'courier new', courier">TimedLoginEnable = true</span></p> <p><span style="font-family: 'courier new', courier">TimedLogin = root</span></p> <p><span style="font-family: 'courier new', courier">TimedLoginDelay = 5 //延迟5秒登录，可修改</span></p> <p><span style="font-family: 'courier new', courier">2）、最后修改gdm3的自动登录pam文件</span></p> <p><span style="font-family: 'courier new', courier">#vi /etc/pam.d/gdm3-autologin</span></p> <p><span style="font-family: 'courier new', courier">将auth required pam_succeed_if.so user != root quiet_success注释掉。 //在本行前加#，取消Debian不让root登录的限制。</span></p> <p><span style="font-family: 'courier new', courier">重启即可。</span></p></div>           </div></div><img src ="http://www.cppblog.com/niewenlong/aggbug/207921.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2014-08-06 14:41 <a href="http://www.cppblog.com/niewenlong/archive/2014/08/06/207921.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ubuntu共享WiFi(AP)给Android方法【修正版】</title><link>http://www.cppblog.com/niewenlong/archive/2013/11/23/204395.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sat, 23 Nov 2013 03:09:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/11/23/204395.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/204395.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/11/23/204395.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/204395.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/204395.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Android不支持Ad-hoc模式的WiFi。Windows&nbsp;7软AP一个还是比较简单的。本文介绍在Ubuntu下实现软AP.(需要你的无线网卡支持AP哈)&nbsp;使用工具hostapd，dnsmasq.我的环境是Ubuntu11.10或ubuntu12.04;手机Android&nbsp;2.3.5;网卡ath5k.有线网络使用静态的IP.&nbsp;1、首先，系统是Ubuntu...&nbsp;&nbsp;<a href='http://www.cppblog.com/niewenlong/archive/2013/11/23/204395.html'>阅读全文</a><img src ="http://www.cppblog.com/niewenlong/aggbug/204395.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-11-23 11:09 <a href="http://www.cppblog.com/niewenlong/archive/2013/11/23/204395.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>解决Ubuntu 12.04LTS终端sudo命令无法解析主机报错问题</title><link>http://www.cppblog.com/niewenlong/archive/2013/06/17/201068.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Mon, 17 Jun 2013 03:21:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/06/17/201068.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/201068.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/06/17/201068.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/201068.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/201068.html</trackback:ping><description><![CDATA[<div><h2><a href="http://ycjvsycj1.lofter.com/post/b34f8_169d78">解决Ubuntu 12.04LTS终端sudo命令无法解析主机报错问题</a></h2>                                                          <p>安装系统时，会提示输入主机名</p><p>前几天为了用IPV6直接从一同学那尻了hosts</p>但是这样操作会产生另一个问题：在执行sudo命令时，会提示sudo: unable to resolve host ，亦即无法解析主机。在网上搜了下，找到了解决方法：<br />1.sudo gedit /etc/hosts<br />找到如下行：<br />127.0.1.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XXX<br />将其修改为：<br />127.0.1.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; （你现在的主机名）<br />注：可以使用全部替换</div><br /><br />**********************************************************************************<br /><div><div id="article_content">  <p>ubuntu永久修改主机名</p> <p>&nbsp;</p> <p>1、查看主机名<br /> <br /> 在Ubuntu系统中，快速查看主机名有多种方法：<br /> 其一，打开一个GNOME终端窗口，在命令提示符中可以看到主机名，主机名通常位于&#8220;@&#8221;符号后；<br /> 其二，在终端窗口中输入命令：hostname或uname &#8211;n，均可以查看到当前主机的主机名。<br /> <br /> 2、临时修改主机名<br /> <br /> 命令行下运行命令：&#8220;hostname 新主机名&#8221;<br /> 其中&#8220;新主机名&#8221;可以用任何合法字符串来表示。不过采用这种方式，新主机名并不保存在系统中，重启系统后主机名将恢复为原先的主机名称。<br /> 例子：hostname ubuntu-temp<br /> 这样主机名字就临时被修改为ubuntu-temp，但是终端下不会立即显示生效后的主机名，重开一个终端窗口(通过ssh连接的终端需要重新连接才可以);<br /> <br /> <br /> 3、永久修改主机名<br /> <br /> 在Ubuntu系统中永久修改主机名也比较简单。主机名存放在/etc/hostname文件中，修改主机名时，编辑hostname文件，在文件中输入新的主机名并保存该文件即可。重启系统后，参照上面介绍的快速查看主机名的办法来确认主机名有没有修改成功。<br /> <br /> 值的指出的是，在其它Linux发行版中，并非都存在/etc/hostname文件。如Fedora发行版将主机名存放在/etc/sysconfig/network文件中。所以，修改主机名时应注意区分是哪种Linux发行版。<br /> <br /> 3、/etc/hostname与/etc/hosts的区别<br /> /etc/hostname中存放的是主机名，hostname文件的一个例子：<br /> v-jiwan-ubuntu-temp<br /> <br /> /etc/hosts存放的是域名与ip的对应关系，域名与主机名没有任何关系，你可以为任何一个IP指定任意一个名字，hostname文件的一个例子：<br /> 127.0.0.1&nbsp; &nbsp;&nbsp; &nbsp; localhost<br /> 127.0.1.1&nbsp; &nbsp;&nbsp; &nbsp; v-jiwan-ubuntu</p>  </div></div><img src ="http://www.cppblog.com/niewenlong/aggbug/201068.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-06-17 11:21 <a href="http://www.cppblog.com/niewenlong/archive/2013/06/17/201068.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ubuntu12.04 升级 grub error的修复</title><link>http://www.cppblog.com/niewenlong/archive/2013/06/16/201056.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sun, 16 Jun 2013 05:55:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/06/16/201056.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/201056.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/06/16/201056.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/201056.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/201056.html</trackback:ping><description><![CDATA[<div><div><pre>系统： ubuntu12.04 beta (development version) 环境： 这台是测试机，多系统并存在一枚硬盘上(ubunntu12.04/10.04/debian 6/win7/Xen server等等)</pre> <p>几天前通过apt 把ubuntu12.04 beta2升级软件到ubuntu  12.04LTS。升级时，在apt的输出中，看到grub软件包更新有warning，写着&#8220;&#8230;not a good  choice..&#8221;，有不详预感，grub的升级一定出了问题。果然，升级后，启动时，进入grub菜单选择后提示：</p> <blockquote> <p><strong>grub error: no such partition</strong></p> </blockquote> <p>于是有了这篇短文，此方法对<strong> grub rescue</strong> 同样有效</p> <p>&nbsp;</p> <h3>出错原因</h3> <p>grub2在升级过程中出错，重新install一遍即可。问题是，连系统都进入不了，如何reinstall呢？</p> <h3>解决方法</h3> <p>使用u盘或cd等外部系统启动，chroot到原系统后 re-install grub。</p> <h3>步骤</h3>  <p>找一张liveCD的linux系统，发行版任意，ubuntu/fedora/等等，都行。目的是用它启动机器，挂载硬盘，然后chroot回到原来的系统路径。笔者是使用<a title="把每一块SD/TF卡都变为操作系统(Uboot, syslinux)" href="http://sunny-play.com/2012/03/install-uboot-syslinux-to-sd/">SD卡中的tinycore linux</a>启动机器。</p> <p>启动后，检查分区情况，定位你升级失败的ubuntu12.04的根目录安装在哪个分区。</p> <pre>sudo fdisk -l</pre> <p>挂载、绑定所需要的系统设备到原ubuntu12.04系统的分区下</p> <pre># 例如，我的ubuntu12.04的根目录是在/dev/sda6下。  sudo mkdir /mnt/sda6 sudo mount /dev/sda6 /mnt/sda6  sudo mount --bind /dev /mnt/dev sudo mount --bind /proc /mnt/proc sudo mount --bind /sys /mnt/sys</pre> <p>一切就绪后，chroot到原系统下</p> <pre>sudo chroot /mnt/sda6 /bin/bash &nbsp; &nbsp; &nbsp;# 若这里提示不能chroot，请看下面的<a href="http://sunny-play.com/2012/05/ubuntu1204-upgrade-grub-error-fixed/#note1">注1</a></pre> <p>执行grub的恢复 (reinstall)</p> <pre>grub-install /dev/sda &nbsp; &nbsp; &nbsp; # 安装到MBR 或者 grub-install /dev/sda6 &nbsp; &nbsp; &nbsp;# 把grub安装到分区</pre> <p>安装好后，请退出chroot的环境</p> <pre>logout 或者  exit 或者 CTRL-D</pre> <p>退出挂载的设备和分区</p> <pre>sudo umount /mnt/sda6/sys sudo umount /mnt/sda6/proc sudo umount /mnt/sda6/dev sudo umount /mnt/sda6</pre> <p>至此，重启即可。</p> <p>&nbsp;</p> <p><a name="note1"></a>注1：这个过程中，请注意liveCD运行环境和已安装linux版本的兼容性问题，32bit的要使用32bit的liveCD，64bit的要使用64bit的liveCD，否则在chroot时会出现提示：</p> <pre>can't execute 'bin/bash': Exec format error</pre> <p>&nbsp;</p><p><br /></p><p><br /></p><p><br /></p><p><br /></p><p>----------------------------------------------------------------------------</p><p>&nbsp;</p><div><p>自从ubuntu 9.10开始，ubuntu正式开始使用grub2作为引导程序。对于多系统用户，可能有时候会将引导搞丢了（比如双系统下重新安装windows系统等），下面奶牛来介绍下ubuntu等linux系统的grub2的修复。</p> <p>1.需要一张可以引导的ubuntu live-cd，并且版本在9.10+</p> <p>用live-cd引导进入系统，然后在mnt目录下挂载分区。</p> <p>首先我们需要确定一个问题，你的/boot是否单独分区了，如果单独分区了请按照方法A进行，如果/boot没有单独分区，可以按照B来进行。</p> <p>A：以/boot为sda8，/为sda9为例，如果还有其它linux分区也用同样的方法挂上来就可以了。</p> <p>打开终端，</p> <p>sudo su</p> <p>fdisk -l （查看分区内容，并且确定硬盘为sda啊还是sdb，或者hda还是sda）</p> <p>mount /dev/sda9 /mnt</p> <p>mount /dev/sda8 /mnt/boot</p> <p>mount &#8211;bind /dev /mnt/dev</p> <p>mount &#8211;bind /proc /mnt/proc</p> <p>如果还有其它linux分区，用同样的方法挂载上</p> <p>chroot /mnt</p> <p>这时没有意外的话我们就已经进入了ubuntu的系统了</p> <p>sudo grub-install /dev/sda</p> <p>sudo update-grub</p> <p>完工，重启，linux系统应该可以进入了。</p> <p>B:方法与A类似，但是不用挂载/boot分区，所以mount /dev/sda8 /mnt/boot可以省略。其它操作一样。</p> <p>如果在sudo update-grub后出现提示</p> <p>Cannot find list of partitions!</p> <p>请不要慌张，因为在多系统的环境下会出现这个提示，告诉我们无法识别linux之外的windows系统，正常重启还是可以进入linux的，进入系统后就啥都好说了，继续多来一次update-grub就可以了。</p></div>-------------------------------------------------------------<br /><div><p>由于寒假，本站已经相当长时间没有更新了。如今开学自然可充分利用时间，所以现在就讲下我前段时间碰到的一个问题：前阵子我硬盘分区失误，导致系统启动时自动进入<a href="http://www.shelwee.com/html/archives/tag/rescue" title="查看 rescue 中的全部文章" target="_blank">rescue</a>模式。<a href="http://shelwee.com/wp-content/uploads/2011/02/rescue.jpg"><img size-medium=""  wp-image-65180"="" title="rescue" src="http://shelwee.com/wp-content/uploads/2011/02/rescue-300x68.jpg" alt="" height="68" width="300" /></a></p> <p>当时折腾了好些时间，都解决不了，现在就将解决办法晒出来。</p> <p>首先声明一下，要解决此问题必须保证<a href="http://www.shelwee.com/html/archives/tag/grub" title="查看 grub 中的全部文章" target="_blank">grub</a>核心文件core.img还在分区内，然后通过：set，ls，insmod，root，prefix等命令解决。</p> <p>此问题还需要分类解决，分为两种情况：1. /boot 没有单独分区，默认包含在 / 分区；2. /boot 分区有单独分区。</p> <p>第一种情况：</p> <p>先确定<a href="http://www.shelwee.com/html/archives/tag/grub" title="查看 grub 中的全部文章" target="_blank">grub</a>核心文件所在分区</p> <p>ls (hd0,x)/查看(hd0,x)分区目录的文件。（##x为未知数，假如我的<a href="http://www.shelwee.com/html/archives/tag/grub" title="查看 grub 中的全部文章" target="_blank">grub</a>核心文件在(hd0,9),就输入ls (hd0,9)）</p> <div id="_mcePaste">ls (hd0,x)/boot/grub/ 查看(hd0,x)分区/boot/grub目录下文件</div> <p>ls (hd0,x)/boot/ 查看(hd0,x)分区的/boot目录下文件ls (hd0,x)/boot/grub/ 查看(hd0,x)分区/boot/grub目录下文件</p> <p>确定分区之后，执行下列命令：</p> <p>grub <a href="http://www.shelwee.com/html/archives/tag/rescue" title="查看 rescue 中的全部文章" target="_blank">rescue</a>&gt;root=(hd0,x)</p> <p>grub <a href="http://www.shelwee.com/html/archives/tag/rescue" title="查看 rescue 中的全部文章" target="_blank">rescue</a>&gt;prefix=/boot/grub</p> <p>grub rescue&gt;set root=(hd0,x)</p> <p>grub rescue&gt;set prefix=(hd0,x)/boot/grub</p> <p>grub rescue&gt;insmod normal</p> <p>rescue&gt;normal &#8212;&#8212;&#8211;&gt;若出现启动菜单，按c进入命令行模式</p> <p>rescue&gt;linux /boot/vmlinuz-xxx-xxx root=/dev/sdax</p> <p>rescue&gt;initrd /boot/initrd.img-xxx-xxx</p> <p>rescue&gt;boot</p> <p>内核版本号 -xxx-xxx可以按Tab键查看后再手动补全。</p> <p>第二种情况:</p> <p>首先用同样的方法找出 /boot 独立分区(hd0,x)和 / 分区(hd0,y)，然后执行下列命令：</p> <p>grub rescue&gt;root=(hd0,x)</p> <p>grub rescue&gt;prefix=/grub</p> <p>grub rescue&gt;set root=(hd0,x)</p> <p>grub rescue&gt;set prefix=(hd0,x)/grub</p> <p>grub rescue&gt;insmod normal</p> <p>rescue&gt;normal &#8212;&#8212;&#8211;&gt;若出现启动菜单，按c进入命令行模式</p> <p>rescue&gt;linux /vmlinuz-xxx-xxx root=/dev/sday</p> <p>rescue&gt;initrd /initrd.img-xxx-xxx</p> <p>rescue&gt;boot</p> <p>boot启动系统后，再在系统下打开终端，执行命令<a href="http://www.shelwee.com/html/archives/tag/%e4%bf%ae%e5%a4%8d" title="查看 修复 中的全部文章" target="_blank">修复</a>grub&nbsp;重建配置文件grub.cfg</p> <p>sudo update-grub</p> <p>重建grub到第一硬盘mbr</p> <p>sudo grub-install /dev/sda</p> <p>本文大部分数据来源于网络，由于时间已久，来源已无处可寻，如有侵犯到您的著作权，请告知，本站将立即删除！</p></div><br /><p>&nbsp;</p></div></div><img src ="http://www.cppblog.com/niewenlong/aggbug/201056.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-06-16 13:55 <a href="http://www.cppblog.com/niewenlong/archive/2013/06/16/201056.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ubuntu12.04 root用户登录设置</title><link>http://www.cppblog.com/niewenlong/archive/2013/06/15/201018.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Fri, 14 Jun 2013 17:20:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/06/15/201018.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/201018.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/06/15/201018.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/201018.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/201018.html</trackback:ping><description><![CDATA[<div style="border-width: 0px; margin: 0px; list-style: none; color: #333333; font-family: 宋体; line-height: 28px;"><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">Ubuntu12.04 root用户登录设置</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">ubuntu12.04默认是不允许root登录的，在登录窗口只能看到普通用户和访客登录。以普通身份登陆Ubuntu后我们需要做一些修改, &nbsp;www.2cto.com &nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">普通用户登录后，修改系统配置文件需要切换到超级用户模式,在终端窗口里面输入: sudo &nbsp;-s.然后输入普通用户登陆的密码，回车即可进入 root用户权限模式.</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">然后执行: vi /etc/lightdm/lightdm.conf.</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">增加 greeter-show-manual-login=true &nbsp;allow-guest=false &nbsp;. 修改完的整个配置文件是</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">[SeatDefaults]</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">greeter-session=unity-greeter</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">user-session=ubuntu</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">greeter-show-manual-login=true #手工输入登陆系统的用户名和密码</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">allow-guest=false &nbsp; #不允许guest登录</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp; www.2cto.com &nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">然后我们启动root帐号：</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">sudo passwd root</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">根据提示输入roott帐号密码。</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">重启ubuntu，登录窗口会有&#8220;登录&#8221;选项，这时候我们就可以通过root登录了。</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;"><img src="http://www.2cto.com/uploadfile/2012/0728/20120728091012539.png" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none; display: inline; width: 630px; height: 304.5945945945946px;" alt="" /></div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">注意：</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">ubuntu12.04默认使用unity界面，不同的用户体验，但是对于从上一个LTS版本过来的我来说，gnome classic界面更容易上手。</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">首先我们需要安装gnome shell，sudo apt-get install gnome-session-fallback</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">记得在登录框右上选择gnome（classic)</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;"><img src="http://www.2cto.com/uploadfile/2012/0728/20120728091013588.png" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none; display: inline; width: 630px; height: 446.55172413793105px;" alt="" /></div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">需要注意的是，12.04的gnome classic和10.04使用上还是有多不同的地方</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp; www.2cto.com &nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">补充：修改vi /etc/lightdm/lightdm.conf</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">user-session=ubuntu &nbsp; &nbsp;---&gt; &nbsp; &nbsp;user-session=gnome-classic &nbsp; &nbsp; &nbsp;&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">&nbsp;</div><div style="border-width: 0px; margin: 0px; list-style: none; background-color: #ffffff;">默认登录到gnome classic界面,如果不需要特效则是gnome-fallback,对应登录窗口的选项gnome classic(no effects)<br /><br /><br /><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;"><a href="http://www.linuxidc.com/topicnews.aspx?tid=2" target="_blank" title="Ubuntu" style="color: #b32bd5;">Ubuntu</a>默认是关闭root账户，但是可以通过sudo来提升权限，这种做法也是比较安全的做法。在 Ubuntu 12.04 root用户登录设置&nbsp;<a href="http://www.linuxidc.com/Linux/2012-05/60806.htm" target="_blank" style="color: #b32bd5;">http://www.linuxidc.com/Linux/2012-05/60806.htm</a>&nbsp;中介绍过在Ubuntu 12.04中使用root登录。<br />&nbsp;<br />在Ubuntu 12.10中使用root进行登录方法类似。</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">先设定一个root的密码，sudo passwd root</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">1、先设定一个root的密码，sudo passwd root</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;"><img src="http://www.linuxidc.com/upload/2012_11/12111918427876.png" alt="Ubuntu 12.10设置root用户登录图形界面" align="middle" width="581" vspace="5" style="border: 0px; cursor: pointer; display: block;" /></p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">2、root 登陆，su root</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">3、备份一下lightgdm</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">cp -p /etc/lightdm/lightdm.conf /etc/lightdm/lightdm.conf.bak</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">4、编辑lightdm.conf</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">sudo gedit /etc/lightdm/lightdm.conf</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;"><img src="http://www.linuxidc.com/upload/2012_11/12111918424482.png" alt="Ubuntu 12.10设置root用户登录图形界面" align="middle" width="581" vspace="5" style="border: 0px; cursor: pointer; display: block;" /></p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">5、加：</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">greeter-show-manual-login=true</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">修改后为：</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">[SeatDefaults]<br />greeter-session=unity-greeter<br />user-session=ubuntu<br /><span style="color: #ff0000;"><strong>greeter-show-manual-login=true</strong></span></p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;"><img src="http://www.linuxidc.com/upload/2012_11/12111918436804.png" alt="Ubuntu 12.10设置root用户登录图形界面" align="middle" style="border: 0px;" /></p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">重启登陆即可。已经可以输入root了。</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;"><strong>注意：</strong>如果root登陆后还没声音，又查了查，如下方法:</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">Ubuntu root登录没有声音这个问题的根本原因是使用root登录后pulseaudio没有启动。</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">将root加到pulse-access组：</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">sudo usermod -a -G pulse-access root</p><p style="font-family: tahoma, 宋体; line-height: 22px; background-color: #efefef;">然后修改配置文件/etc/default/pulseaudio，将PULSEAUDIO_SYSTEM_START设为1，</p></div></div><img src ="http://www.cppblog.com/niewenlong/aggbug/201018.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-06-15 01:20 <a href="http://www.cppblog.com/niewenlong/archive/2013/06/15/201018.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux下使用find xargs grep查找文件及文件内容</title><link>http://www.cppblog.com/niewenlong/archive/2013/06/07/200843.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Fri, 07 Jun 2013 07:16:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/06/07/200843.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/200843.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/06/07/200843.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/200843.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/200843.html</trackback:ping><description><![CDATA[<p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">1，在某个路径下查文件。</p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">在/etc下查找&#8220;*.log&#8221;的文件</p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">find /etc -name &#8220;*.log&#8221;</p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">2，扩展，列出某个路径下所有文件，包括子目录。</p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">find /etc -name &#8220;*&#8221;</p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">3，在某个路径下查找所有包含&#8220;hello abcserver&#8221;字符串的文件。</p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">find /etc -name &#8220;*&#8221; | xargs grep &#8220;hello abcserver&#8221;</p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">或者find /etc -name &#8220;*&#8221; | xargs grep &#8220;hello abcserver&#8221; &gt; ./cqtest.txt</p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">4，网上摘抄的几个和查找文件或文件内容相关的命令详说：</p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">正则表达式<br style="padding: 0px; margin: 0px;" />\分别表示单词的开始和结束<br style="padding: 0px; margin: 0px;" />ex: \ 以T或者t开头，om结尾的单词<br style="padding: 0px; margin: 0px;" />正则表达式的元字符集：<br style="padding: 0px; margin: 0px;" />1) ^行首 /^love/ 以love开头的行；<br style="padding: 0px; margin: 0px;" />2) $行尾 /love$/ 以love结尾的行；<br style="padding: 0px; margin: 0px;" />3) . /l..e/ 匹配所有这样的行，字母l后面紧跟任意两个字符然后是e的行<br style="padding: 0px; margin: 0px;" />4) * 重复0次或者任意多次前面字符<br style="padding: 0px; margin: 0px;" />5) [x-y] 字符范围<br style="padding: 0px; margin: 0px;" />6) [^x-y] 排除字符范围<br style="padding: 0px; margin: 0px;" />7) \ 转义字符<br style="padding: 0px; margin: 0px;" />&nbsp;\ 界定单词的开头和结尾<br style="padding: 0px; margin: 0px;" />9) \( \) 标记后面用到的匹配字符 \(love\)able \1er=loveable lover<br style="padding: 0px; margin: 0px;" />10) x\{m,n\} 重复字符x至少m此，至多n次<br style="padding: 0px; margin: 0px;" />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br style="padding: 0px; margin: 0px;" />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br style="padding: 0px; margin: 0px;" />grep家族<br style="padding: 0px; margin: 0px;" />RE&#8211;regular expression; g: global; p: print<br style="padding: 0px; margin: 0px;" />出了上面10种元字符集，grep还支持下面的RE<br style="padding: 0px; margin: 0px;" />\w 字母或者数字<br style="padding: 0px; margin: 0px;" />\W 非单词字符（标点符号）<br style="padding: 0px; margin: 0px;" />+ 重复一个或者多个前面的字符<br style="padding: 0px; margin: 0px;" />｜ 或 love(a:b)表示lovea或者lobeb<br style="padding: 0px; margin: 0px;" />？单个字符<br style="padding: 0px; margin: 0px;" />grep返回状态值（$?） 0表示成功，1表示失败，2表示没有找到文件<br style="padding: 0px; margin: 0px;" />rgrep递归访问目录树<br style="padding: 0px; margin: 0px;" />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br style="padding: 0px; margin: 0px;" />ls -l |grep ^d 显示目录<br style="padding: 0px; margin: 0px;" />grep -n -v -# -A# -B#<br style="padding: 0px; margin: 0px;" />-i 不区分大小写<br style="padding: 0px; margin: 0px;" />-n 显示匹配行和行号<br style="padding: 0px; margin: 0px;" />-v只显示不匹配行<br style="padding: 0px; margin: 0px;" />-#显示匹配行上下#行<br style="padding: 0px; margin: 0px;" />-A#匹配行后面打印#行<br style="padding: 0px; margin: 0px;" />-B#匹配行前面打印#行<br style="padding: 0px; margin: 0px;" />-c 只输出匹配行的行数<br style="padding: 0px; margin: 0px;" />-h 查询多文件的时候不显示匹配的文件名字<br style="padding: 0px; margin: 0px;" />-l 查询多文件只显示匹配的文件名<br style="padding: 0px; margin: 0px;" />-s 不显示错误信息<br style="padding: 0px; margin: 0px;" />grep与正则表达式同用<br style="padding: 0px; margin: 0px;" />grep &#8220;^[^abc]&#8221; *.f 提取行首不是abc的行<br style="padding: 0px; margin: 0px;" />grep &#8220;[0-9]\{3\}[8]&#8221; *.f 提取类似xxx8的行，x表示任意数字<br style="padding: 0px; margin: 0px;" />grep &#8220;a\{2\}&#8221; *.f 显示a至少出现两次的行，注意grep是以行处理单位的<br style="padding: 0px; margin: 0px;" />grep -n &#8220;^$&#8221; file 列出空行的行号<br style="padding: 0px; margin: 0px;" />-E参数，可以使用&#8221;与&#8221;和&#8221;或&#8221;模式<br style="padding: 0px; margin: 0px;" />grep -E &#8220;abc | def&#8221; *.f 显示包含abc或者def的行<br style="padding: 0px; margin: 0px;" />ex:<br style="padding: 0px; margin: 0px;" />ls -l | grep &#8220;^$&#8221; 显示目录<br style="padding: 0px; margin: 0px;" />ls -l | grep &#8220;^d&#8221; 显示文件<br style="padding: 0px; margin: 0px;" />ls -l | grep &#8220;^d..x..x..x&#8221; 显示特定权限的目录<br style="padding: 0px; margin: 0px;" />ps aux | grep &#8220;httpd&#8221; |grep -v &#8220;grep&#8221;<br style="padding: 0px; margin: 0px;" />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br style="padding: 0px; margin: 0px;" />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br style="padding: 0px; margin: 0px;" />**使用find和xargs<br style="padding: 0px; margin: 0px;" />1. find pathname -options [-print -exec -ok]<br style="padding: 0px; margin: 0px;" />-optinos<br style="padding: 0px; margin: 0px;" />1)-name:按照文件名查找<br style="padding: 0px; margin: 0px;" />find ~ -name &#8220;*.txt&#8221; -print<br style="padding: 0px; margin: 0px;" />find ~ -name &#8220;[a-z][0-9].txt&#8221; -print<br style="padding: 0px; margin: 0px;" />2)-perm:按照权限查找文件<br style="padding: 0px; margin: 0px;" />find ~ -perm 755 -print 查找权限为755的文件<br style="padding: 0px; margin: 0px;" />find ~ -perm 007 -print 查找o位置上具有7权限的文件<br style="padding: 0px; margin: 0px;" />find ~ -perm 4000 -print 查找具有suid的文件<br style="padding: 0px; margin: 0px;" />3)-prune<br style="padding: 0px; margin: 0px;" />不在当前目录下查找<br style="padding: 0px; margin: 0px;" />4)-user和－nouser<br style="padding: 0px; margin: 0px;" />find ~ -user zhao -print 查找文件属主是zhao的文件<br style="padding: 0px; margin: 0px;" />find ~ -nouser -print 查找文件属主已经被删除的文件<br style="padding: 0px; margin: 0px;" />5)-group和－nogroup<br style="padding: 0px; margin: 0px;" />find ~ -group zhao -print 查找文件群组是zhao的文件<br style="padding: 0px; margin: 0px;" />6)按照时间<br style="padding: 0px; margin: 0px;" />find ~ -mtime -5 -print 文件更改时间在5天内的文件<br style="padding: 0px; margin: 0px;" />find ~ -mtime +3 -print 文件更改时间在3天前的文件<br style="padding: 0px; margin: 0px;" />find ~ -newer file1 -print 查找比文件file1新的文件<br style="padding: 0px; margin: 0px;" />7)按照类型查找<br style="padding: 0px; margin: 0px;" />find ~ -type d -print 查找所有目录<br style="padding: 0px; margin: 0px;" />8)按照大小<br style="padding: 0px; margin: 0px;" />find ~ -size +1000000C -print 查找文件大小大于1000000字节(1M)的文件<br style="padding: 0px; margin: 0px;" />9)查找位于本文件系统里面的文件<br style="padding: 0px; margin: 0px;" />find / -name &#8220;*.txt&#8221; -mount -print<br style="padding: 0px; margin: 0px;" />-exec,-ok:find命令对于匹配文件执行该参数所给出shell命令，相应命令形式为: &#8216;command&#8217; {} \;<br style="padding: 0px; margin: 0px;" />-ok 在执行命令前要确认<br style="padding: 0px; margin: 0px;" />find ~ -type f -exec ls -l {} \;<br style="padding: 0px; margin: 0px;" />find / -name &#8220;*.log&#8221; -mtime +5 -ok rm {} \;<br style="padding: 0px; margin: 0px;" />find . -name core -exec rm {} \;<br style="padding: 0px; margin: 0px;" />使用-x dev参数<br style="padding: 0px; margin: 0px;" />防止find搜索其他分区<br style="padding: 0px; margin: 0px;" />find . -size 0 -exec rm {} \;<br style="padding: 0px; margin: 0px;" />删除尺寸为０的文件<br style="padding: 0px; margin: 0px;" />2. xargs与-exec功能类似<br style="padding: 0px; margin: 0px;" />find ~ -type f | xargs ls -l<br style="padding: 0px; margin: 0px;" />find / -name &#8220;*.log&#8221; -type f -print| xargs grep -i DB0<br style="padding: 0px; margin: 0px;" />find . -type f |xargs grep -i &#8220;Mary&#8221;<br style="padding: 0px; margin: 0px;" />在所有文件中检索字符串Mary<br style="padding: 0px; margin: 0px;" />ls *~ |xargs rm -rf<br style="padding: 0px; margin: 0px;" />删除所有以~结尾的文件<br style="padding: 0px; margin: 0px;" />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br style="padding: 0px; margin: 0px;" />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br style="padding: 0px; margin: 0px;" />SED:<br style="padding: 0px; margin: 0px;" />=====<br style="padding: 0px; margin: 0px;" />sed [options] sedcommand inputfile &gt;outputfile<br style="padding: 0px; margin: 0px;" />sed不接触初始输入文件，对其不做修改，若想保存改动，重要将输出重定向到一个文件即可<br style="padding: 0px; margin: 0px;" />a\: 当前行后面加入一行或者文本<br style="padding: 0px; margin: 0px;" />c\: 用信文本替换本行的文本<br style="padding: 0px; margin: 0px;" />d: 删除一行<br style="padding: 0px; margin: 0px;" />D: 删除模板块的第一行<br style="padding: 0px; margin: 0px;" />i\: 在当前行上面插入文本<br style="padding: 0px; margin: 0px;" />h: 拷贝模板块的内容到内存缓冲区<br style="padding: 0px; margin: 0px;" />H: 追加模板块的内容到内存缓冲区<br style="padding: 0px; margin: 0px;" />g: 获得内存缓冲区内容，并替换当前模板中的文本<br style="padding: 0px; margin: 0px;" />G: 获得内存缓冲区内容，并追加到当前模版块文本的后面<br style="padding: 0px; margin: 0px;" />n: 读取下一个输入行，用下一个命令处理新行而不是第一个命令<br style="padding: 0px; margin: 0px;" />N: 追加下一个输入行到模版块后面，并在二者间插入一个新行，改变当前行的号码<br style="padding: 0px; margin: 0px;" />p: 打印模板块的行<br style="padding: 0px; margin: 0px;" />P: 打印模板块的地一行<br style="padding: 0px; margin: 0px;" />q: 退出sed<br style="padding: 0px; margin: 0px;" />r file: 从file中读行<br style="padding: 0px; margin: 0px;" />!: 表示后面的命令对所有没有选中的行起作用<br style="padding: 0px; margin: 0px;" />s/re/strint/: 用string替换正则表达式re<br style="padding: 0px; margin: 0px;" />=: 打印当前行号<br style="padding: 0px; margin: 0px;" />#command: 把注释扩展到下一个换行符号前<br style="padding: 0px; margin: 0px;" />l 打印匹配行，包括显示控制符号<br style="padding: 0px; margin: 0px;" />**替换标记<br style="padding: 0px; margin: 0px;" />g: 行内全部替换<br style="padding: 0px; margin: 0px;" />p: 打印行<br style="padding: 0px; margin: 0px;" />w: 把行写入一个文件<br style="padding: 0px; margin: 0px;" />x: 互换模板块和缓冲区中的文本<br style="padding: 0px; margin: 0px;" />y: 把一个字符翻译成另外一个字符<br style="padding: 0px; margin: 0px;" />**sed中元字符可以使用正则表达式中所有的<br style="padding: 0px; margin: 0px;" />新加：<br style="padding: 0px; margin: 0px;" />&amp; 保存搜索字符 s/love/**&amp;**/ 用**love**代替love<br style="padding: 0px; margin: 0px;" />**sed定位文本的方式<br style="padding: 0px; margin: 0px;" />x 行号<br style="padding: 0px; margin: 0px;" />x-y 从x行到y行<br style="padding: 0px; margin: 0px;" />/patern/ 查询包括patern的行<br style="padding: 0px; margin: 0px;" />x,y! 不包括指定x-y行号的行<br style="padding: 0px; margin: 0px;" />ex:<br style="padding: 0px; margin: 0px;" />sed &#8216;/Tom/d&#8217; file<br style="padding: 0px; margin: 0px;" />删除包含Tom的行；<br style="padding: 0px; margin: 0px;" />sed &#8216;/Tom/!d&#8217; file<br style="padding: 0px; margin: 0px;" />删除所有不包含Tom的行；<br style="padding: 0px; margin: 0px;" />sed -n /north/p&#8217; file<br style="padding: 0px; margin: 0px;" />打印包含north的行；<br style="padding: 0px; margin: 0px;" />sed &#8216;3d&#8217; file<br style="padding: 0px; margin: 0px;" />删除第三行；<br style="padding: 0px; margin: 0px;" />sed &#8217;3,$d&#8217; file<br style="padding: 0px; margin: 0px;" />删除第三行到最后一行；<br style="padding: 0px; margin: 0px;" />sed &#8216;$d&#8217; file<br style="padding: 0px; margin: 0px;" />删除最后一行；<br style="padding: 0px; margin: 0px;" />sed &#8216;/north/d&#8217; file<br style="padding: 0px; margin: 0px;" />删除包含north的行；<br style="padding: 0px; margin: 0px;" />sed -n &#8216;s/west/north/g&#8217; file<br style="padding: 0px; margin: 0px;" />替换所有west为north；<br style="padding: 0px; margin: 0px;" />sed -n &#8216;s/^west/north/p&#8217; file<br style="padding: 0px; margin: 0px;" />一行的开头的west用north替换，并打印发生替换的行；<br style="padding: 0px; margin: 0px;" />sed &#8216;s/[0-9][0-9]$/&amp;.5/&#8217; file<br style="padding: 0px; margin: 0px;" />所有以两个数字结尾的行，最后两个数字被他们自己替换并附加.5；<br style="padding: 0px; margin: 0px;" />sed -n &#8216;s/\(Mar\)got/\1ianne/p&#8217; file<br style="padding: 0px; margin: 0px;" />将Margot替换为Marianne，并打印发生替换的行；<br style="padding: 0px; margin: 0px;" />sed &#8216;s#abc#ABC#g&#8217; file<br style="padding: 0px; margin: 0px;" />所有abc由ABC替换，（所有s后面紧跟的字符都被认为是新的分隔符）；<br style="padding: 0px; margin: 0px;" />sed &#8216;/west/,/east/p&#8217; file<br style="padding: 0px; margin: 0px;" />打印包含west行和包含east行中间的所有行；<br style="padding: 0px; margin: 0px;" />sed &#8217;1,/east/s/$/**A**/&#8217; file<br style="padding: 0px; margin: 0px;" />地一行和包含east行之间的所有行的行尾加上字符串**A**；<br style="padding: 0px; margin: 0px;" />sed -e &#8217;1,3d&#8217; -e &#8216;s/aa/bb/&#8217; file<br style="padding: 0px; margin: 0px;" />先删除1到3行，然后用bb替换aa；<br style="padding: 0px; margin: 0px;" />sed &#8216;/Sam/r file1&#8242; file<br style="padding: 0px; margin: 0px;" />将文件file1中的内容附加在包含Sam的行后面；<br style="padding: 0px; margin: 0px;" />sed &#8216;/Sam/w file1&#8242; file<br style="padding: 0px; margin: 0px;" />将还有Sam行写入文件file1中；<br style="padding: 0px; margin: 0px;" />sed &#8216;/^north /a\new line second line&#8217; file<br style="padding: 0px; margin: 0px;" />所有以north加空格开头的行后面附加上两行文本，a\表示追加文本，\表示换行(tcsh中需要，bash中不需要)；<br style="padding: 0px; margin: 0px;" />sed &#8216;/^north/i\new line&#8217; file<br style="padding: 0px; margin: 0px;" />在行首为north的行前面插入一个新行；<br style="padding: 0px; margin: 0px;" />sed &#8216;/norht/{n; s/aa/bb/;}&#8217; file<br style="padding: 0px; margin: 0px;" />首先匹配含有north的行，然后执行一组命令，n表示移到下一行，并用bb代替aa；<br style="padding: 0px; margin: 0px;" />sed &#8217;1,3g/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/&#8217; file<br style="padding: 0px; margin: 0px;" />将1到3行中的所有小写字母用大写字母替换；<br style="padding: 0px; margin: 0px;" />sed &#8216;/Lewis/{s/Lewis/bbb;q;}&#8217; file<br style="padding: 0px; margin: 0px;" />首先找到匹配Lewis的行，然后用bbb代替Lewis，接着q退出seq；<br style="padding: 0px; margin: 0px;" />sed -e &#8216;/north/h&#8217; -e &#8216;$G&#8217; file<br style="padding: 0px; margin: 0px;" />首先找到包含norht的行，h拷贝到内存缓冲区，然后到文件随后一行($)，G附加在最后一行后面；<br style="padding: 0px; margin: 0px;" />sed -e &#8216;/we/{h;d;}&#8217; -e &#8216;/ct/{G:}&#8217; file<br style="padding: 0px; margin: 0px;" />查找包含we的行，拷贝并且删除他，然后查找包含ct的行，将拷贝内容附加到他后面；<br style="padding: 0px; margin: 0px;" />sed -e &#8216;/north/h&#8217; -e &#8216;$g&#8217; file<br style="padding: 0px; margin: 0px;" />首先找到包含norht的行，h拷贝到内存缓冲区，然后到文件随后一行并覆盖他；<br style="padding: 0px; margin: 0px;" />sed -n &#8216;l&#8217; file<br style="padding: 0px; margin: 0px;" />打印所有包含不能打印字符的行。<br style="padding: 0px; margin: 0px;" />sed -n &#8216;/.*ing/p&#8217; file<br style="padding: 0px; margin: 0px;" />显示含有以ing结尾单词的行；<br style="padding: 0px; margin: 0px;" />sed -n &#8216;/music/=&#8217; file<br style="padding: 0px; margin: 0px;" />打印含有music的行号；<br style="padding: 0px; margin: 0px;" />sed &#8216;^$d&#8217; file<br style="padding: 0px; margin: 0px;" />删除空行<br style="padding: 0px; margin: 0px;" />sed &#8216;s/^/abcd/g&#8217; file<br style="padding: 0px; margin: 0px;" />在行首填加abcd<br style="padding: 0px; margin: 0px;" />sed &#8216;s/$/abcd/g&#8217; file<br style="padding: 0px; margin: 0px;" />在行尾填加abcd<br style="padding: 0px; margin: 0px;" />sed &#8216;s/rm$/played &amp;/g&#8217; file<br style="padding: 0px; margin: 0px;" />&amp;表示在替换的时候保留被替换的词(rm&#8211;played rm)<br style="padding: 0px; margin: 0px;" />sed &#8216;s/^M//g&#8217; file<br style="padding: 0px; margin: 0px;" />去掉行尾的^M (^M的输入，先按ctrl+v然后按enter即可即可)<br style="padding: 0px; margin: 0px;" />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br style="padding: 0px; margin: 0px;" />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br style="padding: 0px; margin: 0px;" />gawk程序：<br style="padding: 0px; margin: 0px;" />awk [-F 域分隔符] &#8216;commands&#8217; inputfile<br style="padding: 0px; margin: 0px;" />awk执行时，其域标志符为$1,$2,$3&#8230;&#8230;&#8230;$n，$0表示所有的域<br style="padding: 0px; margin: 0px;" />awk -v var=value 赋值给一个用户定义的变量<br style="padding: 0px; margin: 0px;" />awk &#8216;pattern&#8217; file<br style="padding: 0px; margin: 0px;" />awk &#8216;{action}&#8217; file<br style="padding: 0px; margin: 0px;" />awk &#8216;pattern {action}&#8217; file<br style="padding: 0px; margin: 0px;" />ex：<br style="padding: 0px; margin: 0px;" />awk &#8216;{print $0}&#8217; file<br style="padding: 0px; margin: 0px;" />打印所有的域<br style="padding: 0px; margin: 0px;" />awk &#8216;/Mary/&#8217; file<br style="padding: 0px; margin: 0px;" />打印包含file中包含Mary的行；<br style="padding: 0px; margin: 0px;" />awk &#8216;{print $1}&#8217; file<br style="padding: 0px; margin: 0px;" />打印文件的第一列（第一个域）；<br style="padding: 0px; margin: 0px;" />awk &#8216;/Mary/ {print $1,$2}&#8217; file<br style="padding: 0px; margin: 0px;" />打印文件file包含Mary的行的第一和第二个域；<br style="padding: 0px; margin: 0px;" />df | awk &#8216;S4&gt;75000&#8242;<br style="padding: 0px; margin: 0px;" />打印可用空间大于75000的文件系统<br style="padding: 0px; margin: 0px;" />date | awk &#8216;{print &#8221; month:&#8221;, $2, &#8220;\n year:&#8221; $6}&#8217;<br style="padding: 0px; margin: 0px;" />格式化date的输出；<br style="padding: 0px; margin: 0px;" />awk &#8216;BEGIN{OFMT=&#8221;%.2f&#8221;; print 1.25463}&#8217;<br style="padding: 0px; margin: 0px;" />指定数字输出格式，小数点后面保留两位有效数(1.25)；<br style="padding: 0px; margin: 0px;" />awk &#8216;/[ab]cdef/&#8217; file<br style="padding: 0px; margin: 0px;" />打印匹配acdef或者bcdef的行；<br style="padding: 0px; margin: 0px;" />awk &#8216;{print NR, $0}&#8217; file<br style="padding: 0px; margin: 0px;" />awk &#8216;{print $0, NR}&#8217; file<br style="padding: 0px; margin: 0px;" />NR当前记录数，每处理一个记录NR就加1<br style="padding: 0px; margin: 0px;" />上面的命令相当于在每一行后面加上一个行号；<br style="padding: 0px; margin: 0px;" />NF则记录每一行的域的个数；<br style="padding: 0px; margin: 0px;" />awk -F &#8216;[ :\t]&#8216; &#8216;{print $0}&#8217; file<br style="padding: 0px; margin: 0px;" />指定域分隔符为空格、:或者tab<br style="padding: 0px; margin: 0px;" />awk &#8216;/^[A-Z][a-z]+/&#8217; file<br style="padding: 0px; margin: 0px;" />打印所有以一个大写字母开头，然后是一个或者多个小写字母的行；<br style="padding: 0px; margin: 0px;" />awk &#8216;$1~/[Bb]ill/&#8217; file<br style="padding: 0px; margin: 0px;" />第一个域匹配Bill或者bill的行；<br style="padding: 0px; margin: 0px;" />awk &#8216;$1!~/ly$/&#8217; file<br style="padding: 0px; margin: 0px;" />第一个域末尾不是ly的行；<br style="padding: 0px; margin: 0px;" />awk &#8216;/^(No|no)/&#8217; file<br style="padding: 0px; margin: 0px;" />打印行首为No或者no的行；<br style="padding: 0px; margin: 0px;" />awk &#8216;BEGIN {print &#8220;file head \n&#8221;} {print $1 \t $4}&#8217; file<br style="padding: 0px; margin: 0px;" />awk &#8216;BEGIN {print &#8220;file head \n&#8221;} {print $1 \t $4}&#8217; file |tee out.file<br style="padding: 0px; margin: 0px;" />打印文件的时候附加一个文件头<br style="padding: 0px; margin: 0px;" />awk &#8216;BEGIN {print &#8220;file head \n&#8221;} {print $1 \t $4} END {print &#8220;end of file&#8221;}&#8217; file<br style="padding: 0px; margin: 0px;" />打印文件的时候附加一个文件头和文件尾<br style="padding: 0px; margin: 0px;" />awk中使用正则表达式<br style="padding: 0px; margin: 0px;" />awk &#8216;{if($1~/hello/) print $0}&#8217; file<br style="padding: 0px; margin: 0px;" />如果域1中包含hello，就打印所有的域<br style="padding: 0px; margin: 0px;" />~//表示匹配正则表达式，!~//表示不匹配正则表达式<br style="padding: 0px; margin: 0px;" />awk &#8216;{if($6,&gt;=,==,!=,~,!~（匹配，不匹配）<br style="padding: 0px; margin: 0px;" />awk &#8216;$3==5346&#8242; file<br style="padding: 0px; margin: 0px;" />第三个域等于5346，就打印出该行；<br style="padding: 0px; margin: 0px;" />awk &#8216;$3&gt;5000 {print $1}&#8217; file<br style="padding: 0px; margin: 0px;" />第三个域大于5000就打印该行第一个域<br style="padding: 0px; margin: 0px;" />awk &#8216;{max={$1&gt;$2}?$1:$2; print max}&#8217; file<br style="padding: 0px; margin: 0px;" />如果第一个域大于第二个域，max=$1否则=$2，打印最大值<br style="padding: 0px; margin: 0px;" />awk &#8216;{print ($1==11?&#8221;high\t&#8221; $2:&#8221;low\t&#8221; $2)}&#8217; file<br style="padding: 0px; margin: 0px;" />&amp;&amp;逻辑和，||逻辑或，!逻辑非<br style="padding: 0px; margin: 0px;" />awk &#8216;$2==$5 &amp;&amp; $3&gt;5&#8242; file<br style="padding: 0px; margin: 0px;" />awk &#8216;/Tom/,/Jary/&#8217; file<br style="padding: 0px; margin: 0px;" />Tom第一次出现和Jary第一次出现之间的所有行；<br style="padding: 0px; margin: 0px;" />awk &#8216;/north/ {print $3+10}&#8217; file<br style="padding: 0px; margin: 0px;" />包含north行的地三个域加10；<br style="padding: 0px; margin: 0px;" />awk &#8216;$3==&#8221;aa&#8221; {$2=&#8221;dd&#8221;; print $0}&#8217; file<br style="padding: 0px; margin: 0px;" />将地三个域为aa的行的第二域变成dd，并打印该行；<br style="padding: 0px; margin: 0px;" />**awk编程：<br style="padding: 0px; margin: 0px;" />使用变量<br style="padding: 0px; margin: 0px;" />awk &#8216;$1~/Tom/ {wage=$2+$3; print wage}&#8217; file<br style="padding: 0px; margin: 0px;" />先扫描第一个域，如果匹配Tom，就将第二和第三域的总和赋值给变量wage并输出；<br style="padding: 0px; margin: 0px;" />awk &#8216;BEGIN{FS=&#8221;:&#8221;; OFS=&#8221;\t&#8221;;ORS=&#8221;\n\n&#8221;}{print $0}&#8217; file<br style="padding: 0px; margin: 0px;" />处理文件前设置<br style="padding: 0px; margin: 0px;" />域分隔符(FS)为(:)<br style="padding: 0px; margin: 0px;" />输出域分隔(OFS)为(\t)<br style="padding: 0px; margin: 0px;" />输出记录分隔符(ORS)为(\n\n)<br style="padding: 0px; margin: 0px;" />awk &#8216;END{print &#8220;The number of record is:&#8217; NR}&#8217; file<br style="padding: 0px; margin: 0px;" />处理完文件后执行END语句<br style="padding: 0px; margin: 0px;" />输出总记录数<br style="padding: 0px; margin: 0px;" />awk &#8216;/Mary/{count++} END{print &#8220;Mary was found&#8221; count &#8220;times&#8221;}&#8217; file<br style="padding: 0px; margin: 0px;" />计数文件中Mary出现的次数；<br style="padding: 0px; margin: 0px;" />**awk输入输出重定向<br style="padding: 0px; margin: 0px;" />awk &#8216;$4&gt;=70 {print $1, $2 &gt;&#8221;outfile&#8221;}&#8217; file<br style="padding: 0px; margin: 0px;" />结果重定向到文件outfile中<br style="padding: 0px; margin: 0px;" />awk &#8216;BEGIN{&#8220;date&#8221; |getline d; print d}&#8217;<br style="padding: 0px; margin: 0px;" />将date结果输给getline函数，并打印<br style="padding: 0px; margin: 0px;" />(getline从标准输出，管道等获得输入)<br style="padding: 0px; margin: 0px;" />awk &#8216;BEGIN{&#8220;date&#8221; |getline d; split(d,mon); print mon[1] mon[2]}&#8217;<br style="padding: 0px; margin: 0px;" />将date结果输给getline函数，slpit将d分解成数组，打印数组第2个变量<br style="padding: 0px; margin: 0px;" />**split函数：split(string,array,field seperator)<br style="padding: 0px; margin: 0px;" />awk &#8216;BEGIN{while(&#8220;ls&#8221;|getline) print}&#8217;<br style="padding: 0px; margin: 0px;" />依次输出ls的每一项<br style="padding: 0px; margin: 0px;" />awk<br style="padding: 0px; margin: 0px;" />&#8216;BEGIN{print &#8220;what is your name?&#8221;; getline name 0) {lc++; print lc &#8221; &#8221; a}}&#8217;<br style="padding: 0px; margin: 0px;" />awk &#8216;BEGIN{while(getline a 0) {lc++; print lc}}&#8217;<br style="padding: 0px; margin: 0px;" />如果文件不存在，getline返回-1<br style="padding: 0px; margin: 0px;" />到达文件尾返回0<br style="padding: 0px; margin: 0px;" />读到一行返回1<br style="padding: 0px; margin: 0px;" />读取文件/etc/passwd，计数行数<br style="padding: 0px; margin: 0px;" />**awk控制语句<br style="padding: 0px; margin: 0px;" />if语句：<br style="padding: 0px; margin: 0px;" />awk &#8216;{if($6&gt;50) print $1 &#8220;too high&#8221;}&#8217; file<br style="padding: 0px; margin: 0px;" />awk &#8216;{if($6&gt;20 &amp;&amp; $250}{x++; print x} else {y++;print y}&#8217; file<br style="padding: 0px; margin: 0px;" />awk &#8216;{if($1~/peter/){next} else {print}}&#8217; file<br style="padding: 0px; margin: 0px;" />如果第一个域包含peter，awk就忽略这一行，读取文件的下一行，脚本从头开始执行；<br style="padding: 0px; margin: 0px;" />循环语句：<br style="padding: 0px; margin: 0px;" />awk &#8216;{i=1; while(i file<br style="padding: 0px; margin: 0px;" />cat -v file 显示文件，包括其中的控制符(-v)<br style="padding: 0px; margin: 0px;" />cat -n file 为每一行编号<br style="padding: 0px; margin: 0px;" />cat -b file 每个非空行编号<br style="padding: 0px; margin: 0px;" />cat -T file 以^I显示tab<br style="padding: 0px; margin: 0px;" />3.<br style="padding: 0px; margin: 0px;" />管道 | 把一个命令的输出传递给另外一个命令为输入<br style="padding: 0px; margin: 0px;" />ex:<br style="padding: 0px; margin: 0px;" />ls | grep file.doc<br style="padding: 0px; margin: 0px;" />查找文件file.doc<br style="padding: 0px; margin: 0px;" />who | awk &#8216;{print $1 &#8220;\t&#8221; $2}&#8217; 只显示用户名和所在终端<br style="padding: 0px; margin: 0px;" />df -h | awk &#8216;{print $1}&#8217; |grep -v &#8220;filesystem&#8221; (-v表示输出不包括filesystem的项目)<br style="padding: 0px; margin: 0px;" />df -h | awk &#8216;{print $1}&#8217; |grep -v &#8220;filesystem&#8221; |sed &#8216;s/\/dev\///g&#8217; 显示设备的时候不显示/dev/<br style="padding: 0px; margin: 0px;" />4.tee<br style="padding: 0px; margin: 0px;" />who | tee who.txt 输出到屏幕的同时输出到文件<br style="padding: 0px; margin: 0px;" />who | tee -a who.txt 附加在文件的后面<br style="padding: 0px; margin: 0px;" />5.文件重定向<br style="padding: 0px; margin: 0px;" />ls -l |grep ^d &gt;file.out 所有目录名字重定向到一个文件<br style="padding: 0px; margin: 0px;" />cat /etc/passwd | awk -F: &#8216;{print $1}&#8217; |sort &gt;a.out (-F:指定分隔符为:)<br style="padding: 0px; margin: 0px;" />cat &gt;file.out reboot<br style="padding: 0px; margin: 0px;" />at&gt; ctrl+D<br style="padding: 0px; margin: 0px;" />3小时后reboot<br style="padding: 0px; margin: 0px;" />3.<br style="padding: 0px; margin: 0px;" />bc &#8211; 计算器<br style="padding: 0px; margin: 0px;" />scale=3 设置小数点后数字为数<br style="padding: 0px; margin: 0px;" />ibase=2 二进制运算<br style="padding: 0px; margin: 0px;" />4.<br style="padding: 0px; margin: 0px;" />ls -d dir<br style="padding: 0px; margin: 0px;" />只显示目录而不显示其下面的文件。<br style="padding: 0px; margin: 0px;" />5.<br style="padding: 0px; margin: 0px;" />sync<br style="padding: 0px; margin: 0px;" />更新superblock并把它写入硬盘<br style="padding: 0px; margin: 0px;" />6.<br style="padding: 0px; margin: 0px;" />scp&nbsp;<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#117;&#115;&#101;&#114;&#64;&#104;&#111;&#115;&#116;&#58;&#47;&#112;&#97;&#116;&#104;&#47;&#102;&#105;&#108;&#101;&#49;" style="padding: 0px; margin: 0px; color: #67581d; text-decoration: none;">user@host:/path/file1</a>&nbsp;<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#117;&#115;&#101;&#114;&#64;&#104;&#111;&#115;&#116;&#58;&#47;&#112;&#97;&#116;&#104;&#47;&#102;&#105;&#108;&#101;" style="padding: 0px; margin: 0px; color: #67581d; text-decoration: none;">user@host:/path/file</a><br style="padding: 0px; margin: 0px;" />服务器间拷贝文件</p>****************************************************************************************<br /><span style="font-family: Arial; background-color: #ffffff;">当我们要查找文件中某些内容，或者在显示文件名时过滤出某一种类的文件，这时就需要用到grep。因为支持正则表达式，使得grep命令的搜索功能非常强大，它是使用好linux必须掌握的一个命令。</span><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">一、常用命令</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">grep&nbsp; 999&nbsp; **/*　列出当前目录(包括子目录)中所有含有999字符的行。</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">grep&nbsp; '999'&nbsp; server.log　列出server.log中含有999字符的行。将999去掉引号或换成双引号，效果一样。</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">grep&nbsp; -c&nbsp; '999'&nbsp; server*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;统计所有以server开头的文件中，含有999字符的行数（注：不是个数）</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">grep&nbsp; '999'&nbsp; aa.txt&nbsp; bb.txt&nbsp; cc.txt　显示aa.txt, bb.txt, cc.txt三文件中含有999字符的行。</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">grep&nbsp; '[a-z]\{5\}'&nbsp; server.log　利用正则表达式来搜索文件。正则表达式的详细说明见后面。</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">grep '2006-08-23 17:50:[0-1][0-9]' wxxr.boss.log　搜索某日某分00秒到19秒之间的日志</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">ls | grep 'server'　这里是在通道里来使用grep，将ls显示的文件名，过滤出含有server字符的文件名。</span><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">二、参数</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;匹配行上下2行也显示出来</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-b&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在行之前显示此行所在的字符号（字符号指：在此之前字符的字符数）</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;匹配行的行数</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-f&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;从某文件中提取要匹配的字符，如：grep&nbsp; -f&nbsp; abc&nbsp; server.log从abc文件中提取要搜索的字符</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">　　（注：abc中可以有多行，每行是"或"的关系，即列出各行字符所匹配的内容。所有匹配行按照其在文件中的顺序显示，即不按abc中的匹配字符来分类显示）</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当搜索多个文件时，不显示每行之前的文件名前缀。</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 忽略搜索字符的大小写</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 显示匹配搜索字符的文件的文件名</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-L&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;显示不匹配搜索字符的文件的文件名</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在每行前加上行号</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 不显示关于不存在或者无法读取文件的错误信息。</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-v&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 显示所有不匹配的行。</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">-w&nbsp;&nbsp;&nbsp;&nbsp; 把搜索字符当作一个完整单词来匹配</span><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">三、正则表达式</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">^jboss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;匹配所有以jboss开头的行&nbsp;</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">jboss$&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;匹配所有以jboss结尾的行</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">jbo.s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.表示任意一字符，匹配jboss, jbo7s，不匹配jbos。&nbsp;</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">jbo*s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *表示0或多个的前一字符，匹配jbs, jbos, jboos, jboooos</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">jbo[sa]s&nbsp;&nbsp;&nbsp;&nbsp;[] 指定字符范围，匹配jboss, jboas</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">jbo[^sb]s&nbsp;&nbsp;[^]指定不允许匹配的字符范围，不匹配jboss, jbobs</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">x\{2\}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 匹配2个x字符，即匹配字符xx&nbsp;</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">x\{2,\}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至少匹配2个x字符</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">x\{2,4\}&nbsp;&nbsp;&nbsp; 匹配2－4个x</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">\w&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;匹配文字和数字字符，和[A-Za-z0-9]等价</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">\W&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;与\w相反，匹配一个或多个非文字和非数字字符，如点号句号等。</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">\bjboss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;匹配单词，如jboss, jboss888，但不匹配8jboss。也就是jboss之前必须是空格或逗句号等。</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">[0-9]{11}&nbsp; 11个数字</span><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">四、egrep（等价于grep -E）扩展支持的正则表达式</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">c+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;匹配一个或多个c字符。[a-c]+，则匹配一个或多个a或b或c字符。</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">c?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;匹配零个或多个c字符</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">a|b&nbsp;&nbsp;&nbsp;&nbsp; 匹配a或b</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;分组符号，作用类似算术里的()</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">x{2},x{2,},x{2,4}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;作用等同于没有用-E参数时的x\{2\},x\{2,\},x\{2,4\}</span><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">五、fgrep（等价于grep -F）</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">当搜索字符里包含有正则表达式的专用符号，然而我们却不想启用正则表达式，就是搜索原字符，这时就可以用grep -F。例：grep&nbsp; -F&nbsp; 'jbo[^sb]s'&nbsp; server.log ，搜索server.log里包含'jbo[^sb]s的字符（＾[]不再是正则表达式里的专用字符）</span><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">六、其他</span><br style="font-family: Arial; background-color: #ffffff;" /><span style="font-family: Arial; background-color: #ffffff;">和其他命令相结合，可把grep用作一个过滤器。比如我们监控日志时，我们只关心某一个包下的日志，这时我们可以这样来写：tail&nbsp; -f&nbsp; server.log | grep 'com.wxxr.chengang'</span><br style="font-family: Arial; background-color: #ffffff;" /><img src ="http://www.cppblog.com/niewenlong/aggbug/200843.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-06-07 15:16 <a href="http://www.cppblog.com/niewenlong/archive/2013/06/07/200843.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Git 快速参考</title><link>http://www.cppblog.com/niewenlong/archive/2013/06/07/200840.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Fri, 07 Jun 2013 05:41:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/06/07/200840.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/200840.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/06/07/200840.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/200840.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/200840.html</trackback:ping><description><![CDATA[<h1><span style="font-size: large; font-family: 宋体;">1.&nbsp;</span><span style="font-size: large; font-family: 宋体;">创建一个新的版本库</span></h1><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">从一个压缩包中创建：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ tar xzf project.tar.gz</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ cd project</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git init #Initialized empty Git repository in .git/</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git add .</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git commit</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">从远程版本库创建：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git clone git://example.com/pub/project.git</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ cd project</span></span></span></pre><h2><a name="t1" style="color: rgb(51, 102, 153);"></a><span style="font-size: large; font-family: 宋体;">2.&nbsp;</span><span style="font-size: large; font-family: 宋体;">管理分支</span></h2><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git branch&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # list all local branches in this repo</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git checkout test&nbsp; # switch working directory to branch "test"</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git branch new&nbsp;&nbsp;&nbsp;&nbsp; # create branch "new" starting at current HEAD</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git branch -d new&nbsp; # delete branch "new"</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">创建一个不以当前的&nbsp;HEAD&nbsp;为起点的分支，用：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git branch new test&nbsp;&nbsp;&nbsp; # branch named "test"</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git branch new v2.6.15 # tag named v2.6.15</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git branch new HEAD^&nbsp;&nbsp; # commit before the most recent</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git branch new HEAD^^&nbsp; # commit before that</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git branch new test~10 # ten commits before tip of branch "test"</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">创建并同时切换至新的分支：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git checkout -b new v2.6.15</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">更新和检验从远程版本库中克隆过来的分支：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git fetch&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # update</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git branch -r&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # list</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp; origin/master</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp; origin/next</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp; ...</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git checkout -b masterwork origin/master</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">从不同的版本库中抓取分支，并给予一个在你的版本库中新的分支名称：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git fetch git://example.com/project.git theirbranch:mybranch</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git fetch git://example.com/project.git v2.6.15:mybranch</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">给你要定期地协同工作的版本库制作一个列表：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git remote add example git://example.com/project.git</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git remote&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # list remote repositories</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">example</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">origin</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git remote show example&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # get details</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">* remote example</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp; URL: git://example.com/project.git</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp; Tracked remote branches</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp;&nbsp;&nbsp; master</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp;&nbsp;&nbsp; next</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp;&nbsp;&nbsp; ...</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git fetch example&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # update branches from example</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git branch -r&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # list all remote branches</span></span></span></pre><h2><a name="t2" style="color: rgb(51, 102, 153);"></a><span style="font-size: large; font-family: 宋体;">3.&nbsp;</span><span style="font-size: large; font-family: 宋体;">勘查历史</span></h2><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ gitk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # visualize and browse history</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git log&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # list all commits</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git log src/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # ...modifying src/</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git log v2.6.15..v2.6.16&nbsp; # ...in v2.6.16, not in v2.6.15</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git log master..test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # ...in branch test, not in branch master</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git log test..master&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # ...in branch master, but not in test</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git log test...master&nbsp;&nbsp;&nbsp;&nbsp; # ...in one branch, not in both</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git log -S'foo()'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # ...where difference contain "foo()"</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git log --since="2 weeks ago"</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git log -p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # show patches as well</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git show&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # most recent commit</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git diff v2.6.15..v2.6.16 # diff between two tagged versions</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git diff v2.6.15..HEAD&nbsp;&nbsp;&nbsp; # diff with current head</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git grep "foo()"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # search working directory for "foo()"</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git grep v2.6.15 "foo()"&nbsp; # search old tree for "foo()"</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git show v2.6.15:a.txt&nbsp;&nbsp;&nbsp; # look at old version of a.txt</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">查找撤退点：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git bisect start</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git bisect bad&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # current version is bad</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git bisect good v2.6.13-rc2&nbsp;&nbsp; # last known good revision</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">Bisecting: 675 revisions left to test after this</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # test here, then:</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git bisect good&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # if this revision is good, or</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git bisect bad&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # if this revision is bad.</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# repeat until done.</span></span></span></pre><h2><a name="t3" style="color: rgb(51, 102, 153);"></a><span style="font-size: large; font-family: 宋体;">4.&nbsp;</span><span style="font-size: large; font-family: 宋体;">制作变更</span></h2><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">配置&nbsp;git</span></span></strong></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><span style="font-size: small; font-family: 宋体;">vi ~/.gitconfig</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small; font-family: 宋体;">[user]</span></span><br /><span style="font-size: small;"><span style="font-family: 宋体;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;">&nbsp;&nbsp;&nbsp; name = Phoenix<br />&nbsp;&nbsp;&nbsp; email = phoenixtoday@gmail.com<br />[alias]<br />&nbsp; co = checkout<br />&nbsp; ci = commit -a<br />&nbsp; st = status<br />&nbsp; br = branch<br />&nbsp; oneline = log --pretty=oneline --since='2 days ago'<br />&nbsp; onelog = log -p -1<br />[color]<br />&nbsp; status = auto<br />&nbsp; branch = auto<br />&nbsp; ui = auto</span></span></span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">选择这下次提交的时候要包含那些文件，接着制作交付：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git add a.txt&nbsp;&nbsp;&nbsp; # updated file</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git add b.txt&nbsp;&nbsp;&nbsp; # new file</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git rm c.txt&nbsp;&nbsp;&nbsp;&nbsp; # old file</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git commit</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">或者是准备提交和创建交付一步完成：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git commit d.txt # use latest content only of d.txt</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git commit -a&nbsp;&nbsp;&nbsp; # use latest content of all tracked files</span></span></span></pre><h2><a name="t4" style="color: rgb(51, 102, 153);"></a><span style="font-size: large; font-family: 宋体;">5.&nbsp;</span><span style="font-size: large; font-family: 宋体;">合并</span></h2><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git merge test&nbsp;&nbsp; # merge branch "test" into the current branch</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git pull git://example.com/project.git master</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # fetch and merge in remote branch</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git pull . test&nbsp; # equivalent to git merge test</span></span></span></pre><h2><a name="t5" style="color: rgb(51, 102, 153);"></a><span style="font-size: large; font-family: 宋体;">6.&nbsp;</span><span style="font-size: large; font-family: 宋体;">共享你的变更</span></h2><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">引入或者导出补丁：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git format-patch origin..HEAD # format a patch for each commit</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # in HEAD but not in origin</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git am mbox # import patches from the mailbox "mbox"</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">抓取一个不同的&nbsp;git&nbsp;版本库的分支，并合并进当前分支：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git pull git://example.com/project.git theirbranch</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">在合并至当前分支之前，将远程分支的变更保存为本地的分支：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git pull git://example.com/project.git theirbranch:mybranch</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">创建了本地分支的交付之后，用这些交付更新远程分支。</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git push ssh://example.com/project.git mybranch:theirbranch</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">当本地和远程分支都是叫&nbsp;"test"&nbsp;时：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git push ssh://example.com/project.git test</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">对于经常通讯的远程版本库，有快捷命令的版本：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git remote add example ssh://example.com/project.git</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git push example test</span></span></span></pre><h2><a name="t6" style="color: rgb(51, 102, 153);"></a><span style="font-size: large; font-family: 宋体;">7.&nbsp;</span><span style="font-size: large; font-family: 宋体;">版本库的维护</span></h2><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">检查损坏：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git fsck</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">重新打包，删除无用的杂物：</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git gc</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><h2><a name="t7" style="color: rgb(51, 102, 153);"></a><span style="font-size: large; font-family: 宋体;">8.&nbsp;</span><span style="font-size: large; font-family: 宋体;">其它</span></h2><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">忽略某些文件及目录</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ vi .gitignore</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">可以使用通配符，目录最后不要加斜杠。</span></span></strong></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong>&nbsp;</strong></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">丢弃当前所有未提交内容</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">$ git reset --hard HEAD</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong>&nbsp;</strong></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong><span style="font-size: small;"><span style="font-family: 宋体;">有未提交内容时快速切换到另一分支</span></span></strong></p><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">git stash save "work in progress for foo feature"</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">切换到另一分支，并修改、提交&#8230;</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">切换回原来分支</span></span></span></pre><pre style="white-space: pre-wrap; word-wrap: break-word; color: #333333; line-height: 26px; background-color: #ffffff;"><span style="background-color: #b6d7a8; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: small;"><span style="font-family: 宋体;">git stash apply</span></span></span></pre><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; margin: auto 0cm;"><strong>&nbsp;</strong></p><img src ="http://www.cppblog.com/niewenlong/aggbug/200840.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-06-07 13:41 <a href="http://www.cppblog.com/niewenlong/archive/2013/06/07/200840.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>git-svn 简单教程</title><link>http://www.cppblog.com/niewenlong/archive/2013/06/04/200791.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Tue, 04 Jun 2013 04:16:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/06/04/200791.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/200791.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/06/04/200791.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/200791.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/200791.html</trackback:ping><description><![CDATA[<p style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;">1、从svn clone出项目，加上-s参数以标记识别svn标准的目录分支结构，同时通过show-ignore设置git库的exclude属性：</p><ol style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;"><li>git svn clone -s https://svn.xxx.com/svn/xxx</li><li>git svn show-ignore &gt;&gt; .git/info/exclude&nbsp;</li></ol><p style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;">2、建立本地工作分支，开始工作：</p><ol style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;"><li>git checkout -b work&nbsp;</li></ol><p style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;">修改内容直接commit，加上-a开头以省略git add操作：</p><ol style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;"><li>git commit -a&nbsp;</li></ol><p style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;">3、提交回svn的过程：</p><ol style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;"><li>git checkout master&nbsp;&nbsp;</li><li>git merge work&nbsp;&nbsp;</li><li>git svn rebase&nbsp;&nbsp;</li><li>git svn dcommit&nbsp;</li></ol><p style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;">在今天工作中，我提交回svn的方式是：</p><ol style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;"><li>git checkout master&nbsp;&nbsp;</li><li>git svn rebase&nbsp;&nbsp;</li><li>git merge work&nbsp;</li></ol><p style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;">结果svn rebase时在master分支上产生了一个新的node，这样merge时就不能快速合并，出现了冲突，修复后，在dcommit时出错，出现N个孤立节点。因为不熟悉，就checkout出work分支，进行了dcommit，然后重新生成一次git库。<br /><br />今天解决了这个问题，参考以下网址：<a href="https://wiki.bnl.gov/dayabay/index.php?title=Synchronizing_Repositories" style="color: #6fbc4c;">https://wiki.bnl.gov/dayabay/index.php?title=Synchronizing_Repositories</a>。<br />以下重新描述一下问题和解决方法：<br />1、在执行git svn dcommit时，出现如下错误：<br />Committing to https://svn.xxx.com/svn/projects/trunk ...<br />提交时发生合并冲突: 您的文件或目录&#8221;test/functional/xxx_controller_test.rb&#8220;可能已经过时: The version resource does not correspond to the resource within the transaction.&nbsp; Either the requested version resource is out of date (needs to be updated), or the requested version resource is newer than the transaction root (restart the commit). at /usr/bin/git-svn line 450<br />2、这时，重新执行以下步骤即可：</p><ol style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;"><li>git svn fetch&nbsp;&nbsp;</li><li>git svn rebase&nbsp;&nbsp;</li><li>git svn dcommit&nbsp;</li></ol><p style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;">但我在执行git svn rebase时，又出现冲突，这个时候，只需要手工合并掉冲突，并重新add一下：</p><ol style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;"><li>git add .&nbsp;</li></ol><p style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;">然后，再执行：</p><ol style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;"><li>git rebase --continue</li></ol><p style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;">如果报告说没有修改内容，则换成执行：</p><ol style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;"><li>git rebase --skip&nbsp;</li></ol><p style="color: #4b4b4b; font-family: verdana, Arial, helvetica, sans-seriff; font-size: 12px; line-height: 19px;">完成rebase过程，这时就可以git svn dcommit了。<br />这样，总算解决了svn历史冲突问题，不用象前面那样笨笨的重新git-svn clone.</p><div><br />***************************************************************************************************<br />***************************************************************************************************<br /></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">git是源于linux内核源码的管理，自然更适合在linux系统下使用。<br />在windows环境下，主要有2种方式：msysgit和cygwin内置的git(需要选择安装)。<br />个人建议使用cygwin git，msysgit的编码问题确实让人头痛。<br />当然，如果要使用图形工具Tortoisegit，就必须安装msysgit了。<br /><br />cygwin配置：<br />（1）在/etc/profile末尾加上一行：. "$HOME/.bashrc"<br />（2）在$HOME目录下新建.bashrc文件，写入一行：source /etc/bash-completion.d/git<br />（3）set CYGWIN=tty notitle glob&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; set LANG=zh_CN&nbsp;<br /><br />git及git-svn使用：<br /><br />下载svn源码：git svn clone http://xxxx myproject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; （相当于svn checkout）<br /><br />建立临时分支：git branch aaa<br />切换到临时分支：git checkout aaa<br />提交：git add .<br />提交确认：git commit<br />提交及确认：git commit -a&nbsp;&nbsp;&nbsp;&nbsp; (git add . + git commit，但新增文件必须要git add .)<br /><br />切换回master分支：git checkout master<br />合并临时分支：git merge aaa<br />删除临时分支：git branch -d aaa<br /><br />从svn更新：&nbsp; git svn rebase&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (相当于svn update)<br />提交至svn：&nbsp; git svn dcommit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (相当于svn commit)<br /><br />查看状态：git status<br />查看diff：git diff，git diff head</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">git svn rebase 冲突：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">git add .&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">然后，再执行：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">git rebase --continue</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">如果报告说没有修改内容，则换成执行：</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">git rebase --skip&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><br /><img src="http://dl.iteye.com/upload/attachment/395387/09721bf7-d24e-368e-b3f4-c9d981cab825.png" alt="" style="border: 0px;" /></p><img src ="http://www.cppblog.com/niewenlong/aggbug/200791.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-06-04 12:16 <a href="http://www.cppblog.com/niewenlong/archive/2013/06/04/200791.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在 Ubuntu 上构建 GNU Radio </title><link>http://www.cppblog.com/niewenlong/archive/2013/06/02/200764.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sun, 02 Jun 2013 15:07:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/06/02/200764.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/200764.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/06/02/200764.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/200764.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/200764.html</trackback:ping><description><![CDATA[<h1 style="font-family: simsun !important;"><font size="3"><span style="font-family: simsun, serif;">Building GNU Radio on Ubuntu Linux</span></font></h1><h2 style="color: #333333; font-weight: bold; font-style: normal; font-variant: normal; font-size: 1.5em; line-height: normal; font-family: simsun, serif; margin: 7px 0px;"><a name="TOC-GNU-Radio-3.2" style="color: #0000cc; text-decoration: none; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat;"></a><font size="3">GNU Radio 发行版 3.2</font></h2><h1><div style="display: inline-block;"><div><div style="margin-left: 40px;"><font size="2"><span style="font-family: simsun, serif;">GNU Radio 最新发行版 3.2， 已经对 Ubuntu 9.04 (Jaunty) 有二进制的安装包（</span><a href="https://sites.google.com/a/microembedded.com/chinese/system/errors/NodeNotFound?suri=wuid://microembedded.com/chinese/gx:505fd16027590cee" style="color: #551a8b; text-decoration: none; font-family: simsun, serif;">binary package</a><span style="font-family: simsun, serif;">）。再也不需预先手动安装构建工具和进行从繁琐的源码安装了。而且 USRP 和 USRP2 的安装和配置是自动完成的。这是最快和最简洁的方法让 GNU Radio 平台运行在你的系统上。</span></font></div><font size="2"><br style="font-family: simsun, serif;" /></font><div style="margin-left: 40px;"><font size="2" style="color: #a64d79;"><span style="font-family: simsun, serif;">以下的篇幅有点过时而且布局也需做些调整。</span></font></div></div></div></h1><h3 style="color: #333333; font-weight: bold; font-style: normal; font-variant: normal; font-size: 1.2em; line-height: normal; font-family: simsun, serif; margin: 5px 0px;"><a name="TOC-2" style="color: #0000cc; text-decoration: none; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat;"></a><font size="2">安 装选项</font></h3><h1><div style="display: inline-block;"><div><div style="margin-left: 40px;"><font size="2" style="font-family: simsun, serif;">这儿提供的信息和脚本用于编译和安装 GNU Radio 及所需的后台程序、库，其可用于&nbsp;</font><font size="2" style="font-family: simsun, serif;">Ubuntu Linux 6.10 ("Edgy") 或其后的版本；也可能适用于此前的版本但这些没有被测试过。</font><br /><font size="2" style="font-family: simsun, serif;">在&nbsp;</font><font size="2" style="font-family: simsun, serif;">Ubuntu 6.10 ("Edgy") 上安装 GNU Radio 可以</font><font size="2" style="font-family: simsun, serif;">由</font><font size="2" style="font-family: simsun, serif;">二进制的安装包（<a href="https://sites.google.com/a/microembedded.com/chinese/system/errors/NodeNotFound?suri=wuid://microembedded.com/chinese/gx:505fd16027590cee" style="color: #551a8b; text-decoration: none;">binary package</a>）和软件包管理器基本上完成，但是也有部分软件包需要下载源码以及从源码编译。</font><br /><font size="2" style="font-family: simsun, serif;">在&nbsp;</font><font size="2" style="font-family: simsun, serif;">Ubuntu 7.04 ("Feisty") 及其后的版本上安装 GNU Radio 可以完全</font><font size="2" style="font-family: simsun, serif;">由</font><font size="2" style="font-family: simsun, serif;">二进制的安 装包（<a href="https://sites.google.com/a/microembedded.com/chinese/system/errors/NodeNotFound?suri=wuid://microembedded.com/chinese/gx:505fd16027590cee" style="color: #551a8b; text-decoration: none;">binary package</a>）和软件包管理器完成，或者由下载源码再编译也可。</font><br /><font size="2" style="font-family: simsun, serif;"><strong><br />备注:</strong>&nbsp;GNU Radio 版本 3.0.3 及更早的版本安装在&nbsp;</font><font size="2" style="font-family: simsun, serif;">Ubuntu 7.04 ("Feisty") 上时使用 USRP 功能不稳定； USRP 工作一阵子便死机，需 USRP 或 Ubuntu 重新启动。 在 SVN 可以找到对此的修补。</font></div><font size="2" style="font-family: simsun, serif;"><br /></font></div></div></h1><h3 style="color: #333333; font-size: 1.2em; line-height: normal; font-family: simsun, serif; margin: 5px 0px;"><a name="TOC-3" style="color: #0000cc; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat;"></a><font size="2">基于源码构建时的先决条件</font></h3><h1><div style="display: inline-block;"><div style="margin-left: 40px;"><font size="2" style="font-family: simsun, serif;">以下软件包是安装 GNU Radio 到 Ubuntu 上为编译源码所需。 这些软件包可以通过&nbsp;</font><font size="2" style="font-family: simsun, serif;">"synaptic"、 "dselect"、 或 "apt-get"</font><font size="2">&nbsp;来安装。除非有明确的强调，在此便认为各个软件包都应该安装最新的版本。</font></div><ul style="font-family: simsun, serif;"><li><font size="2">开发用工具 (编译时所需)</font><ul><li><font size="2">g++</font></li><li><font size="2">subversion</font></li><li><font size="2">make</font></li><li><font size="2">autoconf, automake, libtool</font></li><li><font size="2">sdcc (从 "universe"; 2.4 或 更新的)</font></li><li><font size="2">guile (1.6 或更新的)</font></li><li><font size="2">ccache (不是必须的, 如果频繁编译的话建议安装)</font></li></ul></li></ul><ul style="font-family: simsun, serif;"><li><font size="2">库 (实时运行和编译所需)</font><ul><li><font size="2">python-dev</font></li><li><font size="2">FFTW 3.X (fftw3, fftw3-dev)</font></li><li><font size="2">cppunit (libcppunit 和 libcppunit-dev)</font></li><li><font size="2">Boost 1.35 (或更新的)</font></li><li><font size="2">libusb and libusb-dev</font></li><li><font size="2">wxWidgets (wx-common) 和 wxPython (python-wxgtk2.8)</font></li><li><font size="2">python-numpy (籍借 python-numpy-ext) (for SVN on or after 2007-May-28</font><font size="2">)</font></li><li><font size="2">ALSA (alsa-base, libasound2 和 libasound2-dev)</font></li><li><font size="2">Qt (libqt3-mt-dev 用于比 8.04 更早的版本; version 4 用于 8.04 和以后的 )</font></li><li><font size="2">SDL (libsdl-dev)</font></li><li><font size="2">GSL GNU Scientific Library (libgsl0-dev &gt;= 1.10 required for SVN trunk, not in binary repositories for 7.10 and earlier)</font></li></ul></li></ul><ul style="font-family: simsun, serif;"><li><font size="2">SWIG (1.3.31 或 更新的)</font><ul><li><font size="2">Edgy 及以前版本: 基于源码安装时所需</font></li><li><font size="2">Feisty 或更新的版本: 使用标准软件包安装(swig)</font></li></ul></li></ul><ul style="font-family: simsun, serif;"><li><font size="2">QWT (可选项) (5.0.0 或更新的版本)</font><ul><li><font size="2">必须由源码安装 (注：当下 2008-01-15).</font></li><li><font size="2">8.04 和 8.10 应当使用&nbsp;</font><font size="2">qt4</font><font size="2">. 键入如下命令 :&nbsp;<br /></font></li></ul></li></ul><div style="margin-left: 120px; font-family: simsun, serif;"><font size="2">sudo apt-get update&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 便可升级为合适的 qt4.</font></div><ul style="font-family: simsun, serif;"><li><font size="2">QWT Plot3d Lib</font><ul><li><font size="2">必须安装从而使 gr-qtgui 能够工作。 Ubuntu 8.04 和 8.10 最好使用</font><font size="2">&nbsp;qt4。</font></li></ul></li></ul><ul style="font-family: simsun, serif;"><li><font size="2">例程（Polyphase Filter Bank examples）</font><ul><li><font size="2">以便使 gnuradio-examples/python/pfb 下的例程能够工作，需要安装 python-scipy, python-matplotlib, 和 python-tk</font></li></ul></li></ul><ul style="font-family: simsun, serif;"><li><font size="2">其它</font><ul><li><font size="2">doxygen (以便能够从源码生成文档)</font></li><li><font size="2">octave (from "universe")</font></li></ul></li></ul></div></h1><h3 style="color: #333333; font-size: 1.2em; line-height: normal; font-family: simsun, serif; margin: 5px 0px;"><a name="TOC-4" style="color: #0000cc; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat;"></a><font size="2">安装脚本</font></h3><h1><div style="display: inline-block;"><p style="font-family: simsun, serif; margin-left: 40px;"><font size="2">籍希望能提供足够多的指导来将 GNU Radio 设置并运行于 Ubuntu 上，如下脚本的目的是用来&#8220;牵手&#8221;大多数的用户将 GNU Radio 安装在一个典型的 Ubuntu 上。<br /></font></p><ul style="font-family: simsun, serif;"><li><strong><font size="2">Edgy&nbsp;</font></strong></li></ul><div style="margin-left: 40px;"><font size="2">此部分仅针对 Edgy 或更早的版本(除非是想去除 CDROM 功能，对于 Feisty 或新于它的版本而言，不需做任何更改）：</font></div><div style="margin-left: 40px; font-family: simsun, serif; color: #0000ff;"><font size="2"><span style="color: #000000;">通过如下两种方法之一手动注释所 有的库使得包含 "universe" 和 "multiverse"&nbsp;</span><br /></font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo &lt;EDITOR&gt; /etc/apt/sources.list &nbsp;（方法之一）<br /></font></pre><div style="margin-left: 40px; font-family: simsun, serif;"><div style="margin-left: 40px;">或</div></div><div style="margin-left: 40px; font-family: simsun, serif;"><br /><div style="margin-left: 40px;">通过图形界面 GUI：沿着 System -&gt; Administration -&gt; Software Sources。然后键入 admin 的密码进入。在 "Ubuntu" tab 上，确认所有的 "main restricted universe multiverse" 的选项被选中而其它部分没有被选中（或者做认为对设置合适的工作）。顺序点击"Close" 和 "Reload" 来更新软件包的列单。文件 "/etc/apt/sources.list" 内被注释的行列将会如下一般读入 (DIST 是其具体的发行版本名，诸如：edgy, feisty, gusty, 等等):</div></div><div style="margin-left: 40px; font-family: simsun, serif;"><div style="margin-left: 40px;"><font size="2">deb http://us.archive.ubuntu.com/ubuntu/ DIST main restricted universe multiverse<br />deb http://us.archive.ubuntu.com/ubuntu/ DIST-updates main restricted universe multiverse<br />deb http://security.ubuntu.com/ubuntu/ DIST-security main restricted universe multiverse<br /><br /></font></div></div><div style="margin-left: 40px; font-family: simsun, serif;"><font size="2">更新 本地 dpkg 缓存：<br /></font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get update<br /></font></pre><p style="font-family: simsun, serif; margin-left: 40px;"><font size="2">安装所需的包（有些似乎已经被 Ubuntu 缺省的安装上了；有一些似乎同其它的相重叠；无论如何这些包含了除 Edgy 之外所需的所有软件包）</font></p><ul><li><strong>Lucid (10.04):</strong><br /></li></ul><pre style="margin-left: 80px;">sudo apt-get -y install libfontconfig1-dev libxrender-dev libpulse-dev swig g++ automake libtool python-dev libfftw3-dev \<br />libcppunit-dev libboost-all-dev libusb-dev fort77 sdcc sdcc-libraries \<br />libsdl1.2-dev python-wxgtk2.8 subversion git-core guile-1.8-dev \<br />libqt4-dev python-numpy ccache python-opengl libgsl0-dev \<br />python-cheetah python-lxml doxygen qt4-dev-tools \<br />libqwt5-qt4-dev libqwtplot3d-qt4-dev pyqt4-dev-tools<br /></pre><ul style="font-family: simsun, serif;"><li><strong><font size="2">Karmic (9.10):</font></strong></li></ul><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get -y install swig g++ automake libtool python-dev libfftw3-dev \<br />libcppunit-dev libboost1.38-dev libusb-dev fort77 sdcc sdcc-libraries \<br />libsdl1.2-dev python-wxgtk2.8 subversion git-core guile-1.8-dev \<br />libqt4-dev python-numpy ccache python-opengl libgsl0-dev \<br />python-cheetah python-lxml doxygen qt4-dev-tools \<br />libqwt5-qt4-dev libqwtplot3d-qt4-dev pyqt4-dev-tools<br /></font></pre><ul style="font-family: simsun, serif;"><li><strong><font size="2">Jaunty (9.04):&nbsp;</font></strong></li></ul><div style="margin-left: 40px; font-family: simsun, serif;"><strong><font size="2"><em>需安装</em></font><font size="2"><em>软件包 sdcc-nf needs&nbsp; (而不是 sdcc)</em></font></strong></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get -y install swig g++ automake1.9 libtool python2.5-dev fftw3-dev \<br />libcppunit-dev libboost1.35-dev sdcc-nf libusb-dev \<br />libsdl1.2-dev python-wxgtk2.8 subversion git guile-1.8-dev \<br />libqt4-dev python-numpy ccache python-opengl libgsl0-dev \<br />python-cheetah python-lxml doxygen qt4-dev-tools \<br />libqwt5-qt4-dev libqwtplot3d-qt4-dev pyqt4-dev-tools<br /></font></pre><div style="margin-left: 40px; font-family: simsun, serif;"><font size="2">如果 安装是来自对旧版本的升级，那就是说安装了python-wxgtk2.6。其原因是 python-wxgtk2.6 比 python-wxgtk2.8 有更高的优先级被安装，它必须使用如下指令被去除：&nbsp;<em><br /><br /></em></font></div><div style="margin-left: 40px; font-family: simsun, serif;"><div style="margin-left: 40px;"><font size="2"><em>sudo apt-get remove python-wxgtk2.6</em>&nbsp;<br /></font></div></div><ul style="font-family: simsun, serif;"><li><strong><font size="2">Intrepid (8.10):&nbsp;</font></strong></li></ul><div style="font-family: simsun, serif;"><div style="margin-left: 40px;"><strong><font size="2"><em>需安装</em></font><font size="2"><em>软件包 sdcc-nf needs&nbsp; (而不是 sdcc)</em></font></strong></div></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get -y install swig g++ automake1.9 libtool python-dev fftw3-dev \<br />libcppunit-dev libboost1.35-dev sdcc-nf libusb-dev \<br />libsdl1.2-dev python-wxgtk2.8 subversion git guile-1.8-dev \<br />libqt4-dev python-numpy ccache python-opengl libgsl0-dev \<br />python-cheetah python-lxml doxygen qt4-dev-tools \<br />libqwt5-qt4-dev libqwtplot3d-qt4-dev  pyqt4-dev-tools<br /></font></pre><ul style="font-family: simsun, serif;"><li><font size="2"><strong>Hardy (8.04):</strong>&nbsp;</font></li></ul><div style="margin-left: 40px; font-family: simsun, serif;"><font size="2"><em>如&nbsp;</em></font><font size="2"><em>README.building-boost 所阐述的一样</em></font><font size="2"><em>应当安装&nbsp;</em></font><font size="2"><em>Boost。</em></font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get -y install swig g++ automake1.9 libtool python-dev fftw3-dev \<br />libcppunit-dev sdcc libusb-dev libasound2-dev libsdl1.2-dev \<br />python-wxgtk2.8 subversion guile-1.8-dev libqt4-dev python-numpy-ext \<br />ccache python-opengl libgsl0-dev python-cheetah python-lxml doxygen \<br />libqwt5-qt4-dev libqwtplot3d-qt4-dev qt4-dev-tools<br /></font></pre><ul style="font-family: simsun, serif;"><li><strong><font size="2">Gutsy (7.10):&nbsp;</font></strong></li></ul><div style="font-family: simsun, serif;"><div style="margin-left: 40px;"><font size="2"><em>如&nbsp;</em></font><font size="2"><em>README.building-boost 文档所阐述的一样</em></font><font size="2"><em>应当安装&nbsp;</em></font><font size="2"><em>Boost。也需要 GSL 。<br /></em></font></div></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get -y install g++ automake libtool python-dev fftw3-dev \<br />libcppunit-dev sdcc libusb-dev libasound2-dev \<br />libsdl1.2-dev python-wxgtk2.8 subversion guile-1.8-dev libgsl0-dev \<br />libqt3-mt-dev python-numpy-ext swig ccache<br /></font></pre><ul style="font-family: simsun, serif;"><li><strong><font size="2">Feisty (7.04):&nbsp;</font></strong></li></ul><div style="margin-left: 40px; font-family: simsun, serif;"><font size="2"><em>如&nbsp;</em></font><font size="2"><em>README.building-boost 文档所阐述的一样</em></font><font size="2"><em>应当安装&nbsp;</em></font><font size="2"><em>Boost。也需要 GSL 。</em></font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get -y install g++ automake1.9 libtool python-dev fftw3-dev \<br />libcppunit-dev sdcc libusb-dev libasound2-dev \<br />libsdl1.2-dev python-wxgtk2.8 subversion guile-1.6-dev\<br />libqt3-mt-dev python-numpy-ext swig ccache<br /></font></pre><ul style="font-family: simsun, serif;"><li><strong><font size="2">Edgy (6.10):&nbsp;</font></strong></li></ul><div style="margin-left: 40px; font-family: simsun, serif;"><font size="2"><em>强 烈建议使用上面的新发行版之一</em></font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get -y install g++ automake1.9 libtool python-dev fftw3-dev \<br />libcppunit-dev libboost-dev sdcc libusb-dev libasound2-dev \<br />libsdl1.2-dev python-wxgtk2.6 subversion guile-1.6-dev \<br />libqt3-mt-dev python-numpy-ext ccache<br /></font></pre><div style="margin-left: 40px;"><strong><font size="2" style="font-family: simsun, serif;">备注：</font></strong>如上的 Edgy 安装&nbsp;<font size="2" style="font-family: simsun, serif;">python-wxgtk-2.6。这对于 GNURadio 以前的版本的用户是没问题，但对于最新 GNURadio 的&nbsp;</font><font size="2" style="font-family: simsun, serif;">svn snapshots</font><font size="2" style="font-family: simsun, serif;">&nbsp;（svn 快照技术）</font>显得过于古老。若想基于最新的&nbsp;<span style="border-collapse: separate; font-family: Simsun; font-weight: normal; line-height: normal; font-size: medium;"><span style="font-family: arial; font-size: 14px; line-height: 24px;">svn 快照技术</span></span>&nbsp;（svn snapshot）构建 GNURadio，便需&nbsp;<font size="2" style="font-family: simsun, serif;">wxgtk version 2.8 或更新。</font><br />可以到&nbsp;<font size="2" style="font-family: simsun, serif;">wxwidgets debian 和 ubuntu 的知识栈库安装最新的版本的&nbsp;</font><font size="2" style="font-family: simsun, serif;">wxwidgets。</font><br />查阅&nbsp;<font size="2" style="font-family: simsun, serif;">&nbsp;<a href="http://wiki.wxpython.org/InstallingOnUbuntuOrDebian" rel="nofollow" style="color: #551a8b; text-decoration: none;">Installing latest wxgtk-2.8 packages on debian or Ubuntu</a>&nbsp;进行选项安装；有些也许已经在以前的命令中已经被成功地安装到系统中。<br /></font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get -y install gkrellm wx-common libwxgtk2.8-dev alsa-base autoconf xorg-dev g77 gawk bison openssh-server emacs cvs usbview octave<br /></font></pre><div style="margin-left: 40px;"><font size="2" style="font-family: simsun, serif;">（以下）仅适于 Edgy :&nbsp; 获取、编译、然后安装 SWIG&nbsp;</font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">wget http://prdownloads.sourceforge.net/swig/swig-1.3.33.tar.gz<br />tar zxf swig-1.3.33.tar.gz<br />cd swig-1.3.33<br />./configure<br />make<br />sudo make install<br />cd ..<br /></font></pre><div style="margin-left: 40px;"><font size="2" style="font-family: simsun, serif;">可选项<strong>：</strong></font><font size="2" style="font-family: simsun, serif;">获取、编译、然后安装</font><font size="2" style="font-family: simsun, serif;">&nbsp;QWT 5.0.0 (或 更新)：&nbsp;<strong><br /></strong></font></div><div style="margin-left: 40px;"><font size="2" style="font-family: simsun, serif;"><strong>备注</strong>： 不必设置诸如&nbsp; "QTDIR" 或 "QWT_CFLAGS" 的环境变量，</font><font size="2" style="font-family: simsun, serif;">&nbsp;(在此)</font><font size="2" style="font-family: simsun, serif;">不必理睬这些</font>。</div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">wget http://superb-east.dl.sourceforge.net/sourceforge/qwt/qwt-5.0.2.tar.bz2<br />tar jxf qwt-5.0.2.tar.bz2<br />cd qwt-5.0.2<br /></font></pre><ul><li><font size="2" style="font-family: simsun, serif;">现在编辑&nbsp;<em>qwtconfig.pri</em>:</font></li></ul><div style="margin-left: 40px;"><em><font size="2">将&nbsp; UNIX 版本的&nbsp;&nbsp;</font><font size="2" style="font-family: simsun, serif;">"INSTALLBASE&#8221;置换为 &#8220;</font><font size="2" style="font-family: simsun, serif;">/usr/local</font></em><font size="2" style="font-family: simsun, serif;"><em>&#8221;（原为&nbsp;</em></font><font size="2" style="font-family: simsun, serif;">"/usr/local/qwt-5.0.2"</font><font size="2" style="font-family: simsun, serif;"><em>）；</em><br /><em>将原来的&nbsp;</em></font><em><font size="2" style="font-family: simsun, serif;">"doc.path" 变换为 "$$INSTALLBASE/doc/qwt"&nbsp;</font>；<br /><font size="2" style="font-family: simsun, serif;">Save, exit（</font>保存，推出）。</em><em><br /></em></div><div><div style="margin-left: 40px;"><font size="2"><br />"doc" 是由 HTML 和 man 格式构建，这些都位于</font><font size="2" style="font-family: simsun, serif;">&nbsp;/usr/local/doc/{html,man}。它不是标准路径，但分离出这些似乎也不是一件容易的事情，所以对它弃之不予理睬：<br /></font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">qmake<br />make<br />sudo make install<br />cd ..<br /></font></pre></div></div></h1><h3 style="color: #333333; font-size: 1.2em; line-height: normal; font-family: simsun, serif; margin: 5px 0px;"><a name="TOC-Install-Boost" style="color: #0000cc; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat;"></a><font size="2">安装 Boost</font></h3><h1><div style="display: inline-block;"><p style="font-family: simsun, serif; margin-left: 40px;"><font size="2">对于&nbsp;</font><font size="2">Ubuntu 8.04 或更早的版本，下载并安装 Boost 1.35 或更新版本如下（参阅文档&nbsp;</font><font size="2">README.building-boost）：</font></p><p style="font-family: simsun, serif; margin-left: 80px;"><font size="2">1) 在&nbsp;</font><font size="2">boost.sourceforge.net 下载最新的 boost 的版本 (在写此文时 boost_1_37_0.tar.bz2 是最新的版本)。</font></p><div style="margin-left: 80px; font-family: simsun, serif;"><font size="2">2) 就地解压缩并进入该目录<br /></font></div><pre style="font-family: simsun, serif; margin-left: 120px;"><font size="2">$ cd boost_1_37_0<br /></font></pre><p style="font-family: simsun, serif; margin-left: 80px;"><font size="2">3) 选择前缀来安装。比如使用 /opt/boost_1_37_0</font></p><pre style="font-family: simsun, serif; margin-left: 120px;"><font size="2">$ BOOST_PREFIX=/opt/boost_1_37_0<br /></font></pre><div style="margin-left: 80px; font-family: simsun, serif;"><font size="2">4) 配置<br /></font></div><pre style="font-family: simsun, serif; margin-left: 120px;"><font size="2">$ ./configure --prefix=$BOOST_PREFIX --with-libraries=thread,date_time,program_options<br /></font></pre><div style="margin-left: 80px; font-family: simsun, serif;"><font size="2">5) 编译<br /></font></div><pre style="font-family: simsun, serif; margin-left: 120px;"><font size="2">$ make<br /></font></pre><div style="margin-left: 80px; font-family: simsun, serif;"><font size="2">6) 安装<br /></font></div><pre style="font-family: simsun, serif; margin-left: 120px;"><font size="2">$ sudo make install<br /><br />$ cd ..<br /></font></pre></div></h1><h2 style="color: #333333; line-height: normal; font-family: simsun, serif; margin: 7px 0px;"><a name="TOC-Installing-GNU-Radio" style="color: #0000cc; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat;"></a><font size="2">安装 GNU Radio</font></h2><h1><div style="display: inline-block;"><div><ul><li><font size="2" style="font-family: simsun, serif;">下载、bootstrap、配置，和编译 GNU Radio 软件包：</font></li></ul></div><div><ul><li>使 用 git 来安装 GNU Radio<br /></li></ul><pre style="margin-left: 80px;">git clone http://gnuradio.org/git/gnuradio.git<br /><br />cd gnuradio<br />export LD_LIBRARY_PATH=$BOOST_PREFIX/lib     # As per the instructions for installing Boost<br /><br />./bootstrap<br />./configure --with-boost=$BOOST_PREFIX   # As per the instructions for installing Boost<br />make</pre><div style="margin-left: 40px;"><font size="2" style="font-family: simsun, serif;"><strong>可选项：</strong>运行 GNU Radio 的自检程序；这并不需 USRP。<br /></font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">make check<br /></font></pre><div style="margin-left: 40px;"><font size="2" style="font-family: simsun, serif;">即使有一个甚至一些测试没能通过，但 GNU Radio 也有可能功能性正常工作。尽管如此，到邮件列表寻求解决的方案或者将解决的方案贡献到列表是比较理智的做法。有此善举之时，不要忘记附带如下信息：OS 类型、OS 版本、CPU 类型（诸如，使用</font><font size="2" style="font-family: simsun, serif;">"uname -a"获得的）、任何有关硬件的特别之处、软件的版本</font><font size="2" style="font-family: simsun, serif;">(诸如：gcc, g++, swig, sdcc, 等）以及如何安装（标准或非标软件包，源代码）。<br /></font></div><ul><li><font size="2" style="font-family: simsun, serif;">下面，就一般用途安装 GNU Radio （缺省安装到</font><font size="2" style="font-family: simsun, serif;">&nbsp;/usr/local</font><font size="2" style="font-family: simsun, serif;">）：</font></li></ul><div style="margin-left: 40px;"></div><div style="margin-left: 40px;"><div style="margin-left: 40px;"><font size="2">sudo make install</font></div></div><ul><li><font size="2" style="font-family: simsun, serif;">Ubuntu 使用 udev 来处理设备的热插拔问题，</font>而且缺省地不给&nbsp;<font size="2" style="font-family: simsun, serif;">non-root 用户提供读取 USRP 的权限。</font>以 下脚本摘自&nbsp;<font size="2" style="font-family: simsun, serif;"><a href="http://gnuradio.microembedded.com/udevconfig" target="_blank" style="color: #551a8b; text-decoration: none;">directions</a></font>，它赋予群在无论在在线或热插拔状态下，都能够通过 USB 掌控 USRP。</li></ul></div><div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo addgroup usrp<br />sudo usermod -G usrp -a &lt;YOUR_USERNAME&gt;<br />echo 'ACTION=="add", BUS=="usb", SYSFS{idVendor}=="fffe", SYSFS{idProduct}=="0002", GROUP:="usrp", MODE:="0660"' &gt; tmpfile<br />sudo chown root.root tmpfile<br />sudo mv tmpfile /etc/udev/rules.d/10-usrp.rules<br /></font></pre><ul><li>至此，配置后的 Ubuntu 知道如何处置在 USB 上检测到的 USRP，除非该&#8220;udev&#8221;需要重载更新，以便包含刚产生的新规约。如下可能如此， 如果异常的话，重启计算机将肯定如愿。<br /></li></ul><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo udevadm control --reload-rules<br /></font></pre><div style="margin-left: 80px;"><font size="2" style="font-family: simsun, serif;">或</font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo /etc/init.d/udev stop<br />sudo /etc/init.d/udev start<br /></font></pre><div style="margin-left: 80px;"><font size="2" style="font-family: simsun, serif;">或</font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo killall -HUP udevd<br /></font></pre><div style="margin-left: 40px;"><font size="2" style="font-family: simsun, serif;">当 USRP 被插入系统后，可以使用如下命令通过检查&nbsp;</font><font size="2" style="font-family: simsun, serif;">/dev/bus/usb 来查看是否被认知：</font></div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">ls -lR /dev/bus/usb | grep usrp<br /></font></pre><div style="margin-left: 40px;">结果会显示一、两行信息（每个USRP 占据一行）如下：</div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">crw-rw---- 1 root usrp 189, 514 Mar 24 09:46 003<br /></font></pre><div style="margin-left: 40px;">每个设备文件的列表将以&#8216;usrp' 作为群（<font size="2" style="font-family: simsun, serif;">group</font><font size="2">）</font>、<font size="2" style="font-family: simsun, serif;">&nbsp;'crw-rw----' 作为</font>状态（<font size="2" style="font-family: simsun, serif;">mode</font>）。</div><ul style="font-family: simsun, serif;"><ul><li><strong>备注：</strong>如果系统是 Feisty 或更新的，或许需要重启计算机以便使得 GNU Radio 正常接口 USRP。但对于 Edgy 这似乎是多余的。<br /></li></ul></ul><ul><li><font size="2">USRP 一旦被 Ubuntu 确认，接下来便是确认 GNU Radio 同 USRP 是否配合得当（没有安装 USRP，</font><font size="2">当然可以</font><font size="2">略过这一步）。</font><font size="2">或许&nbsp;</font><font size="2">"usrp_benchmark_usb" 检测表明无法达到满负荷的&nbsp;</font><font size="2">32 MB/s，但是先保证脚本至少可以运行正常；如果有问题（脚本无法运行正常），要么可能是 GNU Radio 系统出问题，要么可能是 USRP 无法读取。在目录&nbsp;</font><font size="2">"gnuradio" 下，确认以下步骤</font><font size="2">工作</font><font size="2">正常：<br /></font></li></ul><ul style="font-family: simsun, serif;"><ul><li><font size="2">Python 和 USRP 的接口；<br /></font></li></ul></ul><div style="margin-left: 80px;"><font size="2">测试宿主机和 USRP 之间一个大致的最大数据吞吐量（以 2 的幂来表示）。<br /></font></div><pre style="font-family: simsun, serif; margin-left: 120px;"><font size="2">cd gnuradio-examples/python/usrp<br />./usrp_benchmark_usb.py<br /></font></pre><ul style="font-family: simsun, serif;"><ul><li><font size="2">C++ 和 USRP 的接口；<br /></font></li></ul></ul><div style="margin-left: 80px;"><font size="2">测试宿主机和 USRP 之间一个大致的最大数据吞吐量（非量化）</font></div><pre style="font-family: simsun, serif; margin-left: 120px;"><font size="2">cd usrp/host/apps<br />./test_usrp_standard_tx<br />./test_usrp_standard_rx<br /></font></pre><ul><li>升级系统，操作完成后或许需要重启系统：<br /></li></ul></div><div><pre style="font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get -y upgrade<br /></font></pre><ul><li><font size="2" style="font-family: simsun, serif;">升级 Linux 的发布版本信息库，完成后需重启系统：</font></li></ul></div><div><pre style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; font-family: simsun, serif; margin-left: 80px;"><font size="2">sudo apt-get -y dist-upgrade<br /></font></pre></div></div></h1><h3 style="color: #333333; font-size: 1.2em; line-height: normal; font-family: simsun, serif; margin: 5px 0px; background-color: #ffffff;"><a name="TOC-Broken-libtool-on-Debian-and-Ubuntu" style="color: #0000cc; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat;"></a><font size="2">Debian 和 Ubuntu 系统的的</font><font size="2">&nbsp;libtool 故障</font></h3><h3 style="color: #333333; font-weight: normal; font-size: 1.2em; line-height: normal; font-family: simsun, serif; margin: 5px 0px 5px 40px; background-color: #ffffff;"><a name="TOC-Debian-Ubuntu-libtool-upstream-version-PREFIX-lib-64-PREFIX-lib64-etc-ld.so.conf-" style="color: #0000cc; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat;"></a><font size="2">Debian 和 Ubuntu 系统在完善 libtool 的</font><font size="2">&nbsp;<span style="color: #ff0000;">upstream version</span></font><font size="2">&nbsp;不尽人意，它们在安装<font size="2">代码和库</font>之前会失去测试的这些<font size="2"><font size="2">代码和库</font></font>能力。但是安装之前的测试不失是个好主意。为了解决这个问题，请将把&nbsp;</font><font size="2">$PREFIX/lib (和 64 位机器的 $PREFIX/lib64) 包含在&nbsp;</font><font size="2">/etc/ld.so.conf 之中。</font></h3><h1><br style="font-family: simsun; font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff;" /><div style="font-family: simsun; font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; margin-left: 40px;">如果没有这样做的话（把&nbsp;$PREFIX/lib包含在&nbsp;/etc/ld.so.conf 之中），在构建的链接阶段便会看见出错信息。这现象将会在多处出现。最有可能是在构建&nbsp;mblocks 第一次出现。这不是&nbsp;mblocks 的问题，是&nbsp;Debian/Ubuntu 自身的问题。</div><p style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; font-family: simsun, serif; margin-left: 40px;">如下步骤便可解决这些&#8220;问题&#8221;：</p><div style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; margin-left: 40px; font-family: simsun, serif;">1) 将当前的&nbsp;ld.so.conf 文件拷贝并保存到 temp 目录下如下：</div><pre style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; font-family: simsun, serif; margin-left: 80px;">cp /etc/ld.so.conf /tmp/ld.so.conf<br /></pre><div style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; margin-left: 40px; font-family: simsun, serif;">2) 添加路径 /usr/local/lib：</div><pre style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; font-family: simsun, serif; margin-left: 80px;">echo /usr/local/lib &gt;&gt; /tmp/ld.so.conf<br /></pre><div style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; margin-left: 40px; font-family: simsun, serif;">3)如果手动安装 Boost （比如：version 1_37_0），添加它的库函数路径如下：&nbsp;</div><pre style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; font-family: simsun, serif; margin-left: 80px;">echo /opt/boost_1_37_0/lib &gt;&gt; /tmp/ld.so.conf<br /></pre><div style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; margin-left: 40px; font-family: simsun, serif;">4) 删除原 ld.so.conf 文件，用如上编辑后的文件替代它：</div><pre style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; font-family: simsun, serif; margin-left: 80px;">sudo mv /tmp/ld.so.conf /etc/ld.so.conf<br /></pre><div style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; margin-left: 40px; font-family: simsun, serif;">5) 运行 ldconfig：</div><pre style="font-size: 13px; font-weight: normal; line-height: 16px; background-color: #ffffff; font-family: simsun, serif; margin-left: 80px;">sudo ldconfig<br /></pre></h1><img src ="http://www.cppblog.com/niewenlong/aggbug/200764.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-06-02 23:07 <a href="http://www.cppblog.com/niewenlong/archive/2013/06/02/200764.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于Unix/Linux下查看命令行历史记录(history/.bash_history)</title><link>http://www.cppblog.com/niewenlong/archive/2013/06/02/200758.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sun, 02 Jun 2013 06:46:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/06/02/200758.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/200758.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/06/02/200758.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/200758.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/200758.html</trackback:ping><description><![CDATA[<div><h2> 			<a id="cb_post_title_url" href="http://www.cnblogs.com/h2-database/archive/2012/07/04/2583318.html">关于Unix/Linux下查看命令行历史记录(history/.bash_history)</a> 		</h2> 		<h3>1.vi .bash_history</h3> <p>关于.bash_history的配置<br /> </p> <p><strong>export HISTCONTROL=ignoreboth </strong><br /> </p> <p>Don&#8217;t save duplicates<br /> </p> <p><strong>export HISTSIZE=10000</strong></p> <p>这个是针对history命令的设置，The number of commands to remember in the command history. The default value is 500.</p> <p><strong>export HISTFILESIZE=<strong>10000</strong></strong></p> <p>这个是针对history文件(.bash_history)的设置，The maximum number of lines  contained&nbsp; in&nbsp; the&nbsp; history file.&nbsp; When this variable is assigned a  value, the his-tory file is truncated, if necessary, by&nbsp; removing&nbsp; the  oldest&nbsp; entries, to contain no more than that number of  lines.&nbsp; The default value is 500.&nbsp; The history file&nbsp; is also&nbsp;  truncated&nbsp; to&nbsp; this size after writing it when an interactive shell  exits.<br /> <strong>export HISTIGNORE='ls'</strong></p> <p>A colon-separated list of patterns used to decide which command lines  should be saved on the history list.Each pattern is anchored at the  beginning&nbsp; of the line and must match the complete line&nbsp;</p> <p>以上的关于history的说明都可以使用<strong>man bash</strong>查的到,如果想要让你的配置永久生效，可以把export命令写到.bash_profile或者全局配置文件/etc/profile里<br /> <br /> </p> <h3>2.history</h3> <p><strong>模糊查询，history | grep -i "xxx"</strong></p> <p>[oracle@bej301441 ~]$ history | grep -i "FND"<br /> &nbsp;&nbsp; 34&nbsp; 2012-07-04 01:29:15 history | grep -i "FND"<br /> &nbsp;&nbsp; 35&nbsp; 2012-07-04 01:29:30 FNDLOAD apps/apps 0 Y DOWNLOAD  $FND_TOP/patch/115/import/affrmcus.lct PT_CUSTOM_FUC.ldt  FND_FORM_CUSTOM_RULES function_name="INV_INVTOMAI"<br /> &nbsp;&nbsp; 36&nbsp; 2012-07-04 01:29:33 history | grep -i "FND"<br /> [oracle@bej301441 ~]$<strong><br /> </strong></p> <p><strong>如何让history可以有时间戳显示</strong></p> <p># export HISTTIMEFORMAT='%F %T '</p> <p>&nbsp;....<br /> </p> <p>&nbsp;1027&nbsp; 2012-07-04 01:12:53 ls /etc/bash*<br /> &nbsp;1028&nbsp; 2012-07-04 01:13:17 vi /etc/bashrc<br /> &nbsp;1029&nbsp; 2012-07-04 01:16:04 history<br /> [oracle@bej301441 ~]$<br /> </p> <p><strong>清除history记录</strong></p> <p>[oracle@bej301441 ~]$ history -c<br /> [oracle@bej301441 ~]$ history<br /> &nbsp;&nbsp; 32&nbsp; 2012-07-04 01:20:40 history<br /> [oracle@bej301441 ~]$<br /> 注:清除history之后，.bash_history里仍会有历史记录</p> <p><strong>如何不让系统记录历史命令</strong></p> <p># export HISTSIZE=0<br /> # history<br /> # [Note that history did not display anything]</p> <h3>3.使用Control+R来搜索命令</h3> <p>命令行中输入Control+R，然后输入过往命令的key word，你就很容易找到以前执行过的命令了<br /> </p> (reverse-i-search)`FND': FNDLOAD apps/apps 0 Y DOWNLOAD  $FND_TOP/patch/115/import/affrmcus.lct PT_CUSTOM_FUC.ldt  FND_FORM_CUSTOM_RULES function_name="INV_INVTOMAI"</div><img src ="http://www.cppblog.com/niewenlong/aggbug/200758.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-06-02 14:46 <a href="http://www.cppblog.com/niewenlong/archive/2013/06/02/200758.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>debian 系统修改语言设置成英文</title><link>http://www.cppblog.com/niewenlong/archive/2013/06/02/200756.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sun, 02 Jun 2013 05:36:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/06/02/200756.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/200756.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/06/02/200756.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/200756.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/200756.html</trackback:ping><description><![CDATA[<div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">root@debian:</span><span style="color: #000000; ">~</span><span style="color: #000000; ">#&nbsp;vi&nbsp;</span><span style="color: #000000; ">/</span><span style="color: #000000; ">etc</span><span style="color: #000000; ">/</span><span style="color: #0000FF; ">default</span><span style="color: #000000; ">/</span><span style="color: #000000; ">locale&nbsp;<br />root@debian:</span><span style="color: #000000; ">~</span><span style="color: #000000; ">#&nbsp;dpkg</span><span style="color: #000000; ">-</span><span style="color: #000000; ">reconfigure&nbsp;locales<br />Generating&nbsp;locales&nbsp;(</span><span style="color: #0000FF; ">this</span><span style="color: #000000; ">&nbsp;might&nbsp;take&nbsp;a&nbsp;</span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">)<img src="http://www.cppblog.com/Images/dot.gif"  alt="" /><br />&nbsp;&nbsp;en_US.UTF</span><span style="color: #000000; ">-</span><span style="color: #000000; ">8</span><span style="color: #000000; "><img src="http://www.cppblog.com/Images/dot.gif"  alt="" />&nbsp;done<br />&nbsp;&nbsp;zh_CN.UTF</span><span style="color: #000000; ">-</span><span style="color: #000000; ">8</span><span style="color: #000000; "><img src="http://www.cppblog.com/Images/dot.gif"  alt="" />&nbsp;done<br />Generation&nbsp;complete.<br />root@debian:</span><span style="color: #000000; ">~</span><span style="color: #000000; ">#&nbsp;cat&nbsp;</span><span style="color: #000000; ">/</span><span style="color: #000000; ">etc</span><span style="color: #000000; ">/</span><span style="color: #0000FF; ">default</span><span style="color: #000000; ">/</span><span style="color: #000000; ">locale&nbsp;<br />#&nbsp;&nbsp;File&nbsp;generated&nbsp;by&nbsp;update</span><span style="color: #000000; ">-</span><span style="color: #000000; ">locale<br />LANG</span><span style="color: #000000; ">=</span><span style="color: #000000; ">en_US.UTF</span><span style="color: #000000; ">-</span><span style="color: #000000; ">8</span><span style="color: #000000; "><br />LANGUAGE</span><span style="color: #000000; ">=</span><span style="color: #000000; ">"</span><span style="color: #000000; ">en_US:en</span><span style="color: #000000; ">"</span><span style="color: #000000; "><br />root@debian:</span><span style="color: #000000; ">~</span><span style="color: #000000; ">#&nbsp;reboot<br /></span></div><p><br /></p><p>今天安装了一个Debian的虚拟机，安装的时候本来想选英语的，但是时区只能用美国的时区，于是就换上了中文的，没有提示选择时区。</p> <p>发现在shell中文还是乱码，于是毅然的把语言更改成英语的。打开文件locale</p> <pre>sudo vi /etc/default/locale</pre> <p>显示</p> <pre>LANG="zh_CN.UTF-8" LANGUAGE="zh_CN:zh"</pre> <p>将其内容更改成</p> <pre>LANG="en_US.UTF-8" LANGUAGE="en_US:en"</pre> <p>然后重启reboot机器。</p> <p>在修改的过程中，vi已经忘记了差不多了，导致修改起来非常纠结，勉强给修改完成。后来想给debian安装一个vim的，提示找不到定位源。后来运行了apt-get update后可以安装了。</p> <p><br /></p> <p>虽然之前的能够将中文改成英文，但是在使用<code>locale</code>命令时时会出现</p> <pre>locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory</pre> <p><a title="ubuntu locale 将中文修改成英文 " href="http://wiki.ubuntu.org.cn/%E4%BF%AE%E6%94%B9locale" target="_blank"></a><br /></p> <pre>dpkg-reconfigure locales</pre> <p>修改，在选项中选择en-US.UTF-8 按空格选中。然后简单的按 ok 键就好了。这下才算正确把中文环境的系统更换成英文的环境的系统。</p></div><img src ="http://www.cppblog.com/niewenlong/aggbug/200756.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-06-02 13:36 <a href="http://www.cppblog.com/niewenlong/archive/2013/06/02/200756.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>win7下硬盘安装debian</title><link>http://www.cppblog.com/niewenlong/archive/2013/01/29/197612.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Mon, 28 Jan 2013 16:45:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2013/01/29/197612.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/197612.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2013/01/29/197612.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/197612.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/197612.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 第一、到这个链接http://cdimage.debian.org/debian-cd/6.0.5/i386/iso-cd/，下载debian-6.0.5-i386-CD-1.iso，就下这一个，其他的不要下，当然，这是针对i386架构的，选择与自己的CPU相符的就ok。<br>第二、这个iso文件要放在一个分区的顶层里！用虚拟光驱打开这个iso文件，执行它的setup.exe程序，它会在C盘下产生个win32-loader文件夹<br>第三、网络上说，拷贝2个文件到win32-loader文件夹下，即hd-media/initrd.gz与hd-media/vmlinuz，debian官网上说，这2个文件要拷贝到iso文件的同一层目录下。其实setup.exe生成的win32-lader文件夹下有个initrd.gz文件，我一开始也没拷贝这2个文件，可重启进入安装程序后，老是找不到iso文件，解决方法是，一定要将这个iso文件放到FAT32格式的分区下！这2个文件也最好拷贝一下，可以从这个地址下载，http://archive.debian.org/debian/dists/sar&nbsp;&nbsp;<a href='http://www.cppblog.com/niewenlong/archive/2013/01/29/197612.html'>阅读全文</a><img src ="http://www.cppblog.com/niewenlong/aggbug/197612.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2013-01-29 00:45 <a href="http://www.cppblog.com/niewenlong/archive/2013/01/29/197612.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[Linux]使linux默认从文本界面启动 </title><link>http://www.cppblog.com/niewenlong/archive/2008/08/24/59752.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sat, 23 Aug 2008 22:58:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2008/08/24/59752.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/59752.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2008/08/24/59752.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/59752.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/59752.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1.shell下键入vi /etc/inittab<br>2.将 id:5:initdefault 中的5改为3，那么默认的启动方式会改为文本模式。<br>注：<br>0 关机<br>1 单用户模式<br>2 多用户模式，但是不支持网络访问<br>3 多用户模式，文本模式启动<br>4 无定义的<br>5 图形化界面<br>6 重启&nbsp;&nbsp;<a href='http://www.cppblog.com/niewenlong/archive/2008/08/24/59752.html'>阅读全文</a><img src ="http://www.cppblog.com/niewenlong/aggbug/59752.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2008-08-24 06:58 <a href="http://www.cppblog.com/niewenlong/archive/2008/08/24/59752.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mysql日期和时间函数不求人</title><link>http://www.cppblog.com/niewenlong/archive/2008/08/15/58900.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Thu, 14 Aug 2008 16:28:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2008/08/15/58900.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/58900.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2008/08/15/58900.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/58900.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/58900.html</trackback:ping><description><![CDATA[<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">对于每个类型拥有的值范围以及并且指定日期何时间值的有效格式的描述见7.3.6 日期和时间类型。&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">这里是一个使用日期函数的例子。下面的查询选择了所有记录，其date_col的值是在最后30天以内：&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">mysql&gt; SELECT something FROM table&nbsp; <br>WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) &lt;= 30;&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">DAYOFWEEK(date)&nbsp; <br>返回日期date的星期索引(1=星期天，2=星期一, &#8230;&#8230;7=星期六)。这些索引值对应于ODBC标准。&nbsp; <br>mysql&gt; select DAYOFWEEK('1998-02-03');&nbsp; <br>-&gt; 3&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">WEEKDAY(date)&nbsp; <br>返回date的星期索引(0=星期一，1=星期二, &#8230;&#8230;6= 星期天)。&nbsp; <br>mysql&gt; select WEEKDAY('1997-10-04 22:23:00');&nbsp; <br>-&gt; 5&nbsp; <br>mysql&gt; select WEEKDAY('1997-11-05');&nbsp; <br>-&gt; 2&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">DAYOFMONTH(date)&nbsp; <br>返回date的月份中日期，在1到31范围内。&nbsp; <br>mysql&gt; select DAYOFMONTH('1998-02-03');&nbsp; <br>-&gt; 3&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">DAYOFYEAR(date)&nbsp; <br>返回date在一年中的日数, 在1到366范围内。&nbsp; <br>mysql&gt; select DAYOFYEAR('1998-02-03');&nbsp; <br>-&gt; 34&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">MONTH(date)&nbsp; <br>返回date的月份，范围1到12。&nbsp; <br>mysql&gt; select MONTH('1998-02-03');&nbsp; <br>-&gt; 2&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">DAYNAME(date)&nbsp; <br>返回date的星期名字。&nbsp; <br>mysql&gt; select DAYNAME("1998-02-05");&nbsp; <br>-&gt; 'Thursday'&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">MONTHNAME(date)&nbsp; <br>返回date的月份名字。&nbsp; <br>mysql&gt; select MONTHNAME("1998-02-05");&nbsp; <br>-&gt; 'February'&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">QUARTER(date)&nbsp; <br>返回date一年中的季度，范围1到4。&nbsp; <br>mysql&gt; select QUARTER('98-04-01');&nbsp; <br>-&gt; 2&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">WEEK(date)&nbsp; <br>　&nbsp; <br>WEEK(date,first)&nbsp; <br>对于星期天是一周的第一天的地方，有一个单个参数，返回date的周数，范围在0到52。2个参数形式WEEK()允许 <br>你指定星期是否开始于星期天或星期一。如果第二个参数是0，星期从星期天开始，如果第二个参数是1， <br>从星期一开始。&nbsp; <br>mysql&gt; select WEEK('1998-02-20');&nbsp; <br>-&gt; 7&nbsp; <br>mysql&gt; select WEEK('1998-02-20',0);&nbsp; <br>-&gt; 7&nbsp; <br>mysql&gt; select WEEK('1998-02-20',1);&nbsp; <br>-&gt; 8&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">YEAR(date)&nbsp; <br>返回date的年份，范围在1000到9999。&nbsp; <br>mysql&gt; select YEAR('98-02-03');&nbsp; <br>-&gt; 1998&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">HOUR(time)&nbsp; <br>返回time的小时，范围是0到23。&nbsp; <br>mysql&gt; select HOUR('10:05:03');&nbsp; <br>-&gt; 10&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">MINUTE(time)&nbsp; <br>返回time的分钟，范围是0到59。&nbsp; <br>mysql&gt; select MINUTE('98-02-03 10:05:03');&nbsp; <br>-&gt; 5&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">SECOND(time)&nbsp; <br>回来time的秒数，范围是0到59。&nbsp; <br>mysql&gt; select SECOND('10:05:03');&nbsp; <br>-&gt; 3&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">PERIOD_ADD(P,N)&nbsp; <br>增加N个月到阶段P（以格式YYMM或YYYYMM)。以格式YYYYMM返回值。注意阶段参数P不是日期值。&nbsp; <br>mysql&gt; select PERIOD_ADD(9801,2);&nbsp; <br>-&gt; 199803&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">PERIOD_DIFF(P1,P2)&nbsp; <br>返回在时期P1和P2之间月数，P1和P2应该以格式YYMM或YYYYMM。注意，时期参数P1和P2不是日期值。&nbsp; <br>mysql&gt; select PERIOD_DIFF(9802,199703);&nbsp; <br>-&gt; 11&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">DATE_ADD(date,INTERVAL expr type)&nbsp; <br>　&nbsp; <br>DATE_SUB(date,INTERVAL expr type)&nbsp; <br>　&nbsp; <br>ADDDATE(date,INTERVAL expr type)&nbsp; <br>　&nbsp; <br>SUBDATE(date,INTERVAL expr type)&nbsp; <br>这些功能执行日期运算。对于MySQL 3.22，他们是新的。ADDDATE()和SUBDATE()是DATE_ADD()和DATE_SUB()的同义词。 <br>在MySQL 3.23中，你可以使用+和-而不是DATE_ADD()和DATE_SUB()。（见例子）date是一个指定开始日期的 <br>DATETIME或DATE值，expr是指定加到开始日期或从开始日期减去的间隔值一个表达式，expr是一个字符串；它可以以 <br>一个&#8220;-&#8221;开始表示负间隔。type是一个关键词，指明表达式应该如何被解释。EXTRACT(type FROM date)函数从日期 <br>中返回&#8220;type&#8221;间隔。下表显示了type和expr参数怎样被关联： type值 含义 期望的expr格式&nbsp; <br>SECOND 秒 SECONDS&nbsp; <br>MINUTE 分钟 MINUTES&nbsp; <br>HOUR 时间 HOURS&nbsp; <br>DAY 天 DAYS&nbsp; <br>MONTH 月 MONTHS&nbsp; <br>YEAR 年 YEARS&nbsp; <br>MINUTE_SECOND 分钟和秒 "MINUTES:SECONDS"&nbsp; <br>HOUR_MINUTE 小时和分钟 "HOURS:MINUTES"&nbsp; <br>DAY_HOUR 天和小时 "DAYS HOURS"&nbsp; <br>YEAR_MONTH 年和月 "YEARS-MONTHS"&nbsp; <br>HOUR_SECOND 小时, 分钟， "HOURS:MINUTES:SECONDS"&nbsp; <br>DAY_MINUTE 天, 小时, 分钟 "DAYS HOURS:MINUTES"&nbsp; <br>DAY_SECOND 天, 小时, 分钟, 秒 "DAYS HOURS:MINUTES:SECONDS"&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">MySQL在expr格式中允许任何标点分隔符。表示显示的是建议的分隔符。如果date参数是一个DATE值并且你的计算仅仅 <br>包含YEAR、MONTH和DAY部分(即，没有时间部分)，结果是一个DATE值。否则结果是一个DATETIME值。&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">mysql&gt; SELECT "1997-12-31 23:59:59" + INTERVAL 1 SECOND;&nbsp; <br>-&gt; 1998-01-01 00:00:00&nbsp; <br>mysql&gt; SELECT INTERVAL 1 DAY + "1997-12-31";&nbsp; <br>-&gt; 1998-01-01&nbsp; <br>mysql&gt; SELECT "1998-01-01" - INTERVAL 1 SECOND;&nbsp; <br>-&gt; 1997-12-31 23:59:59&nbsp; <br>mysql&gt; SELECT DATE_ADD("1997-12-31 23:59:59",&nbsp; <br>INTERVAL 1 SECOND);&nbsp; <br>-&gt; 1998-01-01 00:00:00&nbsp; <br>mysql&gt; SELECT DATE_ADD("1997-12-31 23:59:59",&nbsp; <br>INTERVAL 1 DAY);&nbsp; <br>-&gt; 1998-01-01 23:59:59&nbsp; <br>mysql&gt; SELECT DATE_ADD("1997-12-31 23:59:59",&nbsp; <br>INTERVAL "1:1" MINUTE_SECOND);&nbsp; <br>-&gt; 1998-01-01 00:01:00&nbsp; <br>mysql&gt; SELECT DATE_SUB("1998-01-01 00:00:00",&nbsp; <br>INTERVAL "1 1:1:1" DAY_SECOND);&nbsp; <br>-&gt; 1997-12-30 22:58:59&nbsp; <br>mysql&gt; SELECT DATE_ADD("1998-01-01 00:00:00",&nbsp; <br>INTERVAL "-1 10" DAY_HOUR);&nbsp; <br>-&gt; 1997-12-30 14:00:00&nbsp; <br>mysql&gt; SELECT DATE_SUB("1998-01-02", INTERVAL 31 DAY);&nbsp; <br>-&gt; 1997-12-02&nbsp; <br>mysql&gt; SELECT EXTRACT(YEAR FROM "1999-07-02");&nbsp; <br>-&gt; 1999&nbsp; <br>mysql&gt; SELECT EXTRACT(YEAR_MONTH FROM "1999-07-02 01:02:03");&nbsp; <br>-&gt; 199907&nbsp; <br>mysql&gt; SELECT EXTRACT(DAY_MINUTE FROM "1999-07-02 01:02:03");&nbsp; <br>-&gt; 20102&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">如果你指定太短的间隔值(不包括type关键词期望的间隔部分)，MySQL假设你省掉了间隔值的最左面部分。例如， <br>如果你指定一个type是DAY_SECOND，值expr被希望有天、小时、分钟和秒部分。如果你象"1:10"这样指定值， <br>MySQL假设日子和小时部分是丢失的并且值代表分钟和秒。换句话说，"1:10" DAY_SECOND以它等价于"1:10" MINUTE_SECOND <br>的方式解释，这对那MySQL解释TIME值表示经过的时间而非作为一天的时间的方式有二义性。如果你使用确实不正确的日期， <br>结果是NULL。如果你增加MONTH、YEAR_MONTH或YEAR并且结果日期大于新月份的最大值天数，日子在新月用最大的天调整。&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">mysql&gt; select DATE_ADD('1998-01-30', Interval 1 month);&nbsp; <br>-&gt; 1998-02-28&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">注意，从前面的例子中词INTERVAL和type关键词不是区分大小写的。&nbsp; <br>TO_DAYS(date)&nbsp; <br>给出一个日期date，返回一个天数(从0年的天数)。&nbsp; <br>mysql&gt; select TO_DAYS(950501);&nbsp; <br>-&gt; 728779&nbsp; <br>mysql&gt; select TO_DAYS('1997-10-07');&nbsp; <br>-&gt; 729669&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">TO_DAYS()不打算用于使用格列高里历(1582)出现前的值。&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">FROM_DAYS(N)&nbsp; <br>给出一个天数N，返回一个DATE值。&nbsp; <br>mysql&gt; select FROM_DAYS(729669);&nbsp; <br>-&gt; '1997-10-07'&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">TO_DAYS()不打算用于使用格列高里历(1582)出现前的值。&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">DATE_FORMAT(date,format)&nbsp; <br>根据format字符串格式化date值。下列修饰符可以被用在format字符串中： %M 月名字(January&#8230;&#8230;December)&nbsp; <br>%W 星期名字(Sunday&#8230;&#8230;Saturday)&nbsp; <br>%D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。）&nbsp; <br>%Y 年, 数字, 4 位&nbsp; <br>%y 年, 数字, 2 位&nbsp; <br>%a 缩写的星期名字(Sun&#8230;&#8230;Sat)&nbsp; <br>%d 月份中的天数, 数字(00&#8230;&#8230;31)&nbsp; <br>%e 月份中的天数, 数字(0&#8230;&#8230;31)&nbsp; <br>%m 月, 数字(01&#8230;&#8230;12)&nbsp; <br>%c 月, 数字(1&#8230;&#8230;12)&nbsp; <br>%b 缩写的月份名字(Jan&#8230;&#8230;Dec)&nbsp; <br>%j 一年中的天数(001&#8230;&#8230;366)&nbsp; <br>%H 小时(00&#8230;&#8230;23)&nbsp; <br>%k 小时(0&#8230;&#8230;23)&nbsp; <br>%h 小时(01&#8230;&#8230;12)&nbsp; <br>%I 小时(01&#8230;&#8230;12)&nbsp; <br>%l 小时(1&#8230;&#8230;12)&nbsp; <br>%i 分钟, 数字(00&#8230;&#8230;59)&nbsp; <br>%r 时间,12 小时(hh:mm:ss [AP]M)&nbsp; <br>%T 时间,24 小时(hh:mm:ss)&nbsp; <br>%S 秒(00&#8230;&#8230;59)&nbsp; <br>%s 秒(00&#8230;&#8230;59)&nbsp; <br>%p AM或PM&nbsp; <br>%w 一个星期中的天数(0=Sunday &#8230;&#8230;6=Saturday ）&nbsp; <br>%U 星期(0&#8230;&#8230;52), 这里星期天是星期的第一天&nbsp; <br>%u 星期(0&#8230;&#8230;52), 这里星期一是星期的第一天&nbsp; <br>%% 一个文字&#8220;%&#8221;。&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">所有的其他字符不做解释被复制到结果中。&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">mysql&gt; select DATE_FORMAT('1997-10-04 22:23:00', '%W %M %Y');&nbsp; <br>-&gt; 'Saturday October 1997'&nbsp; <br>mysql&gt; select DATE_FORMAT('1997-10-04 22:23:00', '%H:%i:%s');&nbsp; <br>-&gt; '22:23:00'&nbsp; <br>mysql&gt; select DATE_FORMAT('1997-10-04 22:23:00',&nbsp; <br>'%D %y %a %d %m %b %j');&nbsp; <br>-&gt; '4th 97 Sat 04 10 Oct 277'&nbsp; <br>mysql&gt; select DATE_FORMAT('1997-10-04 22:23:00',&nbsp; <br>'%H %k %I %r %T %S %w');&nbsp; <br>-&gt; '22 22 10 10:23:00 PM 22:23:00 00 6'&nbsp; <br>MySQL3.23中，在格式修饰符字符前需要%。在MySQL更早的版本中，%是可选的。&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">TIME_FORMAT(time,format)&nbsp; <br>这象上面的DATE_FORMAT()函数一样使用，但是format字符串只能包含处理小时、分钟和秒的那些格式修饰符。 <br>其他修饰符产生一个NULL值或0。&nbsp; <br>CURDATE()&nbsp; <br>　&nbsp; <br>CURRENT_DATE&nbsp; <br>以'YYYY-MM-DD'或YYYYMMDD格式返回今天日期值，取决于函数是在一个字符串还是数字上下文被使用。&nbsp; <br>mysql&gt; select CURDATE();&nbsp; <br>-&gt; '1997-12-15'&nbsp; <br>mysql&gt; select CURDATE() + 0;&nbsp; <br>-&gt; 19971215&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">CURTIME()&nbsp; <br>　&nbsp; <br>CURRENT_TIME&nbsp; <br>以'HH:MM:SS'或HHMMSS格式返回当前时间值，取决于函数是在一个字符串还是在数字的上下文被使用。&nbsp; <br>mysql&gt; select CURTIME();&nbsp; <br>-&gt; '23:50:26'&nbsp; <br>mysql&gt; select CURTIME() + 0;&nbsp; <br>-&gt; 235026&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">NOW()&nbsp; <br>　&nbsp; <br>SYSDATE()&nbsp; <br>　&nbsp; <br>CURRENT_TIMESTAMP&nbsp; <br>以'YYYY-MM-DD HH:MM:SS'或YYYYMMDDHHMMSS格式返回当前的日期和时间，取决于函数是在一个字符串还是在数字的 <br>上下文被使用。&nbsp; <br>mysql&gt; select NOW();&nbsp; <br>-&gt; '1997-12-15 23:50:26'&nbsp; <br>mysql&gt; select NOW() + 0;&nbsp; <br>-&gt; 19971215235026&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">UNIX_TIMESTAMP()&nbsp; <br>　&nbsp; <br>UNIX_TIMESTAMP(date)&nbsp; <br>如果没有参数调用，返回一个Unix时间戳记(从'1970-01-01 00:00:00'GMT开始的秒数)。如果UNIX_TIMESTAMP()用一 <br>个date参数被调用，它返回从'1970-01-01 00:00:00' GMT开始的秒数值。date可以是一个DATE字符串、一个DATETIME <br>字符串、一个TIMESTAMP或以YYMMDD或YYYYMMDD格式的本地时间的一个数字。&nbsp; <br>mysql&gt; select UNIX_TIMESTAMP();&nbsp; <br>-&gt; 882226357&nbsp; <br>mysql&gt; select UNIX_TIMESTAMP('1997-10-04 22:23:00');&nbsp; <br>-&gt; 875996580&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">当UNIX_TIMESTAMP被用于一个TIMESTAMP列，函数将直接接受值，没有隐含的&#8220;string-to-unix-timestamp&#8221;变换。&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">FROM_UNIXTIME(unix_timestamp)&nbsp; <br>以'YYYY-MM-DD HH:MM:SS'或YYYYMMDDHHMMSS格式返回unix_timestamp参数所表示的值，取决于函数是在一个字符串 <br>还是或数字上下文中被使用。&nbsp; <br>mysql&gt; select FROM_UNIXTIME(875996580);&nbsp; <br>-&gt; '1997-10-04 22:23:00'&nbsp; <br>mysql&gt; select FROM_UNIXTIME(875996580) + 0;&nbsp; <br>-&gt; 19971004222300&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">FROM_UNIXTIME(unix_timestamp,format)&nbsp; <br>返回表示 Unix 时间标记的一个字符串，根据format字符串格式化。format可以包含与DATE_FORMAT()函数列出的条 <br>目同样的修饰符。&nbsp; <br>mysql&gt; select FROM_UNIXTIME(UNIX_TIMESTAMP(),&nbsp; <br>'%Y %D %M %h:%i:%s %x');&nbsp; <br>-&gt; '1997 23rd December 03:43:30 x'&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">SEC_TO_TIME(seconds)&nbsp; <br>返回seconds参数，变换成小时、分钟和秒，值以'HH:MM:SS'或HHMMSS格式化，取决于函数是在一个字符串还是在数字 <br>上下文中被使用。&nbsp; <br>mysql&gt; select SEC_TO_TIME(2378);&nbsp; <br>-&gt; '00:39:38'&nbsp; <br>mysql&gt; select SEC_TO_TIME(2378) + 0;&nbsp; <br>-&gt; 3938&nbsp; </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">TIME_TO_SEC(time)&nbsp; <br>返回time参数，转换成秒。&nbsp; <br>mysql&gt; select TIME_TO_SEC('22:23:00');&nbsp; <br>-&gt; 80580&nbsp; <br>mysql&gt; select TIME_TO_SEC('00:39:38');&nbsp; <br>-&gt; 2378 </p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;</p>
<img src ="http://www.cppblog.com/niewenlong/aggbug/58900.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2008-08-15 00:28 <a href="http://www.cppblog.com/niewenlong/archive/2008/08/15/58900.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>安装JAVA</title><link>http://www.cppblog.com/niewenlong/archive/2008/07/27/57299.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sun, 27 Jul 2008 06:46:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2008/07/27/57299.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/57299.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2008/07/27/57299.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/57299.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/57299.html</trackback:ping><description><![CDATA[<p style="FONT-FAMILY: Verdana"><br>jdk-6u10-beta-linux-i586-rpm.bin<br>[root@localhost java]# chmod a+x jdk-6u10-beta-linux-i586-rpm.bin<br>[root@localhost java]# ./jdk-6u10-beta-linux-i586-rpm.bin<br>Pre-Release Software Evaluation Agreement</p>
<p style="FONT-FAMILY: Verdana">SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE<br>THE JAVA SE DEVELOPMENT KIT (JDK), VERSION 6<br>PRE-RELEASE SOFTWARE TO LICENSEE ONLY UPON THE<br>CONDITION THAT LICENSEE ACCEPTS ALL OF THE TERMS<br>CONTAINED IN THIS LICENSE AGREEMENT ("AGREEMENT").<br>PLEASE READ THE TERMS AND CONDITIONS OF THIS AGREEMENT<br>CAREFULLY. BY DOWNLOADING OR INSTALLING THIS SOFTWARE,<br>LICENSEE ACCEPTS THE TERMS AND CONDITIONS OF THIS<br>LICENSE AGREEMENT. INDICATE ACCEPTANCE BY SELECTING<br>THE "ACCEPT" BUTTON AT THE BOTTOM OF THIS AGREEMENT.<br>IF LICENSEE IS NOT WILLING TO BE BOUND BY ALL THE<br>TERMS, SELECT THE "DECLINE" BUTTON AT THE BOTTOM OF<br>THE AGREEMENT AND THE DOWNLOAD OR INSTALL PROCESS WILL<br>NOT CONTINUE.</p>
<p style="FONT-FAMILY: Verdana">1.0 DEFINITIONS "Licensed Software" means the Java SE<br>Development Kit (JDK), Version 6 pre-release software<br>in binary and/or source code forms, any other machine<br>readable materials (including, but not limited to,<br>libraries, source files, header files, and data<br>files), Feedback (as defined in Section 5.0), any user<br>manuals, programming guides and other documentation<br>provided to Licensee by Sun under this Agreement.</p>
<p style="FONT-FAMILY: Verdana">2.0 LIMITED LICENSE</p>
<p style="FONT-FAMILY: Verdana">2.1 Source Code. Sun grants to Licensee, a<br>non-exclusive, non-transferable, royalty-free and<br>limited license to view the source code portions of<br>the Licensed Software internally for the purposes of<br>evaluation only.</p>
<p style="FONT-FAMILY: Verdana">2.2 Binary Code. Sun grants to Licensee, a<br>non-exclusive, non-transferable, royalty-free and<br>limited license to use the binary code portions of the<br>Licensed Software internally for the purposes of<br>evaluation only.</p>
<p style="FONT-FAMILY: Verdana">2.3 No licenses are granted to Licensee for any other<br>purposes, Licensee may not sell, rent, loan or<br>otherwise encumber or transfer Licensed Software in<br>whole or in part, to any third party.</p>
<p style="FONT-FAMILY: Verdana">3.0 LICENSE RESTRICTIONS</p>
<p style="FONT-FAMILY: Verdana">3.1 Licensee may not duplicate Licensed Software other<br>than for a single copy of Licensed Software for<br>archival purposes only. Licensee agrees to reproduce<br>any copyright and other proprietary right notices on<br>any such copy.</p>
<p style="FONT-FAMILY: Verdana">3.2 Licensed Software is "Confidential Information".<br>Licensee may not disclose or use Confidential<br>Information, except for the purposes specified in this<br>Agreement. Licensee will protect the Confidential<br>Information with the same degree of care, as Licensee<br>uses to protect its own Confidential Information.</p>
<p style="FONT-FAMILY: Verdana">3.3 Except as otherwise provided by law, Licensee may<br>not modify or create derivative works of the Licensed<br>Software, or reverse engineer, disassemble or<br>decompile binary portions of the Licensed Software, or<br>otherwise attempt to derive the source code from such<br>portions.</p>
<p style="FONT-FAMILY: Verdana">3.4 No right, title, or interest in or to Licensed<br>Software, any trademarks, service marks, or trade<br>names of Sun or Sun's licensors is granted under this<br>Agreement.</p>
<p style="FONT-FAMILY: Verdana">3.5 Licensee shall have no right to use the Licensed<br>Software for productive or commercial use.</p>
<p style="FONT-FAMILY: Verdana">3.6&nbsp; Notwithstanding sections 3.1 and 3.3, and as a<br>special exception thereto, Licensee may use the files<br>from the Licensed Software with a virtual machine ("VM")<br>derived from the HotSpot Virtual Machine source code<br>("HotSpot") found at openjdk.dev.java.net.&nbsp; This<br>exception is subject to and conditioned upon the<br>following: (i) The VM was created in accordance with<br>the license terms governing "HotSpot";&nbsp; (ii) Any<br>activity under this exception is conducted solely<br>internally and for evaluation purposes only; and<br>(iii) Licensee is in compliance with all other terms<br>of this License.</p>
<p style="FONT-FAMILY: Verdana">4.0 NO SUPPORT Sun is under no obligation to support<br>Licensed Software or to provide Licensee with updates<br>or error corrections (collectively "Software<br>Updates"). If Sun, at its sole option, supplies<br>Software Updates to Licensee, the Software Updates<br>will be considered part of Licensed Software, and<br>subject to the terms of this Agreement.</p>
<p style="FONT-FAMILY: Verdana">5.0 LICENSEE DUTIES Licensee agrees to evaluate and<br>test the Software for use in Licensee's software<br>environment and provide feedback to Sun in a manner<br>reasonably requested by Sun. Any and all test results,<br>error data, reports or other information, feedback or<br>materials made or provided by Licensee relating to<br>Software (collectively, "Feedback") are the exclusive<br>property of Sun and Licensee hereby assigns all<br>Feedback to Sun at no cost to Sun. Sun may use such<br>Feedback in any manner and for any purpose, without<br>limitation, liability or obligation to Licensee.</p>
<p style="FONT-FAMILY: Verdana">6.0 TERM AND TERMINATION OF AGREEMENT</p>
<p style="FONT-FAMILY: Verdana">6.1 This Agreement will commence on the date on which<br>Licensee receives Licensed Software (the "Effective<br>Date") and will expire twelve (12) months from the<br>Effective Date, unless terminated earlier as provided<br>herein.</p>
<p style="FONT-FAMILY: Verdana">6.2 Either party may terminate this Agreement upon ten<br>(10) days' written notice to the other party. However,<br>Sun may terminate this Agreement immediately should<br>any Licensed Software become, or in Sun's opinion be<br>likely to become, the subject of a claim of<br>infringement of a patent, trade secret or copyright.</p>
<p style="FONT-FAMILY: Verdana">6.3 Sun may terminate this Agreement immediately<br>should Licensee materially breach any of its<br>provisions or take any action in derogation of Sun's<br>rights to the Confidential Information licensed to<br>Licensee.</p>
<p style="FONT-FAMILY: Verdana">6.4 Upon termination or expiration of this Agreement,<br>Licensee will immediately cease use of and destroy<br>Licensed Software, any copies thereof.</p>
<p style="FONT-FAMILY: Verdana">6.5 Rights and obligations under this Agreement which<br>by their nature should survive, will remain in effect<br>after termination or expiration hereof.</p>
<p style="FONT-FAMILY: Verdana">7.0 INSTALLATION AND AUTO-UPDATE.</p>
<p style="FONT-FAMILY: Verdana">The Software's installation and auto-update processes<br>transmit a limited amount of data to Sun (or its<br>service provider) about those specific processes to<br>help Sun understand and optimize them.&nbsp; Sun does not<br>associate the data with personally identifiable<br>information.&nbsp; You can find more information about the<br>data Sun collects at <a href="http://java.com/data/">http://java.com/data/</a>.</p>
<p style="FONT-FAMILY: Verdana">8.0 DISCLAIMER OF WARRANTY</p>
<p style="FONT-FAMILY: Verdana">8.1 Licensee acknowledges that Licensed Software may<br>contain errors and is not designed, licensed, or<br>intended for use in the design, construction,<br>operation or maintenance of any nuclear facility<br>("HighRisk Activities"). Sun disclaims any express or<br>implied warranty of fitness for such uses. Licensee<br>represents and warrants to Sun that it will not use,<br>distribute or license the Licensed Software for High<br>Risk Activities.</p>
<p style="FONT-FAMILY: Verdana">8.2 LICENSED SOFTWARE IS PROVIDED "AS IS". ALL EXPRESS<br>OR IMPLIED CONDITIONS, REPRESENTATIONS, AND<br>WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF<br>MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A<br>PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE<br>DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS<br>ARE HELD TO BE LEGALLY INVALID.</p>
<p style="FONT-FAMILY: Verdana">9.0 LIMITATION OF LIABILITY</p>
<p style="FONT-FAMILY: Verdana">9.1 Licensee acknowledges that the Licensed Software<br>may be experimental and that the Licensed Software may<br>have defects or deficiencies, which cannot or will not<br>be corrected by Sun. Licensee will hold Sun harmless<br>from any claims based on Licensee's use of the<br>Licensed Software for any purposes other than those of<br>internal evaluation, and from any claims that later<br>versions or releases of any Licensed Software<br>furnished to Licensee are incompatible with the<br>Licensed Software provided to Licensee under this<br>Agreement.</p>
<p style="FONT-FAMILY: Verdana">9.2 To the extent not prohibited by law, in no event<br>will Sun be liable for any indirect, punitive,<br>special, incidental or consequential damage in<br>connection with or arising out of this Agreement<br>(including loss of business, revenue, profits, use,<br>data or other economic advantage), however it arises,<br>whether for breach or in tort, even if Sun has been<br>previously advised of the possibility of such damage.</p>
<p style="FONT-FAMILY: Verdana">10.0 U.S. GOVERNMENT RESTRICTED RIGHTS If this Software<br>is being acquired by or on behalf of the U.S.<br>Government or by a U.S. Government prime contractor or<br>subcontractor (at any tier), then the Government's<br>rights in the Software and accompanying documentation<br>shall be only as set forth in this license; this is in<br>accordance with 48 C.F.R. 227.7202-4 (for Department<br>of Defense (DOD) acquisitions) and with 48 C.F.R.<br>2.101 and 12.212 (for non-DOD acquisitions).</p>
<p style="FONT-FAMILY: Verdana">11.0 GENERAL TERMS</p>
<p style="FONT-FAMILY: Verdana">11.1 Any action relating to or arising out of this<br>Agreement will be governed by California law and<br>controlling U.S. federal law. The U.N. Convention for<br>the International Sale of Goods and the choice of law<br>rules of any jurisdiction will not apply.</p>
<p style="FONT-FAMILY: Verdana">11.2 Licensed Software and technical data delivered<br>under this Agreement are subject to U.S. export<br>control laws and may be subject to export or import<br>regulations in other countries. Licensee agrees to<br>comply strictly with all such laws and regulations and<br>acknowledges that it has the responsibility to obtain<br>such licenses to export, re-export or import as may be<br>required after delivery to Licensee.</p>
<p style="FONT-FAMILY: Verdana">11.3 It is understood and agreed that, notwithstanding<br>any other provision of this Agreement, Licensee's<br>breach of this Agreement will cause Sun irreparable<br>damage for which recovery of money damages would be<br>inadequate, and that Sun will therefore be entitled to<br>seek timely injunctive relief to protect Sun's rights<br>under this Agreement in addition to any and all<br>remedies available at law.</p>
<p style="FONT-FAMILY: Verdana">11.4 Neither party may assign or otherwise transfer<br>any of its rights or obligations under this Agreement,<br>without the prior written consent of the other party,<br>except that Sun may assign this Agreement to an<br>affiliated company.</p>
<p style="FONT-FAMILY: Verdana">11.5 This Agreement is the parties' entire agreement<br>relating to its subject matter. It supersedes all<br>prior or contemporaneous oral or written<br>communications, proposals, conditions, representations<br>and warranties and prevails over any conflicting or<br>additional terms of any quote, order, acknowledgment,<br>or other communication between the parties relating to<br>its subject matter, including any Binary Code<br>Licenses, Supplemental Terms, or other licenses<br>contained within Licensed Software. No modification to<br>this Agreement will be binding, unless in writing and<br>signed by an authorized representative of each party.<br>(LFI#151319/Form ID#011801)</p>
<p style="FONT-FAMILY: Verdana"><br>Do you agree to the above license terms? [yes or no]</p>
<p style="FONT-FAMILY: Verdana">&nbsp;</p>
<p style="FONT-FAMILY: Verdana">&nbsp;</p>
<p style="FONT-FAMILY: Verdana">&nbsp;</p>
<p style="FONT-FAMILY: Verdana">&nbsp;</p>
<p style="FONT-FAMILY: Verdana"><br>yes<br>Unpacking...<br>Checksumming...<br>Extracting...<br>UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#90;&#105;&#112;&#45;&#66;&#117;&#103;&#115;&#64;&#108;&#105;&#115;&#116;&#115;&#46;&#119;&#107;&#117;&#46;&#101;&#100;&#117;">Zip-Bugs@lists.wku.edu</a>).<br>&nbsp; inflating: jdk-6u10-beta-linux-i586.rpm<br>&nbsp; inflating: sun-javadb-common-10.4.1-3.1.i386.rpm<br>&nbsp; inflating: sun-javadb-core-10.4.1-3.1.i386.rpm<br>&nbsp; inflating: sun-javadb-client-10.4.1-3.1.i386.rpm<br>&nbsp; inflating: sun-javadb-demo-10.4.1-3.1.i386.rpm<br>&nbsp; inflating: sun-javadb-docs-10.4.1-3.1.i386.rpm<br>&nbsp; inflating: sun-javadb-javadoc-10.4.1-3.1.i386.rpm<br>Preparing...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ########################################### [100%]<br>&nbsp;&nbsp; 1:jdk&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ########################################### [100%]<br>Unpacking JAR files...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rt.jar...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jsse.jar...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; charsets.jar...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tools.jar...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; localedata.jar...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plugin.jar...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; javaws.jar...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; deploy.jar...<br>Installing JavaDB<br>Preparing...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ########################################### [100%]<br>&nbsp;&nbsp; 1:sun-javadb-common&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ########################################### [ 17%]<br>&nbsp;&nbsp; 2:sun-javadb-core&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ########################################### [ 33%]<br>&nbsp;&nbsp; 3:sun-javadb-client&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ########################################### [ 50%]<br>&nbsp;&nbsp; 4:sun-javadb-demo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ########################################### [ 67%]<br>&nbsp;&nbsp; 5:sun-javadb-docs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ########################################### [ 83%]<br>&nbsp;&nbsp; 6:sun-javadb-javadoc&nbsp;&nbsp;&nbsp;&nbsp; ########################################### [100%]</p>
<p style="FONT-FAMILY: Verdana">Done.<br>[root@localhost java]# vi /etc/profile<br>[root@localhost java]# source /etc/profile</p>
<p style="FONT-FAMILY: Verdana">[root@localhost java]#<br>[root@localhost java]# env<br>KDE_MULTIHEAD=false<br>SSH_AGENT_PID=5201<br>HOSTNAME=localhost.localdomain<br>TERM=xterm<br>SHELL=/bin/bash<br>HISTSIZE=1000<br>GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/root/.gtkrc-2.0:/root/.kde/share/config/gtkrc-2.0<br>KDE_NO_IPV6=1<br>GTK_RC_FILES=/etc/gtk/gtkrc:/root/.gtkrc:/root/.kde/share/config/gtkrc<br>GS_LIB=/root/.fonts<br>WINDOWID=37748743<br>QTDIR=/usr/lib/qt-3.3<br>QTINC=/usr/lib/qt-3.3/include<br>KDE_FULL_SESSION=true<br>USER=root<br>LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:<br>SSH_AUTH_SOCK=/tmp/ssh-JCjHpF5168/agent.5168<br>KDEDIR=/usr<br>SESSION_MANAGER=local/localhost.localdomain:/tmp/.ICE-unix/5379<br>XDG_CONFIG_DIRS=/etc/kde/xdg:/etc/xdg<br>KONSOLE_DCOP=DCOPRef(konsole-5629,konsole)<br>MAIL=/var/spool/mail/root<br>PATH=/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/usr/java/jdk1.6.0_10/bin<br>DESKTOP_SESSION=kde<br>QT_IM_MODULE=scim<br>GDM_XSERVER_LOCATION=local<br>KONSOLE_DCOP_SESSION=DCOPRef(konsole-5629,session-1)<br>INPUTRC=/etc/inputrc<br>PWD=/usr/local/java<br>JAVA_HOME=/usr/java/jdk1.6.0_10<br><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#88;&#77;&#79;&#68;&#73;&#70;&#73;&#69;&#82;&#83;&#61;&#64;&#105;&#109;&#61;&#83;&#67;&#73;&#77;">XMODIFIERS=@im=SCIM</a><br>KDE_IS_PRELINKED=1<br>LANG=zh_CN.UTF-8<br>GDMSESSION=kde<br>XERCESCROOT=/home/soft/xerces-c-src_2_8_0<br>SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass<br>SHLVL=3<br>HOME=/root<br>XCURSOR_THEME=default<br>LOGNAME=root<br>QTLIB=/usr/lib/qt-3.3/lib<br>CVS_RSH=ssh<br>CLASSPATH=/usr/java/jdk1.6.0_10/lib:.<br>DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-FGw3oIRYzq,guid=7c118c48fd191781b3038c562a018700<br>LESSOPEN=|/usr/bin/lesspipe.sh %s<br>DISPLAY=:0.0<br>GTK_IM_MODULE=scim-bridge<br>G_BROKEN_FILENAMES=1<br>COLORTERM=<br>XAUTHORITY=/tmp/.gdmYVAKEU<br>_=/bin/env<br>[root@localhost java]# java -version<br>java version "1.4.2"<br>gij (GNU libgcj) version 4.1.2 20071124 (Red Hat 4.1.2-42)</p>
<p style="FONT-FAMILY: Verdana">Copyright (C) 2006 Free Software Foundation, Inc.<br>This is free software; see the source for copying conditions.&nbsp; There is NO<br>warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.<br>[root@localhost java]#&nbsp;&nbsp;&nbsp;&nbsp; </p>
<img src ="http://www.cppblog.com/niewenlong/aggbug/57299.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2008-07-27 14:46 <a href="http://www.cppblog.com/niewenlong/archive/2008/07/27/57299.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Centos 快速yum 安装程序</title><link>http://www.cppblog.com/niewenlong/archive/2008/07/17/56445.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Thu, 17 Jul 2008 08:41:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2008/07/17/56445.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/56445.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2008/07/17/56445.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/56445.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/56445.html</trackback:ping><description><![CDATA[<p>　　仅仅适用于 centos 5.0 以上系统(5.0下我没有测试)</p>
<p>　　因为Centos 5.0 的yum 版本已经上升到3,所以yum有个插件名叫</p>
<p>　　yum-fastestmirror</p>
<p>　　这个插件能检查到你机器最快的镜像</p>
<p>　　这个插件安装也很简单</p>
<p>　　yum -y install yum-fastestmirror</p>
<p>　　然后你再使用yum安装其他软件就会发现速度快多了</p>
<p><br>&nbsp;</p>
<img src ="http://www.cppblog.com/niewenlong/aggbug/56445.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2008-07-17 16:41 <a href="http://www.cppblog.com/niewenlong/archive/2008/07/17/56445.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How to Install VMware Tools on Ubuntu Hardy 8.04 under VMware Fusion </title><link>http://www.cppblog.com/niewenlong/archive/2008/07/08/55666.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Tue, 08 Jul 2008 14:01:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2008/07/08/55666.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/55666.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2008/07/08/55666.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/55666.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/55666.html</trackback:ping><description><![CDATA[<p><img alt="Ubuntu Hardy under VMware Fusion" src="http://peterc.org/wp-content/uploads/2008/04/vmwarefusionhardy.jpg"></p>
<p>The latest version of <a href="http://www.ubuntu.com/"><u><font color=#0000ff>Ubuntu</font></u></a> (8.04 a.k.a. Ubuntu Hardy - the world&#8217;s most popular Linux distribution) came out yesterday on April 24th. I downloaded it right away to play with on VMware Fusion, my Mac virtualization tool of choice (though I&#8217;ve now been told this works in VMware Workstation and VMware Player on the PC too!). It worked pretty well out of the box, with even seamless mouse support working right away, but I needed, of course, to install VMware Tools too, as any good VMware user would do. From there, things turned sour, and I was bombarded with error messages similar to:</p>
<blockquote>
<p><code><small>In file included from /tmp/vmware-config8/vmblock-only/linux/os.h:35,<br>from /tmp/vmware-config8/vmblock-only/linux/block.c:26:<br>/tmp/vmware-config8/vmblock-only/./include/compat_wait.h:78: error: conflicting types for &#8216;poll_initwait&#8217;<br>include/linux/poll.h:65: error: previous declaration of &#8216;poll_initwait&#8217; was here<br>In file included from /tmp/vmware-config8/vmblock-only/linux/vmblockInt.h:40,<br>from /tmp/vmware-config8/vmblock-only/linux/block.c:29:<br>/tmp/vmware-config8/vmblock-only/./include/vm_basic_types.h:184: error: conflicting types for &#8216;uintptr_t&#8217;<br>include/linux/types.h:40: error: previous declaration of &#8216;uintptr_t&#8217; was here<br>make[2]: *** [/tmp/vmware-config8/vmblock-only/linux/block.o] Error 1<br>make[1]: *** [_module_/tmp/vmware-config8/vmblock-only] Error 2<br>make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-16-generic&#8217;<br>make: *** [vmblock.ko] Error 2<br>make: Leaving directory `/tmp/vmware-config8/vmblock-only&#8217;<br>Unable to build the vmblock module.</small></code></p>
</blockquote>
<p>After banging my head against the wall for a while, trying a &#8220;vmware-any-any&#8221; patch that didn&#8217;t quite do the trick, and scouring the VMWare Fusion and Ubuntu Forums, I eventually came across a link to <a href="http://diamondsw.dyndns.org/Home/Et_Cetera/Entries/2008/4/25_Linux_2.6.24_and_VMWare.html"><u><font color=#0000ff>a page that described how to solve the problem.</font></u></a> The credit for this solution rests entirely on the guy who wrote that page and a guy called Mufassa who posted <a href="http://communities.vmware.com/message/887802#887802"><u><font color=#0000ff>a shorter explanation</font></u></a> to the VMware Fusion forums.</p>
<p>I wanted to write this up into a proper blog post though for two reasons. Firstly, I wanted to show how to fix the problem in a more, direct line by line way (just in case you&#8217;re a novice or would rather follow some command line instructions). Secondly, I know posts on this blog appear in Google very quickly, so I want people Googling for &#8220;vmware fusion&#8221; and &#8220;ubuntu hardy&#8221; (like I was earlier) to find this page and have their problem solved! So, credit to those other guys, but..</p>
<p><big><strong>Steps To Getting VMware Tools installed on Ubuntu Hardy under VMware Fusion:</strong></big></p>
<p>Use the &#8220;Install VMware Tools&#8221; option in VMWare Fusion, and drag the .tar file (not the RPM!) to the Ubuntu desktop.</p>
<p>Open a Terminal (Applications menu -&gt; Accessories -&gt; Terminal). We&#8217;ll do all the work from the Terminal. First, we need to install some dependencies:</p>
<blockquote>
<p><code>sudo apt-get install build-essential libgtk2.0-dev<br>sudo apt-get install libproc-dev libdumbnet-dev xorg-dev<br>cd Desktop/</code></p>
<p>wget http://mesh.dl.sourceforge.net/sourceforge/open-vm-tools/open-vm-tools-2008.04.14-87182.tar.gz</p>
</blockquote>
<p>Next, we need to unpack the tar files we have at hand:</p>
<blockquote>
<p><code>tar xzvf VMware*.gz<br>tar xzvf open-vm-tools*.gz</code></p>
</blockquote>
<p>Next, we&#8217;ll build the open-vm-tools:</p>
<blockquote>
<p><code>cd open-vm-tools-2008.04.14-87182/<br>./configure &amp;&amp; make<br>cd modules/linux/</code></p>
</blockquote>
<p>In the modules/linux folder we have the vmblock, vmhgfs, vmmemctl, vmsync and vmxnet modules that we need to tar up and place into the official VMware tools tarball:</p>
<blockquote>
<p><code>for i in *; do mv ${i} ${i}-only; tar -cf ${i}.tar ${i}-only; done<br>cd ../../..</code></p>
<p>mv -f open-vm-tools-2008.04.14-87182/modules/linux/*.tar vmware-tools-distrib/lib/modules/source/</p>
</blockquote>
<p>Now we can run the regular VMware tools installer:</p>
<blockquote>
<p><code>cd vmware-tools-distrib/<br>sudo ./vmware-install.pl</code></p>
</blockquote>
<p>Once this is done, the best tactic is to restart Ubuntu entirely. Once you boot back up, things should seem a bit smoother. The resolution of the VM will stick to the size of the VM, etc, and you can now drag files directly into Ubuntu Hardy from your Mac desktop!</p>
<p><em>Note: A few of the lines of code you need to use above are single lines of code but spread over multiple lines on your screen when viewing this blog. Either make your browser wider, or copy and paste them into a text editor before continuing.</em></p>
<br clear=left>
<img src ="http://www.cppblog.com/niewenlong/aggbug/55666.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2008-07-08 22:01 <a href="http://www.cppblog.com/niewenlong/archive/2008/07/08/55666.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VMware中安装Ubuntu后鼠标滚轮问题解决 </title><link>http://www.cppblog.com/niewenlong/archive/2008/07/08/55655.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Tue, 08 Jul 2008 10:59:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2008/07/08/55655.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/55655.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2008/07/08/55655.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/55655.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/55655.html</trackback:ping><description><![CDATA[<div class=newmaincontent_newmain>　　Windows中通过VMware嵌套Ubuntu，发现鼠标滚轮功能不能使用。网上找了一下，都说是要将xorg.conf配置文件的问题，改动过程：
<p style="TEXT-INDENT: 2em">
<p style="TEXT-INDENT: 2em">sudo gedit /etc/X11/xorg.conf
<p style="TEXT-INDENT: 2em">
<p style="TEXT-INDENT: 2em">将"Input Device" 这个section的
<p style="TEXT-INDENT: 2em">Option "Protocol" "ps/2"
<p style="TEXT-INDENT: 2em">替换为
<p style="TEXT-INDENT: 2em">Option "Protocol" "IMPS/2"
<p style="TEXT-INDENT: 2em">
<p style="TEXT-INDENT: 2em">我的xorg.conf原来没有这个语句，就添加了。
<p style="TEXT-INDENT: 2em">
<p style="TEXT-INDENT: 2em">Ctrl+alt+backspace 重启X，还是没有效果。
<p style="TEXT-INDENT: 2em">
<p style="TEXT-INDENT: 2em">网上在查了下，发现我的配置还少了句：
<p style="TEXT-INDENT: 2em">
<p style="TEXT-INDENT: 2em">Option "Emulate3Buttons" "yes&#8220;
<p style="TEXT-INDENT: 2em">另外，我的驱动是: Driver "vmmouse"
<p style="TEXT-INDENT: 2em">而一般常见的是: Driver "mouse"
<p style="TEXT-INDENT: 2em">
<p style="TEXT-INDENT: 2em">完整的配置段落：
<p style="TEXT-INDENT: 2em">Section "InputDevice"
<p style="TEXT-INDENT: 2em">Identifier "Configured Mouse"
<p style="TEXT-INDENT: 2em">Driver "vmmouse"
<p style="TEXT-INDENT: 2em">Option "Protocol" "ImPS/2"
<p style="TEXT-INDENT: 2em">Option "CorePointer"
<p style="TEXT-INDENT: 2em">Option "Device" "/dev/input/mice"
<p style="TEXT-INDENT: 2em">Option "ZAxisMapping" "4 5"
<p style="TEXT-INDENT: 2em">Option "Emulate3Buttons" "yes"
<p style="TEXT-INDENT: 2em">EndSection
<p style="TEXT-INDENT: 2em">
<p style="TEXT-INDENT: 2em"></p>
</div>
<img src ="http://www.cppblog.com/niewenlong/aggbug/55655.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2008-07-08 18:59 <a href="http://www.cppblog.com/niewenlong/archive/2008/07/08/55655.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何在Linux使用Eclipse + CDT开发C/C++程序? (OS) (Linux) (C/C++) (gcc) (g++) </title><link>http://www.cppblog.com/niewenlong/archive/2008/07/02/55158.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Wed, 02 Jul 2008 09:19:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2008/07/02/55158.html</guid><description><![CDATA[<p><strong style="FONT-SIZE: 14pt"><span style="FONT-SIZE: 10pt">A.&nbsp;为什么要在Linux使用Eclipse开发C/C++程序?</span>&nbsp;</strong><br><br>Linux是一个以C/C++开发为主的平台，无论是Kernel或是Application，主要都使用C/C++开发。传统在Linux下开发程序，是在文字模式下，利用vi等文字编辑器撰写C/C++程序存盘后，在Command line下使用gcc编译，若要debug，则使用gdb。<br><br><br></p>
<p>这种开发方式生产力并不高，若只是开发学习用的小程序则影响不大，但若要开发大型项目时，程序档案个数众多，需要用project或solution的方式管理；且debug时breakpoint的加入，单步执行，观察变量变化等，都需要更可视化的方式才能够增加生产力；最重要的，由于现在的程序语言皆非常的庞大，又有复杂的函式库，要程序员熟记所有的程序语法和function名称，实在很困难，所以语法提示(Intellisense)的功能就非常重要，这些就必须靠IDE来达成。</p>
<p><br>在Windows平台上，若要开发C/C++程序，我们有Microsoft Visual Studio、Borland C++ Builder可用，这些都是很好用的IDE，但可惜仅能在Windows下使用，但是在Linux平台呢?基于以下理由，我推荐使用Eclipse开发C/C++程序：<br><br><br>1.&nbsp;Eclipse是一个用Java所撰写IDE，因此可跨平台，所以在Linux和Windows平台下皆可使用Eclipse，可降低程序员熟析IDE的学习曲线。<br><br><br>2.&nbsp;Eclipse虽然主要拿来开发Java程序，但事实上Eclipse为一个『万用语言』的IDE，只要挂上plugin后，就可以在Eclipse开发各种语言程序，所以我们只要挂上CDT(C/C++ Development Toolkit)后，就可以在Eclipse开发C/C++程序，除此之外，目前的主流程序语言，如C/C++、C#、Java、PHP、Perl、Python、Ruby、Rebol、JavaScript、SQL、XML、UML等，皆可在Eclipse上撰写，所以只要熟析Eclipse的IDE环境，将来若开发其它语言程序，就不用再重新学习IDE环境了。<br><br><br>3.&nbsp;最重要的，Eclipse和CDT是Open Source且完全免费，取得相当容易，事实上Fedora 5已经包含Eclipse和CDT了，虽然预设Fedara 5安装时并没有含Eclipse，只要手动另外加选即可。</p>
<p><br><strong style="FONT-SIZE: 10pt">B.&nbsp;如何在Linux下安装Eclipse和CDT?</strong>&nbsp; <br>i.&nbsp;由Linux Distribution安装Eclipse，Fedora 5就内含Eclipse和CDT。<br><br>ii.&nbsp;手动安装<br>&nbsp; 1.&nbsp;下载档案<br>&nbsp;&nbsp;&nbsp; A、&nbsp;下载JRE(Java Runtime Environment) 。(<a href="http://java.sun.com/javase/downloads/index.jsp" target=_blank><u><font color=#810081>http://java.sun.com/javase/downloads/index.jsp</font></u></a>)<br><br>&nbsp;&nbsp;&nbsp; B、&nbsp;下载Eclipse SDK。(<a href="http://www.eclipse.org/downloads/" target=_blank><u><font color=#810081>http://www.eclipse.org/downloads/</font></u></a>)<br><br>&nbsp;&nbsp;&nbsp; C、&nbsp;下载CDT。(<a href="http://www.eclipse.org/cdt/downloads.php" target=_blank><u><font color=#810081>http://www.eclipse.org/cdt/downloads.php</font></u></a>)<br><br>&nbsp; 2.&nbsp;安装<br>&nbsp;&nbsp;&nbsp; <strong>A、&nbsp;安装JRE</strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i.&nbsp;[root@localhost ~]#mkdir /usr/local/java<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ii.&nbsp;<span style="COLOR: #008000">(将档案jre-1_5_0_09-linux-i586-rpm.bin下载到/usr/local/java目录下)<br></span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iii.&nbsp;<span style="COLOR: #008000">(超级用户模式)<br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost ~]#su&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iv.&nbsp; [root@localhost ~]#cd /usr/java<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v.&nbsp;<span style="COLOR: #008000">(将您所下载的档的权限更改为可执行)<br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost java]#chmod a+x jre-1_5_0_09-linux-i586-rpm.bin&nbsp;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vi.&nbsp;<span style="COLOR: #008000">(启动安装过程) </span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost java]#./jre-1_5_0_09-linux-i586-rpm.bin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: #008000">(此时将显示二进制许可协议，按控格显示下一页，读完许可协议后，输入 『yes』继续安装。此时会将解压缩，产生jre-1_5_0_9-linux-i586.rpm)<br><img alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/JRE1.jpg" border=0><br><br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vii. <span style="COLOR: #008000">(安装jre-1_5_0_9-linux-i586.rpm)</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost java]#rpm &#8211;ivh jre-1_5_0_9-linux-i586.rpm <br><img height=235 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/JRE2.jpg" width=574 border=0><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: #008000">(此时会将JRE装在/usr/java/jre1.5.0_09目录下)<br></span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viii.&nbsp;<span style="COLOR: #008000">(设定环境变量，让Linux能找到JRE)<br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost java]#vi /etc/profile<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: #008000">(将以下内容加入在档案后面)</span></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">PATH</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">$PATH:</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">usr</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">java</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">jre1.</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">.0_09</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">bin<br></span><span style="COLOR: #008080">2</span><span style="COLOR: #000000"><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>export&nbsp;JAVA_HOME</span><span style="COLOR: #000000">=/</span><span style="COLOR: #000000">usr</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">java</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">jre1.</span><span style="COLOR: #000000">5</span><span style="COLOR: #000000">.0_09<br></span><span style="COLOR: #008080">3</span><span style="COLOR: #000000"><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>export&nbsp;CLASSPATH</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">$JAVA_HOME</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">lib:.</span></div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: #008000">(存盘后，重新启动Linux)<br><br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ix.&nbsp;<span style="COLOR: #008000">(测试Java是否安装成功)<br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost ~]#java &#8211;version<br><img height=164 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/JRE3.jpg" width=665 border=0><br><br>&nbsp;&nbsp;&nbsp;<strong> B、&nbsp;安装Eclipse SDK</strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i.&nbsp;<span style="COLOR: #008000">(将档案eclipse-SDK-3.2.1-linux-gtk.tar.gz下载到桌面)<br><br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ii.&nbsp;[root@localhost ~]#cd /usr/local<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iii.&nbsp;[root@localhost local]#cp ~Desktop/eclipse-SDK-3.2.1-linux-gtk.tar.gz .&nbsp;&nbsp;&nbsp;&nbsp;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iv.<span style="COLOR: #008000">&nbsp;(将eclipse-SDK-3.2.1-linux-gtk.tar.gz解压缩)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost local]#tar &#8211;zxvf eclipse-SDK-3.2.1-linux-gtk.tar.gz<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v.&nbsp;[root@localhost local]#cd eclipse<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vi.&nbsp;<span style="COLOR: #008000">(执行Eclipse)<br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost eclipse]#./eclipse<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vii.&nbsp;<span style="COLOR: #008000">(Select a workspace)<br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: #008000">(将Use this as the default and do not ask again打勾，以后就不会出现这个窗口)<br><img height=319 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/Eclipse1.jpg" width=704 border=0><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (第一次执行Eclipse会出现此error，因为没有任何Eclipse设定档，所以无法读取，第二次执行Eclipse就无此错误讯息，按OK继续。)<br><img height=184 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/Eclipse2.jpg" width=701 border=0><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Eclipse主画面)<br><img height=549 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/Eclipse3.jpg" width=800 border=0><br><br></span>&nbsp;&nbsp;&nbsp; <strong>C、 安装CDT</strong> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i. <span style="COLOR: #008000">(将档案org.eclipse.cdt-3.1.1-linux.x86.tar.gz下载到桌面)</span> <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ii. [root@localhost ~]#cp ~/Desktop/org.eclipse.cdt-3.1.1-linux.x86.tar.gz . <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iii. <span style="COLOR: #008000">(将org.eclipse.cdt-3.1.1-linux.x86.tar.gz解压缩)</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost ~]#tar &#8211;zxvf org.eclipse.cdt-3.1.1-linux.x86.tar.gz<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="COLOR: #008000">(档案将解到~/eclipse目录下)</span> <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iv. <span style="COLOR: #008000">(安装CDT plugin)<br></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [root@localhost ~]cp &#8211;r eclipse/plugins/. /usr/local/eclipse/plugins/ <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v. <span style="COLOR: #008000">(启动Eclipse，多了C和C++ Project支持)</span>&nbsp;<br>&nbsp;&nbsp;&nbsp; <img height=499 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/CDT1.jpg" width=700 border=0><br><br><span>C.&nbsp;<strong>如何在Eclipse上开发C/C++程序?</strong></span><br><strong>i.&nbsp;建立Hello Word project</strong><br>&nbsp; 1.&nbsp;建立C/C++ project<br><img height=156 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/HelloWorld1.jpg" width=468 border=0><br><br>&nbsp; 2.&nbsp;选择Managed Make C++ Project(若选择Managed Make C++ Project，Eclipse会自动为我们建立make file；若选择Standard Make C++ Project，则必须自己写make file。)<br><img alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/HelloWorld2.jpg" border=0><br><br>&nbsp; 3.&nbsp;输入Project name<br><img alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/HelloWorld3.jpg" border=0><br><br>&nbsp; 4.&nbsp;选择Project类型(如执行档或Library，这里选择执行档即可)<br><img height=498 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/HelloWorld4.jpg" width=700 border=0><br><br>&nbsp; 5.&nbsp;额外的设定<br><img height=499 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/HelloWorld5.jpg" width=700 border=0><br><br>&nbsp; 6.&nbsp;Open Associated Perspective?(选Yes继续)<br><img height=498 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/HelloWorld6.jpg" width=699 border=0><br><br>&nbsp; 7.&nbsp;建立C++ Source File<br><img height=308 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/HelloWorld7.jpg" width=577 border=0><br><br>8.&nbsp;输入C++ Source File檔名<br><img alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/HelloWorld8.jpg" border=0><br><br>&nbsp; 9.&nbsp;输入C++程序代码<br><img height=550 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/HelloWorld9.jpg" width=799 border=0><br><br>&nbsp; 10.&nbsp;执行程序(显示在下方的Console区)<br><img height=548 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/HelloWorld10.jpg" width=799 border=0><br><br><strong>ii.&nbsp;如何在Eclipse CDT中Debug C/C++程序?</strong><br>1.&nbsp;在Eclipse中Debug，就如同在一般IDE中Debug一样，只要在程序代码的左方按两下，就可加入breakpoint。<br><img height=547 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/Debug1.jpg" width=799 border=0><br><br>&nbsp; 2.&nbsp;启动Debug<br><img height=547 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/Debug2.jpg" width=798 border=0><br><br>&nbsp; 3.&nbsp;Debug设定，按Debug开始Debug<br><img height=550 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/Debug3.jpg" width=800 border=0><br><br>&nbsp; 4.&nbsp;单步执行，显示变量变化<br><img height=548 alt="" src="http://www.cnblogs.com/images/cnblogs_com/oomusou/Debug4.jpg" width=798 border=0><br><br><span style="FONT-SIZE: 12pt"><strong>E.&nbsp;结论<br></strong></span>Eclipse为Linux在C/C++开发提供一个完善的IDE环境，事实上，以我用过众多IDE的经验，除了Visual Studio最方便外，Eclipse的好用也直追Visual Studio，并且超越Borland C++ Builder及Dev C++，虽然安装上比较麻烦，但只要依照本文介绍一步一步的设定，就一定可完成Eclipse设定，若想要在Windows平台使用gcc compiler，也建议使用Eclipse + CDT + MinGW的组合。<br><br><strong>See Also</strong> <br><a href="http://www.cnblogs.com/oomusou/archive/2006/11/10/557066.html"><u><font color=#0000ff>[转载] Eclipse + CDT + MinGW 安装方法</font></u></a></p>
<p><strong>Reference <br></strong>1.&nbsp;为Linux手动下载和安装Java Runtime Enrironment(JRE)的说明<br>(<a href="http://www.java.com/zh_CN/download/help/5000010500.xml" target=_blank><u><font color=#0000ff>http://www.java.com/zh_CN/download/help/5000010500.xml</font></u></a>)<br>2.&nbsp;Eclipse 3.0 CDT on Linux<br>(<a href="http://www.autexier.de/jmau/dev/CDT/cdt.html" target=_blank><u><font color=#0000ff>http://www.autexier.de/jmau/dev/CDT/cdt.html</font></u></a>)</p>
<img src ="http://www.cppblog.com/niewenlong/aggbug/55158.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2008-07-02 17:19 <a href="http://www.cppblog.com/niewenlong/archive/2008/07/02/55158.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何导出mysql 数据结构</title><link>http://www.cppblog.com/niewenlong/archive/2008/07/02/55119.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Wed, 02 Jul 2008 02:36:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2008/07/02/55119.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/55119.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2008/07/02/55119.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/55119.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/55119.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: mysqldump   -d   -uroot   -p   database>databaseStr.sql   <br>  -d   ：只要结构   <br>  -p   ：输入密码   <br>  -uroot   :   用户为root   <br>  database>databaseStr.sql   把database   数据库的结构生成为文件   databaseStr.sql&nbsp;&nbsp;<a href='http://www.cppblog.com/niewenlong/archive/2008/07/02/55119.html'>阅读全文</a><img src ="http://www.cppblog.com/niewenlong/aggbug/55119.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2008-07-02 10:36 <a href="http://www.cppblog.com/niewenlong/archive/2008/07/02/55119.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>LINUX新手入门及安装配置FAQ</title><link>http://www.cppblog.com/niewenlong/archive/2008/06/15/53364.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sun, 15 Jun 2008 12:25:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2008/06/15/53364.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/53364.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2008/06/15/53364.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/53364.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/53364.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 入门篇安装篇Q：如何制作安装磁盘? 你可以使用两中方法制作安装磁盘。在M$-DOS下，可以使用专门为其开发的rawrite命令（安装光盘\dosutils下），将boot.img（安装光盘\images下）映像文件传输到软盘上；在linux下可以用命令dd，但不要把软驱设备mount入系统。具体语法如下： e:\&gt;e:\dosutils\rawrite Enter disk images s...&nbsp;&nbsp;<a href='http://www.cppblog.com/niewenlong/archive/2008/06/15/53364.html'>阅读全文</a><img src ="http://www.cppblog.com/niewenlong/aggbug/53364.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2008-06-15 20:25 <a href="http://www.cppblog.com/niewenlong/archive/2008/06/15/53364.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>添加静态路由 </title><link>http://www.cppblog.com/niewenlong/archive/2008/06/09/52610.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Sun, 08 Jun 2008 22:13:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2008/06/09/52610.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/52610.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2008/06/09/52610.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/52610.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/52610.html</trackback:ping><description><![CDATA[<p>route<br>route命令来配置并查看内核路由表的配置情况。<br>例如：<br>（1） 添加到主机的路由。<br>#route add &#8211;host 192.168.200.145 dev eth0:0<br>#route add &#8211;host 210.26.24.12 gw 210.26.24.100<br>（2） 添加到网络的路由。<br>#route add &#8211;net 192.168.200.145 netmask 255.255.255.0 eth0<br>#route add &#8211;net 192.168.200.145 netmask 255.255.255.0 gw 210.26.24.98<br>#route add &#8211;net 192.168.1.0/24 eth1<br>#route add -net 192.168.200.0/24 gw 210.26.24.100<br>（3） 添加默认网关。<br>#route add default gw 192.168.200.98<br>（4） 查看内核路由表的配置。<br>#route<br>（5）删除路由。<br>#route del &#8211;host 192.168.200.145 dev eth0:0<br>#route del &#8211;host 192.168.200.0/24 gw 192.168.200.100<br>#route del &#8211;net 210.26.25.145 netmask 255.255.255.0 eth0<br>#route del &#8211;net 210.26.24.98 netmask 255.255.255.248 gw 210.26.24.126<br>#route del &#8211;net 192.168.200.0/24 eth1<br>#route del default gw 192.168.200.100<br>#route del -net 192.168.200.0/24 gw 210.26.24.100<br>3、 traceroute<br>traceroute命令显示数据包到达目的主机所经过的路由。<br>例如：<br>#traceroute<br><a title=www.tsnc.edu.cn href="http://www.tsnc.edu.cn/"><u><font color=#0000ff>www.tsnc.edu.cn</font></u></a></p>
<img src ="http://www.cppblog.com/niewenlong/aggbug/52610.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2008-06-09 06:13 <a href="http://www.cppblog.com/niewenlong/archive/2008/06/09/52610.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>