<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux爱好者</title>
	<atom:link href="http://www.linuxers.cn/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.linuxers.cn</link>
	<description></description>
	<lastBuildDate>Wed, 02 Jun 2010 00:52:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>推荐一个debian源</title>
		<link>http://www.linuxers.cn/2010/06/02/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aadebian%e6%ba%90/</link>
		<comments>http://www.linuxers.cn/2010/06/02/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aadebian%e6%ba%90/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 00:49:41 +0000</pubDate>
		<dc:creator>leconte</dc:creator>
				<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[jdk]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://www.linuxers.cn/?p=499</guid>
		<description><![CDATA[我们使用debian的stable版很不爽的一点就是软件比较陈旧，最新版的往往都是在unstable或者testing里。http://www.backports.org/这个网站就是为了解决这个问题出现的，它将testing和unstable里的许多软件重新编译打包提供。
它的详细使用说明在这里
<span class="readmore"><a href="http://www.linuxers.cn/2010/06/02/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aadebian%e6%ba%90/" title="推荐一个debian源" target="_blank">Read more 982 words</a></span>]]></description>
			<content:encoded><![CDATA[<p>我们使用debian的stable版很不爽的一点就是软件比较陈旧，最新版的往往都是在unstable或者testing里。http://www.backports.org/这个网站就是为了解决这个问题出现的，它将testing和unstable里的许多软件重新编译打包提供。</p>
<p>它的详细使用说明在这里<br />
<a href="http://www.backports.org/dokuwiki/doku.php?id=instructions" target="_blank">http://www.backports.org/dokuwiki/doku.php?id=instructions</a></p>
<p>主要是下面几步<br />
1.将deb http://www.backports.org/debian lenny-backports main contrib non-free添加到/etc/apt/sources.list中<br />
2.执行apt-get install debian-backports-keyring安装key</p>
<p>然后通过apt-get update更新后即可使用，例如在这个源上能够找到最新版的java6 jdk</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace">leconte<span style="color: #000000; font-weight: bold;">@</span>debian:~$ <span style="color: #c20cb9; font-weight: bold;">apt-cache</span> search java6
sun-java6-bin - Sun Java<span style="color: #7a0874; font-weight: bold;">&#40;</span>TM<span style="color: #7a0874; font-weight: bold;">&#41;</span> Runtime Environment <span style="color: #7a0874; font-weight: bold;">&#40;</span>JRE<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">6</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>architecture dependent files<span style="color: #7a0874; font-weight: bold;">&#41;</span>
sun-java6-demo - Sun Java<span style="color: #7a0874; font-weight: bold;">&#40;</span>TM<span style="color: #7a0874; font-weight: bold;">&#41;</span> Development Kit <span style="color: #7a0874; font-weight: bold;">&#40;</span>JDK<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">6</span> demos and examples
sun-java6-doc - Sun JDK<span style="color: #7a0874; font-weight: bold;">&#40;</span>TM<span style="color: #7a0874; font-weight: bold;">&#41;</span> Documention <span style="color: #660033;">--</span> integration installer
sun-java6-fonts - Lucida TrueType fonts <span style="color: #7a0874; font-weight: bold;">&#40;</span>from the Sun JRE<span style="color: #7a0874; font-weight: bold;">&#41;</span>
sun-java6-javadb - Java<span style="color: #7a0874; font-weight: bold;">&#40;</span>TM<span style="color: #7a0874; font-weight: bold;">&#41;</span> DB, Sun Microsystems<span style="color: #ff0000;">' distribution of Apache Derby
sun-java6-jdk - Sun Java(TM) Development Kit (JDK) 6
sun-java6-jre - Sun Java(TM) Runtime Environment (JRE) 6 (architecture independent files)
sun-java6-plugin - The Java(TM) Plug-in, Java SE 6
sun-java6-source - Sun Java(TM) Development Kit (JDK) 6 source files</span></pre></div></div>

<p style='text-align:left'>&copy; 2010, <a target='_blank' href='http://www.linuxers.cn'>Linux爱好者</a>. 版权所有. 转载请注明来自http://www.linuxers.cn</p>
<h4  class="related_post_title">推荐日志</h4><ul class="related_post"></ul>]]></content:encoded>
			<wfw:commentRss>http://www.linuxers.cn/2010/06/02/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aadebian%e6%ba%90/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在debian下设置ip的方法</title>
		<link>http://www.linuxers.cn/2010/06/02/%e5%9c%a8debian%e4%b8%8b%e8%ae%be%e7%bd%aeip%e7%9a%84%e6%96%b9%e6%b3%95/</link>
		<comments>http://www.linuxers.cn/2010/06/02/%e5%9c%a8debian%e4%b8%8b%e8%ae%be%e7%bd%aeip%e7%9a%84%e6%96%b9%e6%b3%95/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 00:31:24 +0000</pubDate>
		<dc:creator>leconte</dc:creator>
				<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[ip]]></category>

		<guid isPermaLink="false">http://www.linuxers.cn/?p=497</guid>
		<description><![CDATA[debian和redhat设置ip的地方有所不同，关于redhat的ip设置请看这里，今天介绍一下debian的配置。
debian的ip配置文件位于/etc/network/interfaces文件中，我的文件内容如下：

&#160;
<span class="readmore"><a href="http://www.linuxers.cn/2010/06/02/%e5%9c%a8debian%e4%b8%8b%e8%ae%be%e7%bd%aeip%e7%9a%84%e6%96%b9%e6%b3%95/" title="在debian下设置ip的方法" target="_blank">Read more 1506 words</a></span>]]></description>
			<content:encoded><![CDATA[<p>debian和redhat设置ip的地方有所不同，关于redhat的ip设置请看<a href="http://www.linuxers.cn/2010/03/28/redhat%E4%B8%8B%E7%9A%84%E7%BD%91%E5%8D%A1%E9%85%8D%E7%BD%AE/">这里</a>，今天介绍一下debian的配置。</p>
<p>debian的ip配置文件位于/etc/network/interfaces文件中，我的文件内容如下：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace">&nbsp;
<span style="color: #666666; font-style: italic;"># This file describes the network interfaces available on your system</span>
<span style="color: #666666; font-style: italic;"># and how to activate them. For more information, see interfaces(5).</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The loopback network interface</span>
auto lo
iface lo inet loopback
&nbsp;
<span style="color: #666666; font-style: italic;"># The primary network interface</span>
auto eth0
<span style="color: #666666; font-style: italic;">#iface eth0 inet dhcp</span>
iface eth0 inet static
address 10.32.20.33
netmask 255.255.255.0
up route add default gw 10.32.20.62</pre></div></div>

<p>iface eth0 inet static代表eth0这块网卡采用静态ip的方式，address和netmask分别指明了ip地址和子网掩码。</p>
<p>如果想采用dhcp方式配置ip，则无需指定address和netmask，而只需设置iface eth0 inet dhcp即可。</p>
<p>up route add default gw 10.32.20.62代表在网卡启动(up)之后自动执行route add default gw 10.32.20.62这条命令，即添加一个默认网关</p>
<p>auto lo和iface lo inet loopback是设置本次回环接口，即127.0.0.1。</p>
<p>经过设置后执行/etc/init.d/networking restart即可令修改生效，执行ifconfig可以看到当前的ip配置：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace">leconte<span style="color: #000000; font-weight: bold;">@</span>debian:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ifconfig</span>
eth0      Link encap:Ethernet  HWaddr 00:1a:4b:3e:07:0c
          inet addr:10.32.20.33  Bcast:10.32.20.255  Mask:255.255.255.0
          inet6 addr: fe80::21a:4bff:fe3e:70c<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">64</span> Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:<span style="color: #000000;">1500</span>  Metric:<span style="color: #000000;">1</span>
          RX packets:<span style="color: #000000;">504593</span> errors:<span style="color: #000000;">0</span> dropped:<span style="color: #000000;">0</span> overruns:<span style="color: #000000;">0</span> frame:<span style="color: #000000;">0</span>
          TX packets:<span style="color: #000000;">151595</span> errors:<span style="color: #000000;">0</span> dropped:<span style="color: #000000;">0</span> overruns:<span style="color: #000000;">0</span> carrier:<span style="color: #000000;">0</span>
          collisions:<span style="color: #000000;">0</span> txqueuelen:<span style="color: #000000;">1000</span>
          RX bytes:<span style="color: #000000;">305990674</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">291.8</span> MiB<span style="color: #7a0874; font-weight: bold;">&#41;</span>  TX bytes:<span style="color: #000000;">51901895</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">49.4</span> MiB<span style="color: #7a0874; font-weight: bold;">&#41;</span>
          Interrupt:<span style="color: #000000;">16</span> Base address:0x4000
&nbsp;
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">128</span> Scope:Host
          UP LOOPBACK RUNNING  MTU:<span style="color: #000000;">16436</span>  Metric:<span style="color: #000000;">1</span>
          RX packets:<span style="color: #000000;">173</span> errors:<span style="color: #000000;">0</span> dropped:<span style="color: #000000;">0</span> overruns:<span style="color: #000000;">0</span> frame:<span style="color: #000000;">0</span>
          TX packets:<span style="color: #000000;">173</span> errors:<span style="color: #000000;">0</span> dropped:<span style="color: #000000;">0</span> overruns:<span style="color: #000000;">0</span> carrier:<span style="color: #000000;">0</span>
          collisions:<span style="color: #000000;">0</span> txqueuelen:<span style="color: #000000;">0</span>
          RX bytes:<span style="color: #000000;">123368</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">120.4</span> KiB<span style="color: #7a0874; font-weight: bold;">&#41;</span>  TX bytes:<span style="color: #000000;">123368</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">120.4</span> KiB<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>可以看到，interfaces文件中的lo和eth0两块设备都正常工作了。</p>
<p style='text-align:left'>&copy; 2010, <a target='_blank' href='http://www.linuxers.cn'>Linux爱好者</a>. 版权所有. 转载请注明来自http://www.linuxers.cn</p>
<h4  class="related_post_title">推荐日志</h4><ul class="related_post"></ul>]]></content:encoded>
			<wfw:commentRss>http://www.linuxers.cn/2010/06/02/%e5%9c%a8debian%e4%b8%8b%e8%ae%be%e7%bd%aeip%e7%9a%84%e6%96%b9%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用last查看系统最近登录用户记录</title>
		<link>http://www.linuxers.cn/2010/05/19/%e4%bd%bf%e7%94%a8last%e6%9f%a5%e7%9c%8b%e7%b3%bb%e7%bb%9f%e6%9c%80%e8%bf%91%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7%e8%ae%b0%e5%bd%95/</link>
		<comments>http://www.linuxers.cn/2010/05/19/%e4%bd%bf%e7%94%a8last%e6%9f%a5%e7%9c%8b%e7%b3%bb%e7%bb%9f%e6%9c%80%e8%bf%91%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7%e8%ae%b0%e5%bd%95/#comments</comments>
		<pubDate>Wed, 19 May 2010 11:53:07 +0000</pubDate>
		<dc:creator>leconte</dc:creator>
				<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[last]]></category>
		<category><![CDATA[strace]]></category>

		<guid isPermaLink="false">http://www.linuxers.cn/?p=495</guid>
		<description><![CDATA[linux下的last命令可以用来查看最近登录过的用户记录，包括详细的时间和时长，例如:

&#91;leconte@web ~&#93;$ last
leconte  pts/0        114.251.86.0     Wed May 19 19:42   still logged in
<span class="readmore"><a href="http://www.linuxers.cn/2010/05/19/%e4%bd%bf%e7%94%a8last%e6%9f%a5%e7%9c%8b%e7%b3%bb%e7%bb%9f%e6%9c%80%e8%bf%91%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7%e8%ae%b0%e5%bd%95/" title="使用last查看系统最近登录用户记录" target="_blank">Read more 1174 words</a></span>]]></description>
			<content:encoded><![CDATA[<p>linux下的last命令可以用来查看最近登录过的用户记录，包括详细的时间和时长，例如:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">last</span>
leconte  pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        114.251.86.0     Wed May <span style="color: #000000;">19</span> <span style="color: #000000;">19</span>:<span style="color: #000000;">42</span>   still logged <span style="color: #000000; font-weight: bold;">in</span>
leconte  pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        114.251.86.0     Wed May <span style="color: #000000;">19</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">22</span> - <span style="color: #000000;">17</span>:<span style="color: #000000;">22</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>00:00<span style="color: #7a0874; font-weight: bold;">&#41;</span>
leconte  pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        114.252.182.234  Tue May <span style="color: #000000;">18</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">47</span> - <span style="color: #000000;">22</span>:<span style="color: #000000;">15</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>00:<span style="color: #000000;">28</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
leconte  pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        114.251.86.0     Fri May  <span style="color: #000000;">7</span> <span style="color: #000000;">18</span>:<span style="color: #000000;">26</span> - <span style="color: #000000;">18</span>:<span style="color: #000000;">56</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>00:<span style="color: #000000;">30</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
leconte  pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        114.251.86.0     Fri Apr <span style="color: #000000;">23</span> <span style="color: #000000;">11</span>:<span style="color: #000000;">49</span> - <span style="color: #000000;">11</span>:<span style="color: #000000;">51</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>00:02<span style="color: #7a0874; font-weight: bold;">&#41;</span>
leconte  pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        114.251.86.0     Mon Apr <span style="color: #000000;">19</span> <span style="color: #000000;">17</span>:03 - <span style="color: #000000;">17</span>:<span style="color: #000000;">30</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>00:<span style="color: #000000;">27</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
leconte  pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        114.251.86.0     Mon Apr <span style="color: #000000;">19</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">56</span> - <span style="color: #000000;">11</span>:03  <span style="color: #7a0874; font-weight: bold;">&#40;</span>00:06<span style="color: #7a0874; font-weight: bold;">&#41;</span>
leconte  pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        121.0.29.237     Tue Apr <span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">25</span> - <span style="color: #000000;">16</span>:<span style="color: #000000;">13</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>00:<span style="color: #000000;">47</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
leconte  pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>        121.0.29.237     Tue Apr <span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">16</span> - <span style="color: #000000;">15</span>:<span style="color: #000000;">24</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>00:08<span style="color: #7a0874; font-weight: bold;">&#41;</span>
...</pre></div></div>

<p>通过这个清单起码可以部分排除服务器被别人非法登录的情况，当然，手法严谨的高手是不会留下蛛丝马迹的。他们往往清空这个记录让你无迹可查。</p>
<p>通过strace跟踪会发现last实际读取的是/var/log/wtmp这个文件</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace">open<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;/var/log/wtmp&quot;</span>, O_RDONLY<span style="color: #7a0874; font-weight: bold;">&#41;</span>         = <span style="color: #000000;">3</span>
fstat64<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">st_mode</span>=S_IFREG<span style="color: #000000; font-weight: bold;">|</span>0664, <span style="color: #007800;">st_size</span>=<span style="color: #000000;">264576</span>, ...<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = <span style="color: #000000;">0</span>
mmap2<span style="color: #7a0874; font-weight: bold;">&#40;</span>NULL, <span style="color: #000000;">4096</span>, PROT_READ<span style="color: #000000; font-weight: bold;">|</span>PROT_WRITE, MAP_PRIVATE<span style="color: #000000; font-weight: bold;">|</span>MAP_ANONYMOUS, -<span style="color: #000000;">1</span>, <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = 0xb7fea000
<span style="color: #c20cb9; font-weight: bold;">read</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span>, <span style="color: #ff0000;">&quot;\10\0\0\0\255\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0&quot;</span>..., <span style="color: #000000;">4096</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = <span style="color: #000000;">4096</span>
fstat64<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">st_mode</span>=S_IFREG<span style="color: #000000; font-weight: bold;">|</span>0664, <span style="color: #007800;">st_size</span>=<span style="color: #000000;">264576</span>, ...<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = <span style="color: #000000;">0</span></pre></div></div>

<p>如果我手工删除这个文件，再执行last则会是这样的结果：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web log<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> wtmp wtmp.bk
Password:
<span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web log<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">last</span>
<span style="color: #c20cb9; font-weight: bold;">last</span>: <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>wtmp: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory
Perhaps this <span style="color: #c20cb9; font-weight: bold;">file</span> was removed by the operator to prevent logging <span style="color: #c20cb9; font-weight: bold;">last</span> info.</pre></div></div>

<p>所以last的输出不可全信，毕竟服务器被入侵的话别人如果想删除wtmp文件是轻而易举的事情。</p>
<p style='text-align:left'>&copy; 2010, <a target='_blank' href='http://www.linuxers.cn'>Linux爱好者</a>. 版权所有. 转载请注明来自http://www.linuxers.cn</p>
<h4  class="related_post_title">推荐日志</h4><ul class="related_post"></ul>]]></content:encoded>
			<wfw:commentRss>http://www.linuxers.cn/2010/05/19/%e4%bd%bf%e7%94%a8last%e6%9f%a5%e7%9c%8b%e7%b3%bb%e7%bb%9f%e6%9c%80%e8%bf%91%e7%99%bb%e5%bd%95%e7%94%a8%e6%88%b7%e8%ae%b0%e5%bd%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用uptime查看系统启动时间</title>
		<link>http://www.linuxers.cn/2010/05/07/%e4%bd%bf%e7%94%a8uptime%e6%9f%a5%e7%9c%8b%e7%b3%bb%e7%bb%9f%e5%90%af%e5%8a%a8%e6%97%b6%e9%97%b4/</link>
		<comments>http://www.linuxers.cn/2010/05/07/%e4%bd%bf%e7%94%a8uptime%e6%9f%a5%e7%9c%8b%e7%b3%bb%e7%bb%9f%e5%90%af%e5%8a%a8%e6%97%b6%e9%97%b4/#comments</comments>
		<pubDate>Fri, 07 May 2010 10:31:40 +0000</pubDate>
		<dc:creator>leconte</dc:creator>
				<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[uptime]]></category>

		<guid isPermaLink="false">http://www.linuxers.cn/?p=493</guid>
		<description><![CDATA[哈哈，我的几个小站服务器硬件虽然很烂，但是到现在为止也坚持了近3个月了。
show一下以作纪念~
[leconte@web ~]$ uptime
 18:26:39 up 98 days,  9:16,  1 user,  load average: 0.10, 0.05, 0.01
<span class="readmore"><a href="http://www.linuxers.cn/2010/05/07/%e4%bd%bf%e7%94%a8uptime%e6%9f%a5%e7%9c%8b%e7%b3%bb%e7%bb%9f%e5%90%af%e5%8a%a8%e6%97%b6%e9%97%b4/" title="使用uptime查看系统启动时间" target="_blank">Read more 187 words</a></span>]]></description>
			<content:encoded><![CDATA[<p>哈哈，我的几个小站服务器硬件虽然很烂，但是到现在为止也坚持了近3个月了。</p>
<p>show一下以作纪念~</p>
<p>[leconte@web ~]$ uptime<br />
 18:26:39 up 98 days,  9:16,  1 user,  load average: 0.10, 0.05, 0.01</p>
<p>uptime能显示当前时间、电脑启动天数、登录用户数，以及系统负载情况。</p>
<p>服务器负载很低，毕竟目前还没有跑什么大型的应用，慢慢来吧。</p>
<p style='text-align:left'>&copy; 2010, <a target='_blank' href='http://www.linuxers.cn'>Linux爱好者</a>. 版权所有. 转载请注明来自http://www.linuxers.cn</p>
<h4  class="related_post_title">推荐日志</h4><ul class="related_post"></ul>]]></content:encoded>
			<wfw:commentRss>http://www.linuxers.cn/2010/05/07/%e4%bd%bf%e7%94%a8uptime%e6%9f%a5%e7%9c%8b%e7%b3%bb%e7%bb%9f%e5%90%af%e5%8a%a8%e6%97%b6%e9%97%b4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用date查看和设置系统时间</title>
		<link>http://www.linuxers.cn/2010/04/29/%e4%bd%bf%e7%94%a8date%e6%9f%a5%e7%9c%8b%e5%92%8c%e8%ae%be%e7%bd%ae%e7%b3%bb%e7%bb%9f%e6%97%b6%e9%97%b4/</link>
		<comments>http://www.linuxers.cn/2010/04/29/%e4%bd%bf%e7%94%a8date%e6%9f%a5%e7%9c%8b%e5%92%8c%e8%ae%be%e7%bd%ae%e7%b3%bb%e7%bb%9f%e6%97%b6%e9%97%b4/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 12:42:18 +0000</pubDate>
		<dc:creator>leconte</dc:creator>
				<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.linuxers.cn/?p=491</guid>
		<description><![CDATA[在linux下可以用date命令方便的查看和修改系统时间。
不带任何参数执行date将输出系统的当前时间：

&#91;leconte@localhost ~&#93;$ date
<span class="readmore"><a href="http://www.linuxers.cn/2010/04/29/%e4%bd%bf%e7%94%a8date%e6%9f%a5%e7%9c%8b%e5%92%8c%e8%ae%be%e7%bd%ae%e7%b3%bb%e7%bb%9f%e6%97%b6%e9%97%b4/" title="使用date查看和设置系统时间" target="_blank">Read more 1132 words</a></span>]]></description>
			<content:encoded><![CDATA[<p>在linux下可以用date命令方便的查看和修改系统时间。</p>
<p>不带任何参数执行date将输出系统的当前时间：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>localhost ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">date</span>
<span style="color: #000000;">2010</span>年 03月 <span style="color: #000000;">30</span>日 星期二 <span style="color: #000000;">10</span>:00:<span style="color: #000000;">37</span> CST</pre></div></div>

<p>这里显示中文是因为我的LC_ALL是zh_CN.UTF-8，date这个命令是支持这些标准locale环境变量的。如果将LC_ALL设置为C的话，将会输出英文:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>localhost ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LC_ALL</span>=C
<span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>localhost ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">date</span>
Tue Mar <span style="color: #000000;">30</span> <span style="color: #000000;">10</span>:01:<span style="color: #000000;">12</span> CST <span style="color: #000000;">2010</span></pre></div></div>

<p>通过date -s 可以对系统时间进行设置，例如：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>localhost ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #660033;">-s</span> <span style="color: #ff0000;">'2010-04-29 22:00:00'</span>
Thu Apr <span style="color: #000000;">29</span> <span style="color: #000000;">22</span>:00:00 CST <span style="color: #000000;">2010</span></pre></div></div>

<p>设置的时间格式其实很灵活，例如通过&#8217;20100429 22:00:00&#8242;也可以达到同样的效果。</p>
<p>此外也可以仅设置时间，例如：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>localhost ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #660033;">-s</span> <span style="color: #ff0000;">'11:00:00'</span>
Password:
Thu Apr <span style="color: #000000;">29</span> <span style="color: #000000;">11</span>:00:00 CST <span style="color: #000000;">2010</span></pre></div></div>

<p>需要注意设置系统时间是需要root权限的，因此需要sudo后执行。如果用strace跟踪就会发现，其实date存取时间访问的是/etc/localtime这个文件，例如用date读取时间的时候，跟踪结果的片段如下：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace">open<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;/etc/localtime&quot;</span>, O_RDONLY<span style="color: #7a0874; font-weight: bold;">&#41;</span>        = <span style="color: #000000;">3</span>
fstat64<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">st_mode</span>=S_IFREG<span style="color: #000000; font-weight: bold;">|</span>0644, <span style="color: #007800;">st_size</span>=<span style="color: #000000;">405</span>, ...<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = <span style="color: #000000;">0</span>
fstat64<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span>, <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">st_mode</span>=S_IFREG<span style="color: #000000; font-weight: bold;">|</span>0644, <span style="color: #007800;">st_size</span>=<span style="color: #000000;">405</span>, ...<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = <span style="color: #000000;">0</span>
mmap2<span style="color: #7a0874; font-weight: bold;">&#40;</span>NULL, <span style="color: #000000;">4096</span>, PROT_READ<span style="color: #000000; font-weight: bold;">|</span>PROT_WRITE, MAP_PRIVATE<span style="color: #000000; font-weight: bold;">|</span>MAP_ANONYMOUS, -<span style="color: #000000;">1</span>, <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = 0xb7ffc000
<span style="color: #c20cb9; font-weight: bold;">read</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span>, <span style="color: #ff0000;">&quot;TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0\0\0\3\0\0\0\0&quot;</span>..., <span style="color: #000000;">4096</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = <span style="color: #000000;">405</span>
close<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>                                = <span style="color: #000000;">0</span></pre></div></div>

<p>用file和ls查看这个文件可以看到，它仅是root可写的</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>localhost ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>localtime
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>localtime: timezone data
<span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>localhost ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-al</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>localtime
<span style="color: #660033;">-rw-r--r--</span> <span style="color: #000000;">1</span> root root <span style="color: #000000;">405</span> Oct <span style="color: #000000;">22</span>  <span style="color: #000000;">2009</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>localtime</pre></div></div>

<p>用file也能看到它是timezone类型的数据，file命令对数据格式收集的还是挺全的。</p>
<p style='text-align:left'>&copy; 2010, <a target='_blank' href='http://www.linuxers.cn'>Linux爱好者</a>. 版权所有. 转载请注明来自http://www.linuxers.cn</p>
<h4  class="related_post_title">推荐日志</h4><ul class="related_post"></ul>]]></content:encoded>
			<wfw:commentRss>http://www.linuxers.cn/2010/04/29/%e4%bd%bf%e7%94%a8date%e6%9f%a5%e7%9c%8b%e5%92%8c%e8%ae%be%e7%bd%ae%e7%b3%bb%e7%bb%9f%e6%97%b6%e9%97%b4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>推荐一个源代码浏览网站</title>
		<link>http://www.linuxers.cn/2010/04/23/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e6%ba%90%e4%bb%a3%e7%a0%81%e6%b5%8f%e8%a7%88%e7%bd%91%e7%ab%99/</link>
		<comments>http://www.linuxers.cn/2010/04/23/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e6%ba%90%e4%bb%a3%e7%a0%81%e6%b5%8f%e8%a7%88%e7%bd%91%e7%ab%99/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 04:18:55 +0000</pubDate>
		<dc:creator>leconte</dc:creator>
				<category><![CDATA[Linux开发]]></category>
		<category><![CDATA[sooset]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://www.linuxers.cn/?p=488</guid>
		<description><![CDATA[今天在逛水木linux dev版的时候发现了一个不错的网站，www.sooset.com，它可以提供在线的源代码浏览。目前提供的工程很多了，比如kernel，lucene,apache等。
它目前支持在右侧以文件夹形式浏览，对于C和Cpp等常见格式的文件都可以做到语法高亮；左侧有一个符号列表，能列出在当前文章中出现的符号；当你在源代码中点击那些符号的时候，在下边会列出该项目中所有出现该符号的文件，点击它可以在各个文件中进行切换。整体如图所示：
<span class="readmore"><a href="http://www.linuxers.cn/2010/04/23/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e6%ba%90%e4%bb%a3%e7%a0%81%e6%b5%8f%e8%a7%88%e7%bd%91%e7%ab%99/" title="推荐一个源代码浏览网站" target="_blank">Read more 276 words</a></span>]]></description>
			<content:encoded><![CDATA[<p>今天在逛水木linux dev版的时候发现了一个不错的网站，<a href="http://www.sooset.com" target="_blank">www.sooset.com</a>，它可以提供在线的源代码浏览。目前提供的工程很多了，比如kernel，lucene,apache等。</p>
<p>它目前支持在右侧以文件夹形式浏览，对于C和Cpp等常见格式的文件都可以做到语法高亮；左侧有一个符号列表，能列出在当前文章中出现的符号；当你在源代码中点击那些符号的时候，在下边会列出该项目中所有出现该符号的文件，点击它可以在各个文件中进行切换。整体如图所示：<br />
<a href="http://www.linuxers.cn/wp-content/uploads/2010/04/12.png"><img class="alignnone size-medium wp-image-489" title="1" src="http://www.linuxers.cn/wp-content/uploads/2010/04/12-672x312.png" alt="1" width="672" height="312" /></a></p>
<p>整体看来就像是一个整合了ctags,filemanager功能的vim，值得称赞的是它的速度相当快，强烈推荐！</p>
<p style='text-align:left'>&copy; 2010, <a target='_blank' href='http://www.linuxers.cn'>Linux爱好者</a>. 版权所有. 转载请注明来自http://www.linuxers.cn</p>
<h4  class="related_post_title">推荐日志</h4><ul class="related_post"></ul>]]></content:encoded>
			<wfw:commentRss>http://www.linuxers.cn/2010/04/23/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e6%ba%90%e4%bb%a3%e7%a0%81%e6%b5%8f%e8%a7%88%e7%bd%91%e7%ab%99/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux下最简单的秒表</title>
		<link>http://www.linuxers.cn/2010/04/20/linux%e4%b8%8b%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e7%a7%92%e8%a1%a8/</link>
		<comments>http://www.linuxers.cn/2010/04/20/linux%e4%b8%8b%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e7%a7%92%e8%a1%a8/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 09:32:12 +0000</pubDate>
		<dc:creator>leconte</dc:creator>
				<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.linuxers.cn/?p=486</guid>
		<description><![CDATA[今天介绍个小玩意，在linux下用最简单的方式实现秒表。
time这个命令我在之前的文章中介绍过了，它可以用来统计一个程序的执行时间，并且能详细到用户态执行时间和内核态执行时间。read指令是bash内建的命令，它用来从标准输入读取一行数据。将这两个命令相结合即可实现秒表功能。
执行time read之后将处于等待输入状态，这时候你可以去做想做的事情，比如统计脉搏，再比如你出去跑一圈。做完这些之后在终端上按回车或者Ctrl+D结束输入，此时屏幕就会显示出你耗费的时间。
<span class="readmore"><a href="http://www.linuxers.cn/2010/04/20/linux%e4%b8%8b%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e7%a7%92%e8%a1%a8/" title="linux下最简单的秒表" target="_blank">Read more 364 words</a></span>]]></description>
			<content:encoded><![CDATA[<p>今天介绍个小玩意，在linux下用最简单的方式实现秒表。</p>
<p>time这个命令我在之前的文章中介绍过了，它可以用来统计一个程序的执行时间，并且能详细到用户态执行时间和内核态执行时间。read指令是bash内建的命令，它用来从标准输入读取一行数据。将这两个命令相结合即可实现秒表功能。</p>
<p>执行time read之后将处于等待输入状态，这时候你可以去做想做的事情，比如统计脉搏，再比如你出去跑一圈。做完这些之后在终端上按回车或者Ctrl+D结束输入，此时屏幕就会显示出你耗费的时间。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>vmout103 tmp<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #000000; font-weight: bold;">time</span> <span style="color: #c20cb9; font-weight: bold;">read</span>
&nbsp;
&nbsp;
real    0m6.248s
user    0m0.000s
sys     0m0.000s</pre></div></div>

<p>real的值即耗费的总时间，为6.248s，user和sys的值为0，因为这段时间里该程序一直在等待输入状态，并没有占据CPU时间。</p>
<p style='text-align:left'>&copy; 2010, <a target='_blank' href='http://www.linuxers.cn'>Linux爱好者</a>. 版权所有. 转载请注明来自http://www.linuxers.cn</p>
<h4  class="related_post_title">推荐日志</h4><ul class="related_post"></ul>]]></content:encoded>
			<wfw:commentRss>http://www.linuxers.cn/2010/04/20/linux%e4%b8%8b%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e7%a7%92%e8%a1%a8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>软链接和硬链接</title>
		<link>http://www.linuxers.cn/2010/04/19/%e8%bd%af%e9%93%be%e6%8e%a5%e5%92%8c%e7%a1%ac%e9%93%be%e6%8e%a5/</link>
		<comments>http://www.linuxers.cn/2010/04/19/%e8%bd%af%e9%93%be%e6%8e%a5%e5%92%8c%e7%a1%ac%e9%93%be%e6%8e%a5/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 09:19:55 +0000</pubDate>
		<dc:creator>leconte</dc:creator>
				<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[link]]></category>

		<guid isPermaLink="false">http://www.linuxers.cn/?p=482</guid>
		<description><![CDATA[在linux下存在两种文件链接方式，软连接和硬链接，软链接又叫符号链接，它实际上一种类似于windows快捷方式的概念。硬链接实际是文件系统上实现的一种文件指针，它可以令两个文件指向同样一个inode，本质来说他们是一个文件。
二者都可以通过ln命令来创建。基本的创建语法如下：
ln [源] [目标] 
<span class="readmore"><a href="http://www.linuxers.cn/2010/04/19/%e8%bd%af%e9%93%be%e6%8e%a5%e5%92%8c%e7%a1%ac%e9%93%be%e6%8e%a5/" title="软链接和硬链接" target="_blank">Read more 1070 words</a></span>]]></description>
			<content:encoded><![CDATA[<p>在linux下存在两种文件链接方式，软连接和硬链接，软链接又叫符号链接，它实际上一种类似于windows快捷方式的概念。硬链接实际是文件系统上实现的一种文件指针，它可以令两个文件指向同样一个inode，本质来说他们是一个文件。</p>
<p>二者都可以通过ln命令来创建。基本的创建语法如下：</p>
<blockquote><p>ln [源] [目标] </p></blockquote>
<p>默认情况下将会建立硬链接，例如</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web tmkp<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">ln</span> data ha
<span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web tmkp<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-al</span>
<span style="color: #660033;">-rw-rw-r--</span>  <span style="color: #000000;">2</span> leconte leconte  <span style="color: #000000;">402</span> Apr <span style="color: #000000;">19</span> <span style="color: #000000;">11</span>:00 data
<span style="color: #660033;">-rw-rw-r--</span>  <span style="color: #000000;">2</span> leconte leconte  <span style="color: #000000;">402</span> Apr <span style="color: #000000;">19</span> <span style="color: #000000;">11</span>:00 ha</pre></div></div>

<p>我们为data创建了一个硬链接ha，然后用ls -al去看，它们的大小完全一样，细心的话你会发现在leconte leconte前有一个数字2，这代表的是指向该文件inode的链接数为2，实际就是data和ha这两个文件。</p>
<p>使用ls -il可以更直观的看到inode号</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web tmkp<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-il</span>
<span style="color: #000000;">493327</span> <span style="color: #660033;">-rw-rw-r--</span> <span style="color: #000000;">2</span> leconte leconte <span style="color: #000000;">402</span> Apr <span style="color: #000000;">19</span> <span style="color: #000000;">17</span>:06 data
<span style="color: #000000;">493327</span> <span style="color: #660033;">-rw-rw-r--</span> <span style="color: #000000;">2</span> leconte leconte <span style="color: #000000;">402</span> Apr <span style="color: #000000;">19</span> <span style="color: #000000;">17</span>:06 ha</pre></div></div>

<p>可以看到，data和ha这两个文件的inode号都是493327。</p>
<p>为ln指定-s参数就可以用来创建软链接（符号链接），这也是我们平常更常用的链接方式</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web tmkp<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-fs</span> data a
<span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web tmkp<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-il</span>
total <span style="color: #000000;">12</span>
<span style="color: #000000;">493329</span> lrwxrwxrwx <span style="color: #000000;">1</span> leconte leconte   <span style="color: #000000;">4</span> Apr <span style="color: #000000;">19</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">15</span> a -<span style="color: #000000; font-weight: bold;">&gt;</span> data
<span style="color: #000000;">493328</span> <span style="color: #660033;">-rw-rw-r--</span> <span style="color: #000000;">1</span> leconte leconte  <span style="color: #000000;">39</span> Nov <span style="color: #000000;">25</span> <span style="color: #000000;">18</span>:<span style="color: #000000;">27</span> ab
<span style="color: #000000;">493327</span> <span style="color: #660033;">-rw-rw-r--</span> <span style="color: #000000;">2</span> leconte leconte <span style="color: #000000;">410</span> Apr <span style="color: #000000;">19</span> <span style="color: #000000;">17</span>:06 data
<span style="color: #000000;">493327</span> <span style="color: #660033;">-rw-rw-r--</span> <span style="color: #000000;">2</span> leconte leconte <span style="color: #000000;">410</span> Apr <span style="color: #000000;">19</span> <span style="color: #000000;">17</span>:06 ha</pre></div></div>

<p>我们为data又创建了一个符号链接a，通过ls -il看的时候会发现几点<br />
1.a的inode号和data不同，它本质上是另外一个文件<br />
2.ls的结果a->data直接反映a是指向data的符号链接。<br />
3.为data增加一个符号链接并不会增加data的链接数，它仍然是2<br />
4.a的大小为4字节，实际上它只会保存指向信息，并不会保存实际指向文件的内容。</p>
<p>此外，由于硬链接是基于文件系统实现的，因此是无法跨文件系统创建的，而符号链接可以。</p>
<p style='text-align:left'>&copy; 2010, <a target='_blank' href='http://www.linuxers.cn'>Linux爱好者</a>. 版权所有. 转载请注明来自http://www.linuxers.cn</p>
<h4  class="related_post_title">推荐日志</h4><ul class="related_post"></ul>]]></content:encoded>
			<wfw:commentRss>http://www.linuxers.cn/2010/04/19/%e8%bd%af%e9%93%be%e6%8e%a5%e5%92%8c%e7%a1%ac%e9%93%be%e6%8e%a5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux下历史命令(history)添加时间戳</title>
		<link>http://www.linuxers.cn/2010/04/13/linux%e4%b8%8b%e5%8e%86%e5%8f%b2%e5%91%bd%e4%bb%a4history%e6%b7%bb%e5%8a%a0%e6%97%b6%e9%97%b4%e6%88%b3/</link>
		<comments>http://www.linuxers.cn/2010/04/13/linux%e4%b8%8b%e5%8e%86%e5%8f%b2%e5%91%bd%e4%bb%a4history%e6%b7%bb%e5%8a%a0%e6%97%b6%e9%97%b4%e6%88%b3/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 07:44:07 +0000</pubDate>
		<dc:creator>leconte</dc:creator>
				<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://www.linuxers.cn/?p=480</guid>
		<description><![CDATA[熟悉bash的都一定知道使用history可以输出你曾经输入过的历史命令，例如

&#91;leconte@web ~&#93;$ history  &#124; more
   25  cd docroot/
<span class="readmore"><a href="http://www.linuxers.cn/2010/04/13/linux%e4%b8%8b%e5%8e%86%e5%8f%b2%e5%91%bd%e4%bb%a4history%e6%b7%bb%e5%8a%a0%e6%97%b6%e9%97%b4%e6%88%b3/" title="Linux下历史命令(history)添加时间戳" target="_blank">Read more 807 words</a></span>]]></description>
			<content:encoded><![CDATA[<p>熟悉bash的都一定知道使用history可以输出你曾经输入过的历史命令，例如</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #7a0874; font-weight: bold;">history</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">more</span>
   <span style="color: #000000;">25</span>  <span style="color: #7a0874; font-weight: bold;">cd</span> docroot<span style="color: #000000; font-weight: bold;">/</span>
   <span style="color: #000000;">26</span>  <span style="color: #c20cb9; font-weight: bold;">ls</span>
   <span style="color: #000000;">27</span>  <span style="color: #7a0874; font-weight: bold;">cd</span> blog<span style="color: #000000; font-weight: bold;">/</span>
   <span style="color: #000000;">28</span>  <span style="color: #c20cb9; font-weight: bold;">ls</span>
   <span style="color: #000000;">29</span>  <span style="color: #7a0874; font-weight: bold;">cd</span> wp-content<span style="color: #000000; font-weight: bold;">/</span>themes<span style="color: #000000; font-weight: bold;">/</span>
   <span style="color: #000000;">30</span>  <span style="color: #c20cb9; font-weight: bold;">ls</span></pre></div></div>

<p>但是这里只显示了命令，并没有显示执行命令的时间，因为保存历史命令的~/.bash_history里并没有保存时间。</p>
<p>通过设置环境变量<strong><span style="color: #ff0000;">HISTTIMEFORMAT=&#8221;%F %T &#8220;</span></strong>即可为history加上时间戳，例如：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTTIMEFORMAT</span>=<span style="color: #ff0000;">&quot;%F %T &quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>web ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span>
  <span style="color: #000000;">997</span>  <span style="color: #000000;">2010</span>-04-<span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">25</span>:08 <span style="color: #7a0874; font-weight: bold;">history</span>
  <span style="color: #000000;">998</span>  <span style="color: #000000;">2010</span>-04-<span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">25</span>:08 <span style="color: #7a0874; font-weight: bold;">history</span>  <span style="color: #000000; font-weight: bold;">|</span> gmore
  <span style="color: #000000;">999</span>  <span style="color: #000000;">2010</span>-04-<span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">25</span>:08 <span style="color: #7a0874; font-weight: bold;">history</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">more</span>
 <span style="color: #000000;">1000</span>  <span style="color: #000000;">2010</span>-04-<span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">25</span>:08 <span style="color: #7a0874; font-weight: bold;">exit</span>
 <span style="color: #000000;">1001</span>  <span style="color: #000000;">2010</span>-04-<span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">10</span> <span style="color: #7a0874; font-weight: bold;">history</span>
 <span style="color: #000000;">1002</span>  <span style="color: #000000;">2010</span>-04-<span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">37</span>:07  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTTIMEFORMAT</span>=<span style="color: #ff0000;">&quot;%F %T &quot;</span>
 <span style="color: #000000;">1003</span>  <span style="color: #000000;">2010</span>-04-<span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">37</span>:<span style="color: #000000;">12</span> <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span>
 <span style="color: #000000;">1004</span>  <span style="color: #000000;">2010</span>-04-<span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">37</span>:<span style="color: #000000;">26</span> <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span>
 <span style="color: #000000;">1005</span>  <span style="color: #000000;">2010</span>-04-<span style="color: #000000;">13</span> <span style="color: #000000;">15</span>:<span style="color: #000000;">37</span>:<span style="color: #000000;">37</span> <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span></pre></div></div>

<p>可以看到，历史命令的时间戳已经加上了，但是.bash_history里并没有加上这个时间戳。其实这个时间记录是保存在当前shell进程内存里的，如果你logout并且重新登录的话会发现你上次登录时执行的那些命令的时间戳都为同一个值，即当时logout时的时间。</p>
<p>尽管如此，对于加上screen的bash来说，这个时间戳仍然可以长时间有效的，毕竟只要你的server不重启，screen就不会退出，因而这些时间就能长时间保留。</p>
<p style='text-align:left'>&copy; 2010, <a target='_blank' href='http://www.linuxers.cn'>Linux爱好者</a>. 版权所有. 转载请注明来自http://www.linuxers.cn</p>
<h4  class="related_post_title">推荐日志</h4><ul class="related_post"></ul>]]></content:encoded>
			<wfw:commentRss>http://www.linuxers.cn/2010/04/13/linux%e4%b8%8b%e5%8e%86%e5%8f%b2%e5%91%bd%e4%bb%a4history%e6%b7%bb%e5%8a%a0%e6%97%b6%e9%97%b4%e6%88%b3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bash PS1环境变量的设置</title>
		<link>http://www.linuxers.cn/2010/04/12/bash-ps1%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e7%9a%84%e8%ae%be%e7%bd%ae/</link>
		<comments>http://www.linuxers.cn/2010/04/12/bash-ps1%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e7%9a%84%e8%ae%be%e7%bd%ae/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 02:40:50 +0000</pubDate>
		<dc:creator>leconte</dc:creator>
				<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[PS1]]></category>

		<guid isPermaLink="false">http://www.linuxers.cn/?p=476</guid>
		<description><![CDATA[在bash下，命令行提示符的格式是由PS1这个环境变量来设置的。通常在/etc/bashrc会有一个系统级别的设置，例如我本机/etc/bashrc中的：

PS1=&#34;[\u@\h \W]\\$ &#34;

<span class="readmore"><a href="http://www.linuxers.cn/2010/04/12/bash-ps1%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e7%9a%84%e8%ae%be%e7%bd%ae/" title="bash PS1环境变量的设置" target="_blank">Read more 612 words</a></span>]]></description>
			<content:encoded><![CDATA[<p>在bash下，命令行提示符的格式是由PS1这个环境变量来设置的。通常在/etc/bashrc会有一个系统级别的设置，例如我本机/etc/bashrc中的：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">&quot;[\u@\h \W]\<span style="color: #000099; font-weight: bold;">\$</span> &quot;</span></pre></div></div>

<p>\u,\h,\W分别代表用户名，主机名和当前目录名。\$的含义是如果用户为root则输出#，否则输出$。<br />
因此在这种PS1的设置下，终端提示符通常如下：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family: Consolas,'Courier New',monospace"><span style="color: #7a0874; font-weight: bold;">&#91;</span>leconte<span style="color: #000000; font-weight: bold;">@</span>localhost ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$</pre></div></div>

<p>当然，用户可以~/.bashrc中自定义自己的提示符样式以满足自己的习惯。PS1支持的标示符很多，常用的有以下一些：</p>
<blockquote><p>\d:日期，例如Tue May 26<br />
\h:主机名<br />
\H:机器名<br />
\j:当前shell的job数<br />
\t:\T\@\A:四种格式显示的当前时间<br />
\u:当前用户名<br />
\w\W:当前工作目录<br />
\!:历史命令条数<br />
\e:转义字符</p></blockquote>
<p>值得一提的是可以通过\e结合终端的颜色支持实现提示符的彩色化，通过\e[开头，m结尾的格式可以定义一种颜色，例如\e[32;40m代表将当前色设置为绿色，如图：<br />
<a href="http://www.linuxers.cn/wp-content/uploads/2010/04/11.png"><img src="http://www.linuxers.cn/wp-content/uploads/2010/04/11.png" alt="1" title="1" width="442" height="90" class="alignnone size-full wp-image-477" /></a></p>
<p>可以看到提示符变成了绿色的，这个PS1的设置为[\e[32;40m\u@\w]\$\e[0m，我们来从前往后解析它，\e[32;40m代表将当前颜色改为绿色，因此它之前输出的[是白色，之后的leconte@~]$都是绿色，\e[0m代表恢复默认颜色，因此随后输出的ls的颜色为默认的白色。</p>
<p>这样以来，通过ascii颜色就可以定制出满足自身审美和需求的终端提示了，hoho</p>
<p style='text-align:left'>&copy; 2010, <a target='_blank' href='http://www.linuxers.cn'>Linux爱好者</a>. 版权所有. 转载请注明来自http://www.linuxers.cn</p>
<h4  class="related_post_title">推荐日志</h4><ul class="related_post"></ul>]]></content:encoded>
			<wfw:commentRss>http://www.linuxers.cn/2010/04/12/bash-ps1%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e7%9a%84%e8%ae%be%e7%bd%ae/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
