﻿<?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>BlogJava-Chan Chen Coding...-文章分类-Linux</title><link>http://www.blogjava.net/czihong/category/50894.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 25 May 2013 03:30:30 GMT</lastBuildDate><pubDate>Sat, 25 May 2013 03:30:30 GMT</pubDate><ttl>60</ttl><item><title> top命令的Load average 含义及性能参考基值</title><link>http://www.blogjava.net/czihong/articles/399670.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Thu, 23 May 2013 09:47:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/399670.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/399670.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/399670.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/399670.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/399670.html</trackback:ping><description><![CDATA[<div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><pre style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding: 0px;"><code style="word-wrap: break-word;">$ uptime<br style="word-wrap: break-word;" />11:12:26 up 3:44, 4 users, load average: 0.38, 0.31, 0.19<br style="word-wrap: break-word;" /></code></pre><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px;">系统平均负载被定义为在特定时间间隔内运行队列中的平均进程树。如果一个进程满足以下条件则其就会位于运行队列中：</p><ul style="word-wrap: break-word; margin: 0px; padding: 0px; list-style: none;"><li style="word-wrap: break-word; margin: 0px; padding: 0px; list-style: disc outside;">它没有在等待I/O操作的结果</li><li style="word-wrap: break-word; margin: 0px; padding: 0px; list-style: disc outside;">它没有主动进入等待状态(也就是没有调用'wait')</li><li style="word-wrap: break-word; margin: 0px; padding: 0px; list-style: disc outside;">没有被停止(例如：等待终止)</li></ul><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px;">上面的输出，load average后面分别是1分钟、5分钟、15分钟的负载情况。数据是每隔5秒钟检查一次活跃的进程数，然后根据这个数值算出来的。如果这个数除以CPU 的数目，结果高于5的时候就表明系统在超负荷运转了。</p></div><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">&nbsp;</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">Linux系统Load average负载详细解释&nbsp; 　我们知道判断一个系统的负载可以使用top，uptime等命令去查看，它分别记录了一分钟、五分钟、以及十五分钟的系统平均负载</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　例如我的某台服务器：</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　$ uptime</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　09:50:21 up 200 days, 15:07, 1 user, load average: 0.27, 0.33, 0.37</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　大部分的人都认为这个数字越小越好，其实有很多关联的提示信息，今天看到这个好文，应该可以给大家说清楚很多问题，转一下：</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　原文链接：&nbsp;<a href="http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages" style="word-wrap: break-word; text-decoration: none; color: #565656;">http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages</a></div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　你可能对于 Linux 的负载均值（load averages）已有了充分的了解。负载均值在 uptime 或者 top 命令中可以看到，它们可能会显示成这个样子：</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　load average: 0.09, 0.05, 0.01</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　很多人会这样理解负载均值：三个数分别代表不同时间段的系统平均负载（一分钟、五 分钟、以及十五分钟），它们的数字当然是越小越好。数字越高，说明服务器的负载越 大，这也可能是服务器出现某种问题的信号。</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　而事实不完全如此，是什么因素构成了负载均值的大小，以及如何区分它们目前的状况是 &#8220;好&#8221;还是&#8220;糟糕&#8221;？什么时候应该注意哪些不正常的数值？</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　回答这些问题之前，首先需要了解下这些数值背后的些知识。我们先用最简单的例子说明， 一台只配备一块单核处理器的服务器。</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　行车过桥</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　一只单核的处理器可以形象得比喻成一条单车道。设想下，你现在需要收取这条道路的过桥 费 &#8212; 忙于处理那些将要过桥的车辆。你首先当然需要了解些信息，例如车辆的载重、以及 还有多少车辆正在等待过桥。如果前面没有车辆在等待，那么你可以告诉后面的司机通过。 如果车辆众多，那么需要告知他们可能需要稍等一会。</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　因此，需要些特定的代号表示目前的车流情况，例如：</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　0.00 表示目前桥面上没有任何的车流。 实际上这种情况与 0.00 和 1.00 之间是相同的，总而言之很通畅，过往的车辆可以丝毫不用等待的通过。</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　1.00 表示刚好是在这座桥的承受范围内。 这种情况不算糟糕，只是车流会有些堵，不过这种情况可能会造成交通越来越慢。</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　超过 1.00，那么说明这座桥已经超出负荷，交通严重的拥堵。 那么情况有多糟糕？ 例如 2.00 的情况说明车流已经超出了桥所能承受的一倍，那么将有多余过桥一倍的车辆正在焦急的等待。3.00 的话情况就更不妙了，说明这座桥基本上已经快承受不了，还有超出桥负载两倍多的车辆正在等待。</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　上面的情况和处理器的负载情况非常相似。一辆汽车的过桥时间就好比是处理器处理某线程 的实际时间。Unix 系统定义的进程运行时长为所有处理器内核的处理时间加上线程 在队列中等待的时间。</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　和收过桥费的管理员一样，你当然希望你的汽车（操作）不会被焦急的等待。所以，理想状态 下，都希望负载平均值小于 1.00 。当然不排除部分峰值会超过 1.00，但长此以往保持这 个状态，就说明会有问题，这时候你应该会很焦急。</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　&#8220;所以你说的理想负荷为 1.00 ？&#8221;</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　嗯，这种情况其实并不完全正确。负荷 1.00 说明系统已经没有剩余的资源了。在实际情况中 ，有经验的系统管理员都会将这条线划在 0.70：</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　&#8220;需要进行调查法则&#8221;： 如果长期你的系统负载在 0.70 上下，那么你需要在事情变得更糟糕之前，花些时间了解其原因。</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　&#8220;现在就要修复法则&#8221;：1.00 。 如果你的服务器系统负载长期徘徊于 1.00，那么就应该马上解决这个问题。否则，你将半夜接到你上司的电话，这可不是件令人愉快的事情。</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">　　&#8220;凌晨三点半锻炼身体法则&#8221;：5.00。 如果你的服务器负载超过了 5.00 这个数字，那么你将失去你的睡眠，还得在会议中说明这情况发生的原因，总之千万不要让它发生。</div><img src ="http://www.blogjava.net/czihong/aggbug/399670.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2013-05-23 17:47 <a href="http://www.blogjava.net/czihong/articles/399670.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Curl命令使用整理</title><link>http://www.blogjava.net/czihong/articles/399038.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Thu, 09 May 2013 03:52:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/399038.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/399038.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/399038.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/399038.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/399038.html</trackback:ping><description><![CDATA[<div style="margin: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #fefef2;"><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">Refer to:&nbsp;<a href="http://www.cnblogs.com/wangkangluo1/archive/2012/04/17/2453975.html">http://www.cnblogs.com/wangkangluo1/archive/2012/04/17/2453975.html<br /></a><br />可以看作命令行浏览器</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">1、开启gzip请求<br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte</span><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /><strong style="margin: 0px; padding: 0px;">2、监控网页的响应时间</strong><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" "http://www.kklinux.com"</span><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /><strong style="margin: 0px; padding: 0px;">3. 监控站点可用性</strong><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -o /dev/null -s -w %{http_code} "http://www.kklinux.com"</span><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /><strong style="margin: 0px; padding: 0px;">4、以http1.0协议请求（默认为http1.1）</strong>&nbsp;<br style="margin: 0px; padding: 0px;" />curl -0 ..............&nbsp;<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1）读取网页&nbsp;<br style="margin: 0px; padding: 0px;" />　　<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl linuxidc.com"&gt;http://www.linuxidc.com</span>&nbsp;<br style="margin: 0px; padding: 0px;" />　　2）保存网页&nbsp;<br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">　　$ curl http://www.linuxidc.com &gt; page.html $ curl -o page.html http://www.linuxidc.com&nbsp;</span><br style="margin: 0px; padding: 0px;" />　　3）使用的proxy服务器及其端口：-x&nbsp;<br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">　　$ curl -x 123.45.67.89：1080 -o page.html http://www.linuxidc.com&nbsp;</span><br style="margin: 0px; padding: 0px;" />　　4）使用cookie来记录session信息&nbsp;<br style="margin: 0px; padding: 0px;" />　　<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -x 123.45.67.89：1080 -o page.html -D cookie0001.txt http://www.linuxidc.com</span>&nbsp;<br style="margin: 0px; padding: 0px;" />option： -D 是把http的response里面的cookie信息存到一个特别的文件中去，这样，当页面被存到page.html的同时，cookie信息也被存到了cookie0001.txt里面了&nbsp;<br style="margin: 0px; padding: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;5）那么，下一次访问的时候，如何继续使用上次留下的cookie信息呢？&nbsp;<br style="margin: 0px; padding: 0px;" />　　使用option来把上次的cookie信息追加到http request里面去：-b&nbsp;<br style="margin: 0px; padding: 0px;" />　　<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -x 123.45.67.89：1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com&nbsp;</span><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />6）浏览器信息~~~~&nbsp;<br style="margin: 0px; padding: 0px;" />随意指定自己这次访问所宣称的自己的浏览器信息： -A<br style="margin: 0px; padding: 0px;" />curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.yahoo.com&nbsp;<br style="margin: 0px; padding: 0px;" />这样，服务器端接到访问的要求，会认为你是一个运行在Windows 2000上的IE6.0，嘿嘿嘿，其实也许你用的是苹果机呢！&nbsp;<br style="margin: 0px; padding: 0px;" />而"Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686"则可以告诉对方你是一台PC上跑着的Linux，用的是Netscape 4.73，呵呵呵&nbsp;<br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />7）<br style="margin: 0px; padding: 0px;" />另外一个服务器端常用的限制方法，就是检查http访问的referer。比如你先访问首页，再访问里面所指定的下载页，这第二次访问的referer地址就是第一次访问成功后的页面地&nbsp;<br style="margin: 0px; padding: 0px;" />址。这样，<span style="margin: 0px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0102;">服务器端只要发现对下载页面某次访问的referer地址不 是首页的地址，就可以断定那是个盗连了</span></span><span style="margin: 0px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">~~~~~&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">讨厌讨厌~~~我就是要盗连~~~~~！！</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">幸好curl给我们提供了设定referer的option： -e</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.yahoo.com" -o page.html -D cookie0001.txt http://www.yahoo.com&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">这样，就可以骗对方的服务器，你是从mail.yahoo.com点击某个链接过来的了，呵呵呵&nbsp;</span><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">8）curl 下载文件&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">刚才讲过了，下载页面到一个文件里，可以使用 -o ，下载文件也是一样。</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">比如，&nbsp;<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG</span></span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">这里教大家一个新的option： -O</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">大写的O，这么用：&nbsp;<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG</span></span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">这样，就可以按照服务器上的文件名，自动存在本地了！&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">再来一个更好用的。</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">如果screen1.JPG以外还有screen2.JPG、screen3.JPG、....、screen10.JPG需要下载，难不成还要让我们写一个script来完成这些操作？</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">不干！</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">在curl里面，这么写就可以了：</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">呵呵呵，厉害吧？！~~~&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">9）</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">再来，我们继续讲解下载！</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG</span>&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">这样产生的下载，就是</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">~zzh/001.JPG</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">~zzh/002.JPG</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">...</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">~zzh/201.JPG</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">~nick/001.JPG</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">~nick/002.JPG</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">...</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">~nick/201.JPG&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">够方便的了吧？哈哈哈&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">咦？高兴得太早了。</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">由于zzh/nick下的文件名都是001，002...，201，下载下来的文件重名，后面的把前面的文件都给覆盖掉了~~~&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">没关系，我们还有更狠的！</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">--这是.....自定义文件名的下载？</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">--对头，呵呵！&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">#1是变量，指的是{zzh,nick}这部分，第一次取值zzh，第二次取值nick</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">#2代表的变量，则是第二段可变部分---[001-201]，取值从001逐一加到201</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">这样，自定义出来下载下来的文件名，就变成了这样：</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">原来： ~zzh/001.JPG ---&gt; 下载后： 001-zzh.JPG</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">原来： ~nick/001.JPG ---&gt; 下载后： 001-nick.JPG&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">这样一来，就不怕文件重名啦，呵呵&nbsp;</span><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">9）</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">继续讲下载</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">我们平时在windows平台上，flashget这样的工具可以帮我们分块并行下载，还可以断线续传。</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">curl在这些方面也不输给谁，嘿嘿&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">比如我们下载screen1.JPG中，突然掉线了，我们就可以这样开始续传</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">当然，你不要拿个flashget下载了一半的文件来糊弄我~~~~别的下载软件的半截文件可不一定能用哦~~~&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">分块下载，我们使用这个option就可以了： -r</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">举例说明</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">比如我们有一个http://cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 要下载（赵老师的电话朗诵 :D ）</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">我们就可以用这样的命令：</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -r 0-10240 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &amp;\</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -r 10241-20480 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &amp;\</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -r 20481-40960 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &amp;\</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -r 40961- -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">这样就可以分块下载啦。</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">不过你需要自己把这些破碎的文件合并起来</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">如果你用UNIX或苹果，用 cat zhao.part* &gt; zhao.mp3就可以</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">如果用的是Windows，用copy /b 来解决吧，呵呵&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">上面讲的都是http协议的下载，其实ftp也一样可以用。</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">用法嘛，</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -u name:passwd ftp://ip:port/path/file</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">或者大家熟悉的</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl ftp://name:passwd@ip:port/path/file&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">&nbsp;&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">10)上传的option是 -T&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">比如我们向ftp传一个文件：&nbsp;<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -T localfile -u name:passwd ftp://upload_site:port/path/&nbsp;</span></span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">当然，向http服务器上传文件也可以</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">比如&nbsp;<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi</span></span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">注意，这时候，使用的协议是HTTP的PUT method&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">刚才说到PUT，嘿嘿，自然让老服想起来了其他几种methos还没讲呢！</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">GET和POST都不能忘哦。&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">http提交一个表单，比较常用的是POST模式和GET模式&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff0000;">GET模式什么option都不用，只需要把变量写在url里面就可以了<br style="margin: 0px; padding: 0px;" />比如：<br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl http://www.yahoo.com/login.cgi?user=nickwolfe&amp;password=12345&nbsp;</span><br style="margin: 0px; padding: 0px;" />而POST模式的option则是 -d&nbsp;<br style="margin: 0px; padding: 0px;" />比如，<span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -d "user=nickwolfe&amp;password=12345" http://www.yahoo.com/login.cgi</span></span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">就相当于向这个站点发出一次登陆申请~~~~~&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">到底该用GET模式还是POST模式，要看对面服务器的程序设定。&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">一点需要注意的是，POST模式下的文件上的文件上传，比如</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">&lt;form method="POST" enctype="multipar/form-data" action="http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi"&gt;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">&lt;input type=file name=upload&gt;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">&lt;input type=submit name=nick value="go"&gt;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">&lt;/form&gt;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">这样一个HTTP表单，我们要用curl进行模拟，就该是这样的语法：</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">罗罗嗦嗦讲了这么多，其实curl还有很多很多技巧和用法</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">比如 https的时候使用本地证书，就可以这样</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -E localcert.pem https://remote_server&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">再比如，你还可以用curl通过dict协议去查字典~~~~~</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl dict://dict.org/d:computer&nbsp;</span><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">今天为了检查所有刺猬主机上所有域名是否有备案．在使用wget不爽的情况下，找到了curl这个命令行流量器命令．发现其对post的调用还是蛮好的．特别有利于对提交信息及变&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">更参数进行较验．对于我想将几十万域名到miibeian.gov.cn进行验证是否有备案信息非常有用．发现这篇文章很不错，特为转贴．&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">我的目标：</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -d "cxfs=1&amp;ym=xieyy.cn" http://www.miibeian.gov.cn/baxx_cx_servlet&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">在出来的信息中进行过滤，提取备案号信息，并设置一个标识位．将域名，备案号及标识位入库&nbsp;</span><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">用curl命令，post提交带空格的数据&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">今天偶然遇到一个情况，我想用curl登入一个网页，无意间发现要post的数据里带空格。比如用户名为"abcdef"，密码为"abc def"，其中有一个空格，按照我以前的方式提交：&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -D cookie -d "username=abcdef&amp;password=abc def" http://login.xxx.com/</span>提示登入失败。&nbsp;</span><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">于是查看curl手册man curl。找到：&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">d/--data (HTTP) Sends the speci?ed data in a POST request to the HTTP server, in a way that can emulate as if a user has ?lled in a HTML form and pressed the&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">submit button. Note that the data is sent exactly as speci?ed with no extra processing (with all newlines cut off). The data is expected to be "url-encoded".&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F/--form. If this option is used&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">more than once on the same command line, the data pieces speci?ed will be merged together with a separating &amp;-letter. Thus, using &#8217;-d name=daniel -d&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">skill=lousy&#8217; would generate a post chunk that looks like &#8217;name=daniel&amp;skill=lousy&#8217;.&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">于是改用：&nbsp;</span><br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #383838;">curl -D cookie -d "username=abcdef" -d "password=abc efg" http://login.xxx.com/这样就能成功登入了。&nbsp;</span></span></p>(责任编辑：飘飞的夜)</div><div style="margin: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #fefef2;">&nbsp;</div><div style="margin: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #fefef2;"><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5;">Curl是Linux下一个很强大的http命令行工具，其功能十分强大。</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">1) 二话不说，先从这里开始吧！</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl http://www.linuxidc.com</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">回车之后，www.linuxidc.com 的html就稀里哗啦地显示在屏幕上了&nbsp;&nbsp;&nbsp;&nbsp;~</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">2) 嗯，要想把读过来页面存下来，是不是要这样呢？</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl http://www.linuxidc.com &gt; page.html</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">当然可以，但不用这么麻烦的！</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">用curl的内置option就好，存下http的结果，用这个option: -o</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -o page.html http://www.linuxidc.com</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这样，你就可以看到屏幕上出现一个下载页面进度指示。等进展到100%，自然就 OK咯</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">3) 什么什么？！访问不到？肯定是你的proxy没有设定了。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">使用curl的时候，用这个option可以指定http访问所使用的proxy服务器及其端口： -x</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">4) 访问有些网站的时候比较讨厌，他使用cookie来记录session信息。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">像IE/NN这样的浏览器，当然可以轻易处理cookie信息，但我们的curl呢？.....</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">我们来学习这个option: -D &lt;&#8212; 这个是把http的response里面的cookie信息存到一个特别的文件中去</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这样，当页面被存到page.html的同时，cookie信息也被存到了cookie0001.txt里面了</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">5）那么，下一次访问的时候，如何继续使用上次留下的cookie信息呢？要知道，很多网站都是靠监视你的cookie信息，来判断你是不是不按规矩访问他们的网站的。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这次我们使用这个option来把上次的cookie信息追加到http request里面去： -b</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这样，我们就可以几乎模拟所有的IE操作，去访问网页了！</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">6）稍微等等&nbsp;&nbsp;&nbsp;&nbsp;~我好像忘记什么了&nbsp;&nbsp;&nbsp;&nbsp;~</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">对了！是浏览器信息</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">有些讨厌的网站总要我们使用某些特定的浏览器去访问他们，有时候更过分的是，还要使用某些特定的版本&nbsp;&nbsp;&nbsp;&nbsp;NND，哪里有时间为了它去找这些怪异的浏览器呢！？</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">好在curl给我们提供了一个有用的option，可以让我们随意指定自己这次访问所宣称的自己的浏览器信息： -A</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这样，服务器端接到访问的要求，会认为你是一个运行在Windows 2000上的 IE6.0，嘿嘿嘿，其实也许你用的是苹果机呢！</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">而"Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686"则可以告诉对方你是一台 PC上跑着的Linux，用的是Netscape 4.73，呵呵呵</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">7）另外一个服务器端常用的限制方法，就是检查http访问的referer。比如你先访问首页，再访问里面所指定的下载页，这第二次访问的 referer地址就是第一次访问成功后的页面地址。这样，服务器端只要发现对下载页面某次访问的referer地址不是首页的地址，就可以断定那是个盗 连了&nbsp;&nbsp;&nbsp;&nbsp;~</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">讨厌讨厌 ~我就是要盗连&nbsp;&nbsp;&nbsp;&nbsp;~！！</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">幸好curl给我们提供了设定referer的option： -e</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.linuxidc.com" -o page.html -D cookie0001.txt http://www.linuxidc.com</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这样，就可以骗对方的服务器，你是从mail.linuxidc.com点击某个链接过来的了，呵呵呵</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">8）写着写着发现漏掉什么重要的东西了！&#8212;&#8212;- 利用curl 下载文件</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">刚才讲过了，下载页面到一个文件里，可以使用 -o ，下载文件也是一样。比如，</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这里教大家一个新的option： -O 大写的O，这么用：</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这样，就可以按照服务器上的文件名，自动存在本地了！</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">再来一个更好用的。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">如果screen1.JPG以外还有screen2.JPG、screen3.JPG、....、screen10.JPG需要下载，难不成还要让我们写一个script来完成这些操作？</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">不干！</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">在curl里面，这么写就可以了：</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">呵呵呵，厉害吧？！ ~</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">9）再来，我们继续讲解下载！</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这样产生的下载，就是</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">~zzh/001.JPG</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">~zzh/002.JPG</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">...</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">~zzh/201.JPG</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">~nick/001.JPG</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">~nick/002.JPG</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">...</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">~nick/201.JPG</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">够方便的了吧？哈哈哈</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">咦？高兴得太早了。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">由于zzh/nick下的文件名都是001，002...，201，下载下来的文件重名，后面的把前面的文件都给覆盖掉了 ~</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">没关系，我们还有更狠的！</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;"><span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">$ curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG</span></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">&#8212;这是.....自定义文件名的下载？ &#8212;对头，呵呵！</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这样，自定义出来下载下来的文件名，就变成了这样：原来： ~zzh/001.JPG &#8212;-&gt; 下载后： 001-zzh.JPG 原来： ~nick/001.JPG &#8212;-&gt; 下载后： 001-nick.JPG</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 1.5;">这样一来，就不怕文件重名啦，呵呵</p></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 19px; font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #fefef2;">完</p><img src ="http://www.blogjava.net/czihong/aggbug/399038.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2013-05-09 11:52 <a href="http://www.blogjava.net/czihong/articles/399038.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java Web Application 远程调试</title><link>http://www.blogjava.net/czihong/articles/398812.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Sun, 05 May 2013 08:49:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/398812.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/398812.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/398812.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/398812.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/398812.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">最近在开发java web application的时候，因为很多原因，无法对自己开发的项目在本地进行调试，常常需要进行远程调试，之前一直通过打logger的方式进行，每次都要重新部署，相当的痛苦，今天下午研究了以下，如果进行远程调试。<br /><br />开发的web application是部署在tomcat上面的，那么问题就转化为如何调试tomcat。其实调试tomcat，本质上就是调试JVM。JVM的强大，从J2SE1.4.2开始，就实现了JPDA （Java Platform Debug Architecture）。<br /><br />tomcat默认情况下，是没有启用jpda的，如果要启用，需要传入参数<br /><strong><span style="text-decoration: underline;">-Xdebug -Xrunjdwp:transport=dt_socket, address=8000,server=y,suspend=y</span></strong><br /><br />那么问题是这些参数如何在tomcat启动的使用传入呢？这是时候，需要了解tomcat的启动脚本，在TOMCAT_HOME/bin</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">目录下，有三个脚本catalina.sh, startup.sh, 和 shutdown.sh。如果查看startup.sh和shutdown.sh，都是通过catalina.sh来启动的。脚本如下：<br /></p><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 />-->EXECUTABLE=catalina.sh<br /><br />exec&nbsp;"$PRGDIR"/"$EXECUTABLE"&nbsp;start&nbsp;"$@"</div>于是，我们可以查看下catalina.sh的脚本是如何实现的。<br /><br /><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><div># &nbsp; JPDA_TRANSPORT &nbsp;(Optional) JPDA transport used when the "jpda start"</div><div># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; command is executed. The default is "dt_socket".</div><div>#</div><div># &nbsp; JPDA_ADDRESS &nbsp; &nbsp;(Optional) Java runtime options used when the "jpda start"</div><div># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; command is executed. The default is 8000.</div><div>#</div><div># &nbsp; JPDA_SUSPEND &nbsp; &nbsp;(Optional) Java runtime options used when the "jpda start"</div><div># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; command is executed. Specifies whether JVM should suspend</div><div># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; execution immediately after startup. Default is "n".</div><div>#</div><div># &nbsp; JPDA_OPTS &nbsp; &nbsp; &nbsp; (Optional) Java runtime options used when the "jpda start"</div><div># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,</div><div># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and JPDA_SUSPEND are ignored. Thus, all required jpda</div><div># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; options MUST be specified. The default is:</div><div>#</div><div># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -agentlib:jdwp=transport=$JPDA_TRANSPORT,</div><div># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND</div><div><br /><div></div><div>if [ "$1" = "jpda" ] ; then</div><div>&nbsp; if [ -z "$JPDA_TRANSPORT" ]; then</div><div>&nbsp; &nbsp; JPDA_TRANSPORT="dt_socket"</div><div>&nbsp; fi &nbsp;</div><div>&nbsp; if [ -z "$JPDA_ADDRESS" ]; then</div><div>&nbsp; &nbsp; JPDA_ADDRESS="8000"</div><div>&nbsp; fi &nbsp;</div><div>&nbsp; if [ -z "$JPDA_SUSPEND" ]; then</div><div>&nbsp; &nbsp; JPDA_SUSPEND="n"</div><div>&nbsp; fi &nbsp;</div><div>&nbsp; if [ -z "$JPDA_OPTS" ]; then</div><div>&nbsp; &nbsp; JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"</div><div>&nbsp; fi &nbsp;</div><div>&nbsp; CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"</div><div>&nbsp; shift</div><div>fi</div><div style="display: inline-block;"><div></div></div></div></div><br />通过这个代码，我们可以看出，其实要启动jpda, 最主要的是要对JPDA_SUSPEND的值进行设置，由N改为Y。<br /><br />借鉴start.sh的启动，在linux下，我们可以自己创建一个jpda.sh的脚本，用来启动开启debug模式的tomcat，具体脚本如下，黑体为修改部分。<br /><br /><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 />-->os400=<span style="color: #0000FF; ">false</span><br />darwin=<span style="color: #0000FF; ">false</span><br /><span style="color: #0000FF; ">case</span>&nbsp;"`uname`"&nbsp;in<br />CYGWIN*)&nbsp;cygwin=<span style="color: #0000FF; ">true</span>;;<br />OS400*)&nbsp;os400=<span style="color: #0000FF; ">true</span>;;<br />Darwin*)&nbsp;darwin=<span style="color: #0000FF; ">true</span>;;<br />esac<br /><br />#&nbsp;resolve&nbsp;links&nbsp;-&nbsp;$0&nbsp;may&nbsp;be&nbsp;a&nbsp;softlink<br />PRG="$0"<br /><br /><span style="color: #0000FF; ">while</span>&nbsp;[&nbsp;-h&nbsp;"$PRG"&nbsp;]&nbsp;;&nbsp;<span style="color: #0000FF; ">do</span><br />&nbsp;&nbsp;ls=`ls&nbsp;-ld&nbsp;"$PRG"`<br />&nbsp;&nbsp;link=`expr&nbsp;"$ls"&nbsp;:&nbsp;'.*-&gt;&nbsp;\(.*\)$'`<br />&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;expr&nbsp;"$link"&nbsp;:&nbsp;'/.*'&nbsp;&gt;&nbsp;/dev/<span style="color: #0000FF; ">null</span>;&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;PRG="$link"<br />&nbsp;&nbsp;<span style="color: #0000FF; ">else</span><br />&nbsp;&nbsp;&nbsp;&nbsp;PRG=`dirname&nbsp;"$PRG"`/"$link"<br />&nbsp;&nbsp;fi<br />done<br />&nbsp;<br />PRGDIR=`dirname&nbsp;"$PRG"`<br />EXECUTABLE=catalina.sh<br /><br />#&nbsp;Check&nbsp;that&nbsp;target&nbsp;executable&nbsp;exists<br /><span style="color: #0000FF; ">if</span>&nbsp;$os400;&nbsp;then<br />&nbsp;&nbsp;#&nbsp;-x&nbsp;will&nbsp;Only&nbsp;work&nbsp;on&nbsp;the&nbsp;os400&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;the&nbsp;files&nbsp;are:&nbsp;<br />&nbsp;&nbsp;#&nbsp;1.&nbsp;owned&nbsp;by&nbsp;the&nbsp;user<br />&nbsp;&nbsp;#&nbsp;2.&nbsp;owned&nbsp;by&nbsp;the&nbsp;PRIMARY&nbsp;group&nbsp;of&nbsp;the&nbsp;user<br />&nbsp;&nbsp;#&nbsp;<span style="color: #0000FF; ">this</span>&nbsp;will&nbsp;not&nbsp;work&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;the&nbsp;user&nbsp;belongs&nbsp;in&nbsp;secondary&nbsp;groups<br />&nbsp;&nbsp;eval<br /><span style="color: #0000FF; ">else</span><br />&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;[&nbsp;!&nbsp;-x&nbsp;"$PRGDIR"/"$EXECUTABLE"&nbsp;];&nbsp;then<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"Cannot&nbsp;find&nbsp;$PRGDIR/$EXECUTABLE"<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"The&nbsp;file&nbsp;is&nbsp;absent&nbsp;or&nbsp;does&nbsp;not&nbsp;have&nbsp;execute&nbsp;permission"<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"This&nbsp;file&nbsp;is&nbsp;needed&nbsp;to&nbsp;run&nbsp;this&nbsp;program"<br />&nbsp;&nbsp;&nbsp;&nbsp;exit&nbsp;1<br />&nbsp;&nbsp;fi<br />fi&nbsp;<br /><br /><strong>export&nbsp;JPDA_SUSPEND=y</strong><br /><br />exec&nbsp;"$PRGDIR"/"$EXECUTABLE"&nbsp;<strong>jpda&nbsp;start</strong>&nbsp;"$@"</div><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><strong>在Eclipse中远程调试Tomcat</strong></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">首先将Tomcat 5.5.26的源代码分为container connectors jasper servletapi build五个项目，导入到Eclipse中。启动相关的代码主要在container中，就以它为当前项目，打开&#8221;Debug Configurations&#8220;对话框。</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">然后创建一个&#8221;Remote Java Application&#8220;，Connection Type选择&#8221;Standard (Socket Attach)&#8220;，Host填写localhost（Tomcat所在的主机地址），Port填写8000。最后点击&#8221;Apply&#8220;保存。</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><img src="http://hi.csdn.net/attachment/201001/24/49338_1264334380iDG5.jpg" alt="Eclipse的Debug Configurations对话框中配置远程调试" width="793" height="525" style="border: none;" /></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">首先确保已经执行了jpda.bat，Tomcat正在等待调试器连接；然后执行上述的Debug Configuration，Eclipse就可以连上Tomcat。</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">Tomcat的启动是从Bootstrap的main方法开始，我在第一行代码处设置了断点，Tomcat的启动就停在了这一行：</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><img src="http://hi.csdn.net/attachment/201001/24/49338_1264335021XUuZ.jpg" alt="断点调试Tomcat的启动过程" width="932" height="569" style="border: none;" /></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">接着，让Tomcat继续执行，我们可以看到，控制台输出了启动信息。</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><img src="http://hi.csdn.net/attachment/201001/24/49338_1264335334QJ8n.jpg" alt="Tomcat在JPDA模式下继续启动" width="661" height="530" style="border: none;" /></p><img src ="http://www.blogjava.net/czihong/aggbug/398812.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2013-05-05 16:49 <a href="http://www.blogjava.net/czihong/articles/398812.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Memcache服务器端的安装</title><link>http://www.blogjava.net/czihong/articles/396798.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Thu, 21 Mar 2013 06:06:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/396798.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/396798.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/396798.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/396798.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/396798.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-color: #ffffff; color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px;"><strong style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;">Linux下Memcache服务器端的安装</strong><br />服务器端主要是安装memcache服务器端，目前的最新版本是 memcached-1.3.0 。<br />下载：http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz<br />另外，Memcache用到了libevent这个库用于Socket的处理，所以还需要安装libevent，libevent的最新版本是libevent-1.3。（如果你的系统已经安装了libevent，可以不用安装）<br />官网：http://www.monkey.org/~provos/libevent/<br />下载：http://www.monkey.org/~provos/libevent-1.3.tar.gz</p><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-color: #ffffff; color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px;">用wget指令直接下载这两个东西.下载回源文件后。<br />1.先安装libevent。这个东西在配置时需要指定一个安装路径，即./configure --prefix=/usr；然后make；然后make install；<br />2.再安装memcached，只是需要在配置时需要指定libevent的安装路径即./configure --with-libevent=/usr；然后make；然后make install；<br />这样就完成了Linux下Memcache服务器端的安装。详细的方法如下：<br /><br /></p><blockquote style="margin: 5px 0px; padding: 8px 12px 8px 36px; border: 1px dashed #cccccc; outline: 0px; font-size: 16px; vertical-align: baseline; background-image: url(http://www.ccvita.com/usr/themes/ccvita/images/blockquote.gif); background-attachment: scroll; background-color: #f4f5f7; quotes: ''; color: #666666; font-style: italic; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px; background-position: 3px 3px; background-repeat: no-repeat no-repeat;"><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;">1.分别把memcached和libevent下载回来，放到 /tmp 目录下：<br /># cd /tmp<br /># wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz<br /># wget http://www.monkey.org/~provos/libevent-1.2.tar.gz</p><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;">2.先安装libevent：<br /># tar zxvf libevent-1.2.tar.gz<br /># cd libevent-1.2<br /># ./configure --prefix=/usr<br /># make<br /># make install</p><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;">3.测试libevent是否安装成功：<br /># ls -al /usr/lib | grep libevent<br />lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent-1.2.so.1 -&gt; libevent-1.2.so.1.0.3<br />-rwxr-xr-x 1 root root 263546 11?? 12 17:38 libevent-1.2.so.1.0.3<br />-rw-r--r-- 1 root root 454156 11?? 12 17:38 libevent.a<br />-rwxr-xr-x 1 root root 811 11?? 12 17:38 libevent.la<br />lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent.so -&gt; libevent-1.2.so.1.0.3<br />还不错，都安装上了。</p><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;">4.安装memcached，同时需要安装中指定libevent的安装位置：<br /># cd /tmp<br /># tar zxvf memcached-1.2.0.tar.gz<br /># cd memcached-1.2.0<br /># ./configure --with-libevent=/usr<br /># make<br /># make install<br />如果中间出现报错，请仔细检查错误信息，按照错误信息来配置或者增加相应的库或者路径。<br />安装完成后会把memcached放到 /usr/local/bin/memcached ，</p><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;">5.测试是否成功安装memcached：<br /># ls -al /usr/local/bin/mem*<br />-rwxr-xr-x 1 root root 137986 11?? 12 17:39 /usr/local/bin/memcached<br />-rwxr-xr-x 1 root root 140179 11?? 12 17:39 /usr/local/bin/memcached-debug</p></blockquote><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-color: #ffffff; color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px;"><strong style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;">安装Memcache的PHP扩展</strong><br />1.在http://pecl.php.net/package/memcache 选择相应想要下载的memcache版本。<br />2.安装PHP的memcache扩展<br /></p><blockquote style="margin: 5px 0px; padding: 8px 12px 8px 36px; border: 1px dashed #cccccc; outline: 0px; font-size: 16px; vertical-align: baseline; background-image: url(http://www.ccvita.com/usr/themes/ccvita/images/blockquote.gif); background-attachment: scroll; background-color: #f4f5f7; quotes: ''; color: #666666; font-style: italic; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px; background-position: 3px 3px; background-repeat: no-repeat no-repeat;">tar vxzf memcache-2.2.1.tgz<br />cd memcache-2.2.1<br />/usr/local/php/bin/phpize<br />./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir<br />make<br />make install</blockquote><br style="color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; font-size: 16px; line-height: 28px; background-color: #ffffff;" /><span style="color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; font-size: 16px; line-height: 28px; background-color: #ffffff;">3.上述安装完后会有类似这样的提示：</span><br style="color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; font-size: 16px; line-height: 28px; background-color: #ffffff;" /><blockquote style="margin: 5px 0px; padding: 8px 12px 8px 36px; border: 1px dashed #cccccc; outline: 0px; font-size: 16px; vertical-align: baseline; background-image: url(http://www.ccvita.com/usr/themes/ccvita/images/blockquote.gif); background-attachment: scroll; background-color: #f4f5f7; quotes: ''; color: #666666; font-style: italic; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px; background-position: 3px 3px; background-repeat: no-repeat no-repeat;">Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/</blockquote><br style="color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; font-size: 16px; line-height: 28px; background-color: #ffffff;" /><span style="color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; font-size: 16px; line-height: 28px; background-color: #ffffff;">4.把php.ini中的extension_dir = "./"修改为</span><br style="color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; font-size: 16px; line-height: 28px; background-color: #ffffff;" /><blockquote style="margin: 5px 0px; padding: 8px 12px 8px 36px; border: 1px dashed #cccccc; outline: 0px; font-size: 16px; vertical-align: baseline; background-image: url(http://www.ccvita.com/usr/themes/ccvita/images/blockquote.gif); background-attachment: scroll; background-color: #f4f5f7; quotes: ''; color: #666666; font-style: italic; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px; background-position: 3px 3px; background-repeat: no-repeat no-repeat;">extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/"</blockquote><br style="color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; font-size: 16px; line-height: 28px; background-color: #ffffff;" /><span style="color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; font-size: 16px; line-height: 28px; background-color: #ffffff;">5.添加一行来载入memcache扩展：extension=memcache.so</span><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-color: #ffffff; color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px;"></p><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-color: #ffffff; color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px;"><strong style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;">memcached的基本设置</strong>：<br />1.启动Memcache的服务器端：<br /># /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 12000 -c 256 -P /tmp/memcached.pid<br /></p><blockquote style="margin: 5px 0px; padding: 8px 12px 8px 36px; border: 1px dashed #cccccc; outline: 0px; font-size: 16px; vertical-align: baseline; background-image: url(http://www.ccvita.com/usr/themes/ccvita/images/blockquote.gif); background-attachment: scroll; background-color: #f4f5f7; quotes: ''; color: #666666; font-style: italic; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px; background-position: 3px 3px; background-repeat: no-repeat no-repeat;">-d选项是启动一个守护进程，<br />-m是分配给Memcache使用的内存数量，单位是MB，我这里是10MB，<br />-u是运行Memcache的用户，我这里是root，<br />-l是监听的服务器IP地址，如果有多个地址的话，我这里指定了服务器的IP地址192.168.0.200，<br />-p是设置Memcache监听的端口，我这里设置了12000，最好是1024以上的端口，<br />-c选项是最大运行的并发连接数，默认是1024，我这里设置了256，按照你服务器的负载量来设定，<br />-P是设置保存Memcache的pid文件，我这里是保存在 /tmp/memcached.pid，</blockquote><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-color: #ffffff; color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px;">2.如果要结束Memcache进程，执行：<br /></p><blockquote style="margin: 5px 0px; padding: 8px 12px 8px 36px; border: 1px dashed #cccccc; outline: 0px; font-size: 16px; vertical-align: baseline; background-image: url(http://www.ccvita.com/usr/themes/ccvita/images/blockquote.gif); background-attachment: scroll; background-color: #f4f5f7; quotes: ''; color: #666666; font-style: italic; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px; background-position: 3px 3px; background-repeat: no-repeat no-repeat;"># kill `cat /tmp/memcached.pid`</blockquote><br style="color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; font-size: 16px; line-height: 28px; background-color: #ffffff;" /><span style="color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; font-size: 16px; line-height: 28px; background-color: #ffffff;">也可以启动多个守护进程，不过端口不能重复。</span><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-color: #ffffff; color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px;"></p><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-color: #ffffff; color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px;">3.重启apache，service httpd restart</p><p style="margin: 0px 0px 20px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-color: #ffffff; color: #444444; font-family: Georgia, Times, 'Times New Roman', serif; line-height: 28px;"><strong style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;">Memcache环境测试</strong>：<br />运行下面的php文件，如果有输出This is a test!，就表示环境搭建成功。开始领略Memcache的魅力把！<br />&lt; ?php<br />$mem = new Memcache;<br />$mem-&gt;connect("127.0.0.1", 11211);<br />$mem-&gt;set('key', 'This is a test!', 0, 60);<br />$val = $mem-&gt;get('key');<br />echo $val;<br />?&gt;</p><img src ="http://www.blogjava.net/czihong/aggbug/396798.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2013-03-21 14:06 <a href="http://www.blogjava.net/czihong/articles/396798.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FTP Server</title><link>http://www.blogjava.net/czihong/articles/395862.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Thu, 28 Feb 2013 08:43:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/395862.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/395862.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/395862.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/395862.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/395862.html</trackback:ping><description><![CDATA[<div style="margin: 0px; border: 0px; font-size: 13px; line-height: 19px; font-family: Ubuntu, 'Ubuntu Beta', 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; vertical-align: baseline; color: #333333; background-color: #ffffff;"><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">File Transfer Protocol (FTP) is a TCP protocol for downloading files between computers. In the past, it has also been used for uploading but, as that method does not use encryption, user credentials as well as data transferred in the clear and are easily intercepted. So if you are here looking for a way to upload and download files securely, see the section on&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">OpenSSH</span>&nbsp;in&nbsp;<a href="https://help.ubuntu.com/12.04/serverguide/remote-administration.html" title="Remote Administration" style="text-decoration: none; color: #dd4814; margin: 0px; padding: 0px; border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: #ccc1c1; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;">Remote Administration</a>&nbsp;instead.</p><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">FTP works on a client/server model. The server component is called an&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">FTP daemon</span>. It continuously listens for FTP requests from remote clients. When a request is received, it manages the login and sets up the connection. For the duration of the session it executes any of commands sent by the FTP client.</p><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Access to an FTP server can be managed in two ways:</p><div itemizedlist"="" style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><ul itemizedlist=""  compact"="" style="margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; list-style: decimal;"><li itemizedlist"="" style="margin: 0px 0px 8px 2.4em; padding: 0px; border: 0px; font-style: inherit; line-height: 14px; font-family: inherit; text-align: left; vertical-align: baseline;"><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Anonymous</p></li><li itemizedlist"="" style="margin: 0.2em 0px 0px 2.4em; padding: 0px; border: 0px; font-style: inherit; line-height: 14px; font-family: inherit; text-align: left; vertical-align: baseline;"><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Authenticated</p></li></ul></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">In the Anonymous mode, remote clients can access the FTP server by using the default user account called "anonymous" or "ftp" and sending an email address as the password. In the Authenticated mode a user must have an account and a password. This latter choice is very insecure and should not be used except in special circumstances. If you are looking to transfer files securely see SFTP in the section on OpenSSH-Server. User access to the FTP server directories and files is dependent on the permissions defined for the account used at login. As a general rule, the FTP daemon will hide the root directory of the FTP server and change it to the FTP Home directory. This hides the rest of the file system from remote sessions.</p></div><div sectionlinks"="" style="margin: 0px; padding-right: 1em; padding-left: 1em; border: 1px solid #ccc1c1; font-size: 13px; line-height: 19px; font-family: Ubuntu, 'Ubuntu Beta', 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; vertical-align: baseline; display: inline-block; background-color: #f7f6f5; color: #333333;"><ul style="margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; list-style: decimal;"><li style="margin: 0.5em 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 14px; font-family: inherit; text-align: left; vertical-align: baseline; list-style-type: none;"><a href="https://help.ubuntu.com/12.04/serverguide/ftp-server.html#vsftpd-ftp-server-installation" title="vsftpd - FTP Server Installation" style="text-decoration: none; color: #dd4814; margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd - FTP Server Installation</a></li><li style="margin: 0.5em 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 14px; font-family: inherit; text-align: left; vertical-align: baseline; list-style-type: none;"><a href="https://help.ubuntu.com/12.04/serverguide/ftp-server.html#vsftpd-anonymous-configuration" title="Anonymous FTP Configuration" style="text-decoration: none; color: #dd4814; margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;">Anonymous FTP Configuration</a></li><li style="margin: 0.5em 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 14px; font-family: inherit; text-align: left; vertical-align: baseline; list-style-type: none;"><a href="https://help.ubuntu.com/12.04/serverguide/ftp-server.html#vsftpd-userauth-configuration" title="User Authenticated FTP Configuration" style="text-decoration: none; color: #dd4814; margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;">User Authenticated FTP Configuration</a></li><li style="margin: 0.5em 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 14px; font-family: inherit; text-align: left; vertical-align: baseline; list-style-type: none;"><a href="https://help.ubuntu.com/12.04/serverguide/ftp-server.html#vsftpd-security" title="Securing FTP" style="text-decoration: none; color: #dd4814; margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;">Securing FTP</a></li><li style="margin: 0.5em 0px 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 14px; font-family: inherit; text-align: left; vertical-align: baseline; list-style-type: none;"><a href="https://help.ubuntu.com/12.04/serverguide/ftp-server.html#vsftpd-references" title="References" style="text-decoration: none; color: #dd4814; margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;">References</a></li></ul></div><div sect"="" id="vsftpd-ftp-server-installation" style="margin: 2.4em 0px 0px; border: 0px; font-size: 13px; line-height: 19px; font-family: Ubuntu, 'Ubuntu Beta', 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; vertical-align: baseline; clear: both; color: #333333; background-color: #ffffff;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><div style="margin: 0px 0px 0.5em; border-width: 0px 0px 1px; border-bottom-style: solid; border-bottom-color: #ccc1c1; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><h2>vsftpd - FTP Server Installation</h2></div><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>&nbsp;is an FTP daemon available in Ubuntu. It is easy to install, set up, and maintain. To install&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>&nbsp;you can run the following command:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;"><span command"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline; background-color: #f7f6f5;">sudo apt-get install vsftpd</span> </pre></div></div></div></div></div><div sect"="" id="vsftpd-anonymous-configuration" style="margin: 2.4em 0px 0px; border: 0px; font-size: 13px; line-height: 19px; font-family: Ubuntu, 'Ubuntu Beta', 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; vertical-align: baseline; clear: both; color: #333333; background-color: #ffffff;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><div style="margin: 0px 0px 0.5em; border-width: 0px 0px 1px; border-bottom-style: solid; border-bottom-color: #ccc1c1; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><h2>Anonymous FTP Configuration</h2></div><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">By default&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>&nbsp;is&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">not</span>&nbsp;configured to allow anonymous download. If you wish to enable anonymous download edit&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/etc/vsftpd.conf</span>&nbsp;by changing:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-image: url(https://help.ubuntu.com/12.04/serverguide/yelp-code.png); background-position: 100% 0%; background-repeat: no-repeat no-repeat;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;">anonymous_enable=Yes </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">During installation a&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">ftp</span>&nbsp;user is created with a home directory of&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/srv/ftp</span>. This is the default FTP directory.</p><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">If you wish to change this location, to&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/srv/files/ftp</span>&nbsp;for example, simply create a directory in another location and change the&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">ftp</span>&nbsp;user's home directory:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;"><span command"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline; background-color: #f7f6f5;">sudo mkdir /srv/files/ftp</span> <span command"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline; background-color: #f7f6f5;">sudo usermod -d /srv/files/ftp ftp</span>  </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">After making the change restart&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;"><span command"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline; background-color: #f7f6f5;">sudo restart vsftpd</span> </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Finally, copy any files and directories you would like to make available through anonymous FTP to&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/srv/files/ftp</span>, or&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/srv/ftp</span>&nbsp;if you wish to use the default.</p></div></div></div></div><div sect"="" id="vsftpd-userauth-configuration" style="margin: 2.4em 0px 0px; border: 0px; font-size: 13px; line-height: 19px; font-family: Ubuntu, 'Ubuntu Beta', 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; vertical-align: baseline; clear: both; color: #333333; background-color: #ffffff;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><div style="margin: 0px 0px 0.5em; border-width: 0px 0px 1px; border-bottom-style: solid; border-bottom-color: #ccc1c1; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><h2>User Authenticated FTP Configuration</h2></div><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">By default&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>&nbsp;is configured to authenticate system users and allow them to download files. If you want users to be able to upload files, edit<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/etc/vsftpd.conf</span>:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-image: url(https://help.ubuntu.com/12.04/serverguide/yelp-code.png); background-position: 100% 0%; background-repeat: no-repeat no-repeat;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;">write_enable=YES </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Now restart&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;"><span command"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline; background-color: #f7f6f5;">sudo restart vsftpd</span> </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Now when system users login to FTP they will start in their&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">home</span>&nbsp;directories where they can download, upload, create directories, etc.</p><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Similarly, by default, anonymous users are not allowed to upload files to FTP server. To change this setting, you should uncomment the following line, and restart&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-image: url(https://help.ubuntu.com/12.04/serverguide/yelp-code.png); background-position: 100% 0%; background-repeat: no-repeat no-repeat;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;">anon_upload_enable=YES </pre></div><div note-warning"="" title="Warning" style="margin: 0px; padding: 6px; border: 1px solid #e5e5e3; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-color: #f7f6f5;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-image: url(https://help.ubuntu.com/12.04/serverguide/yelp-note-warning.png); min-height: 24px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><div style="margin: 0px 0px 0px 30px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Enabling anonymous FTP upload can be an extreme security risk. It is best to not enable anonymous upload on servers accessed directly from the Internet.</p></div></div></div></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">The configuration file consists of many configuration parameters. The information about each parameter is available in the configuration file. Alternatively, you can refer to the man page,&nbsp;<span command"="" style="margin: 0px; padding: 0px 0.2em; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline; background-color: #f7f6f5;">man 5 vsftpd.conf</span>&nbsp;for details of each parameter.</p></div></div></div></div><div sect"="" id="vsftpd-security" style="margin: 2.4em 0px 0px; border: 0px; font-size: 13px; line-height: 19px; font-family: Ubuntu, 'Ubuntu Beta', 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; vertical-align: baseline; clear: both; color: #333333; background-color: #ffffff;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><div style="margin: 0px 0px 0.5em; border-width: 0px 0px 1px; border-bottom-style: solid; border-bottom-color: #ccc1c1; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><h2>Securing FTP</h2></div><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">There are options in&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/etc/vsftpd.conf</span>&nbsp;to help make&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>&nbsp;more secure. For example users can be limited to their home directories by uncommenting:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-image: url(https://help.ubuntu.com/12.04/serverguide/yelp-code.png); background-position: 100% 0%; background-repeat: no-repeat no-repeat;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;">chroot_local_user=YES </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">You can also limit a specific list of users to just their home directories:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-image: url(https://help.ubuntu.com/12.04/serverguide/yelp-code.png); background-position: 100% 0%; background-repeat: no-repeat no-repeat;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;">chroot_list_enable=YES chroot_list_file=/etc/vsftpd.chroot_list </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">After uncommenting the above options, create a&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/etc/vsftpd.chroot_list</span>&nbsp;containing a list of users one per line. Then restart&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;"><span command"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline; background-color: #f7f6f5;">sudo restart vsftpd</span> </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Also, the&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/etc/ftpusers</span>&nbsp;file is a list of users that are&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">disallowed</span>&nbsp;FTP access. The default list includes root, daemon, nobody, etc. To disable FTP access for additional users simply add them to the list.</p><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">FTP can also be encrypted using&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">FTPS</span>. Different from&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">SFTP</span>,&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">FTPS</span>&nbsp;is FTP over Secure Socket Layer (SSL).&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">SFTP</span>&nbsp;is a FTP like session over an encrypted&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">SSH</span>&nbsp;connection. A major difference is that users of SFTP need to have a&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">shell</span>&nbsp;account on the system, instead of a&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">nologin</span>&nbsp;shell. Providing all users with a shell may not be ideal for some environments, such as a shared web host. However, it is possible to restrict such accounts to only SFTP and disable shell interaction. See the section on OpenSSH-Server for more.</p><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">To configure&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">FTPS</span>, edit&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/etc/vsftpd.conf</span>&nbsp;and at the bottom add:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-image: url(https://help.ubuntu.com/12.04/serverguide/yelp-code.png); background-position: 100% 0%; background-repeat: no-repeat no-repeat;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;">ssl_enable=Yes </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Also, notice the certificate and key related options:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-image: url(https://help.ubuntu.com/12.04/serverguide/yelp-code.png); background-position: 100% 0%; background-repeat: no-repeat no-repeat;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;">rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">By default these options are set to the certificate and key provided by the&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">ssl-cert</span>&nbsp;package. In a production environment these should be replaced with a certificate and key generated for the specific host. For more information on certificates see&nbsp;<a href="https://help.ubuntu.com/12.04/serverguide/certificates-and-security.html" title="Certificates" style="text-decoration: none; color: #dd4814; margin: 0px; padding: 0px; border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: #ccc1c1; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;">Certificates</a>.</p><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Now restart&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>, and non-anonymous users will be forced to use&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">FTPS</span>:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;"><span command"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline; background-color: #f7f6f5;">sudo restart vsftpd</span> </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">To allow users with a shell of&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/usr/sbin/nologin</span>&nbsp;access to FTP, but have no shell access, edit&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/etc/shells</span>&nbsp;adding the&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">nologin</span>&nbsp;shell:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-image: url(https://help.ubuntu.com/12.04/serverguide/yelp-code.png); background-position: 100% 0%; background-repeat: no-repeat no-repeat;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;"># /etc/shells: valid login shells /bin/csh /bin/sh /usr/bin/es /usr/bin/ksh /bin/ksh /usr/bin/rc /usr/bin/tcsh /bin/tcsh /usr/bin/esh /bin/dash /bin/bash /bin/rbash /usr/bin/screen /usr/sbin/nologin </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">This is necessary because, by default&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">vsftpd</span>&nbsp;uses PAM for authentication, and the&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/etc/pam.d/vsftpd</span>&nbsp;configuration file contains:</p><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline; background-image: url(https://help.ubuntu.com/12.04/serverguide/yelp-code.png); background-position: 100% 0%; background-repeat: no-repeat no-repeat;"><pre "="" style="margin-top: 0px; margin-bottom: 8px; padding: 0.5em 1em; border: 1px dashed #c1b496; font-style: inherit; line-height: 16px; font-family: UbuntuMono, courier, monospace; vertical-align: baseline; background-color: #f3f3f3; white-space: pre-wrap; word-wrap: break-word;">auth    required        pam_shells.so </pre></div><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">The&nbsp;<span emphasis"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">shells</span>&nbsp;PAM module restricts access to shells listed in the&nbsp;<span filename"="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: monospace; vertical-align: baseline;">/etc/shells</span>&nbsp;file.</p><p style="line-height: 1.5; margin: 0px 0px 8px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline;">Most popular FTP clients can be configured to connect using FTPS. The&nbsp;<span application"="" style="margin: 0px; padding: 0px; border: 0px; font-style: italic; line-height: 1.5; font-family: inherit; vertical-align: baseline;">lftp</span>&nbsp;command line FTP client has the ability to use FTPS as well.</p></div></div></div></div><div sect"="" id="vsftpd-references" style="margin: 2.4em 0px 0px; border: 0px; font-size: 13px; line-height: 19px; font-family: Ubuntu, 'Ubuntu Beta', 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; vertical-align: baseline; clear: both; color: #333333; background-color: #ffffff;"><div style="margin: 0px; border: 0px; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><div style="margin: 0px 0px 0.5em; border-width: 0px 0px 1px; border-bottom-style: solid; border-bottom-color: #ccc1c1; font-style: inherit; line-height: 1.5; font-family: inherit; vertical-align: baseline;"><h2>References</h2></div></div></div><img src ="http://www.blogjava.net/czihong/aggbug/395862.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2013-02-28 16:43 <a href="http://www.blogjava.net/czihong/articles/395862.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>set up ssh server on ubuntu server 12.04 edition</title><link>http://www.blogjava.net/czihong/articles/395640.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Sat, 23 Feb 2013 17:18:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/395640.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/395640.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/395640.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/395640.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/395640.html</trackback:ping><description><![CDATA[<p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">SSH stands for &#8220;secure shell&#8221;, and it is a network protocol that allows you to securely send commands to a remote machine. The &#8220;secure&#8221; part comes from the fact that the connection is encrypted, which means that an attacker cannot eavesdrop on the connection, or intercept and replace your commands with his own midway through transit. SSH is pretty reliable and secure, and is commonly used in the Linux world. Administrators often use it to remotely manage machines &#8211; it&#8217;s usually more comfortable to control a server from your laptop than in the chilly and noisy server room.</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">In this post, we&#8217;ll show you how to set up an SSH server on Ubuntu 12.04 Precise Pangolin.<br /><br /><iframe width="300" height="250" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" id="aswift_0" name="aswift_0" style="background-color: transparent; border-width: 0px; margin: 0px; padding: 0px; vertical-align: baseline; left: 0px; position: absolute; top: 0px;"></iframe></p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">The default SSH server package for Ubuntu 12.04 Precise Pangolin is OpenSSH Server, which we&#8217;ll use here.</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">First, you&#8217;ll need to install OpenSSH Server. To do so, open up a Terminal window and type the following command:</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;"><strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">sudo apt-get install openssh-server</strong></p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">Enter your password to authenticate, and the apt utility will download and install OpenSSH Server for you. Depending on the speed of your Internet connection and your computer, the installation may take several minutes.</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">Once the installation has finished, return to the Terminal window. We&#8217;ll need to make a few changes to your /etc/ssh/sshd_config file in order to increase SSH&#8217;s security. First, as always, we&#8217;ll want to make a backup copy of your sshd_config file in case anything goes wrong. Type this command into the Terminal:</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;"><strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">sudo cp /etc/ssh/sshd_config ~</strong></p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">This will make a backup copy of the sshd_config file in your home directory.</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">Next, we&#8217;ll need to edit the sshd_config file itself.</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;"><strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">sudo vi /etc/ssh/sshd_config</strong></p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">(Note that you can use emacs or gedit or another text editor of your choice.)</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">Like almost every other server software package, SSH is controlled by a number of directives in its configuration file. The default installation of OpenSSH server is reasonably secure. However, you might want to make a few changes to tighten up its security to additional degree.</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">The &#8220;PermitRootLogin&#8221; directive is one you&#8217;ll want to change. Once you&#8217;re editing the /etc/ssh/sshd_config file, you&#8217;ll want to change the following directive as follows:</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;"><strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">PermitRootLogin no</strong></p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">This will keep anyone from attempting to log into your server via SSH as root. It&#8217;s generally a good idea not to allow any to log into your SSH server as root. If an attacker manages to hack into your SSH server with the root login, he will have complete control over your machine, and that is definitely not a good thing.</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">Another directive you might want to change is the &#8220;AllowUsers.&#8221; When the AllowUsers directive is active, only users specifically specified in the directive can access the system through SSH. This adds an additional layer of protection to your SSH server by only allowing specific users to connect via SSH. For instance, if you wanted to limit SSH access to just the &#8220;camalas&#8221; user account, edit the AllowUsers directive like this:</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;"><strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">AllowUsers camalas</strong></p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">To add multiple users to the AllowUsers directive, just add them one by one without commas or semicolons. An AllowUsers directive that permits the camalas user account and the lmaraeus user account to log in would look like this:</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;"><strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">AllowUsers camalas lmaraeus</strong></p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">You may also want to consider changing the Port directive. By default SSH runs over TCP/IP port 22, which means that any malware bot autoscanning port 22 can target it. If you set up your user accounts with a weak password (always a bad idea), eventually an automated bot might break through and guess the password. Changing the Port directive to something different will make SSH run over a different port, blocking some of those automated cracking attempts. To set SSH to run over port 5699 instead, make sure your Port directive looks like this:</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;"><strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">Port 5699</strong></p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">Note that if you change your SSH server&#8217;s default port, you&#8217;ll need to remember the new port number when using an SSH client, which we&#8217;ll cover in the next section.</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">After you&#8217;ve finished changing the directives in /etc/ssh/sshd_config, switch vi to command mode, and save and quit vi. After you return to the command line, restart the SSH daemon with this command:</p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;"><strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">sudo restart ssh</strong></p><p style="background-color: #ffffff; border: 0px; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px;">You should now be able to SSH into your Ubuntu 12.04 Precise Pangolin machine from another system with an SSH client.</p><img src ="http://www.blogjava.net/czihong/aggbug/395640.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2013-02-24 01:18 <a href="http://www.blogjava.net/czihong/articles/395640.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu</title><link>http://www.blogjava.net/czihong/articles/395629.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Sat, 23 Feb 2013 05:27:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/395629.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/395629.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/395629.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/395629.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/395629.html</trackback:ping><description><![CDATA[<h3>About LAMP</h3><hr style="margin: 5px 0px; border-right-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: #eeeeee; border-bottom-style: solid; border-bottom-color: #ffffff; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the virtual private server is already running Ubuntu, the linux part is taken care of. Here is how to install the rest.</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><h2>Set Up</h2><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">The steps in this tutorial require the user to have root privileges on your VPS. You can see how to set that up in the&nbsp;</span><a href="https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-12-04" style="color: #0088cc; text-decoration: none; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;">Initial Server Setup</a><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">&nbsp;in steps 3 and 4.&nbsp;</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><h2>Step One&#8212;Install Apache</h2><hr style="margin: 5px 0px; border-right-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: #eeeeee; border-bottom-style: solid; border-bottom-color: #ffffff; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Apache is a free open source software which runs over 50% of the world&#8217;s web servers.</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">To install apache, open terminal and type in these commands:</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">sudo apt-get update <br />sudo apt-get install apache2</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">That&#8217;s it. To check if Apache is installed, direct your browser to your server&#8217;s IP address (eg. http://12.34.56.789). The page should display the words &#8220;It works!" like</span><a href="http://i.imgur.com/333VJ.png" style="color: #0088cc; text-decoration: none; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;">this</a><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">.</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><h2>How to Find your Server&#8217;s IP address</h2><hr style="margin: 5px 0px; border-right-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: #eeeeee; border-bottom-style: solid; border-bottom-color: #ffffff; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">You can run the following command to reveal your server&#8217;s IP address.</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">ifconfig eth0 | grep inet | awk '{ print $2 }'</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><h2>Step Two&#8212;Install MySQL</h2><hr style="margin: 5px 0px; border-right-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: #eeeeee; border-bottom-style: solid; border-bottom-color: #ffffff; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">MySQL is a powerful database management system used for organizing and retrieving data&nbsp;</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">To install MySQL, open terminal and type in these commands:</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">During the installation, MySQL will ask you to set a root password. If you miss the chance to set the password while the program is installing, it is very easy to set the password later from within the MySQL shell.</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Once you have installed MySQL, we should activate it with this command:</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">sudo mysql_install_db</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Finish up by running the MySQL set up script:</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">sudo /usr/bin/mysql_secure_installation</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">The prompt will ask you for your current root password.&nbsp;</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Type it in.</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">Enter current password for root (enter for none):  <br />OK, successfully used password, moving on...</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Then the prompt will ask you if you want to change the root password. Go ahead and choose N and move on to the next steps.&nbsp;</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">It&#8217;s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL <br />without having to have a user account created for them.  This is intended only for testing, <br />and to make the installation go a bit smoother.  You should remove them before moving into<br /> a production environment.  <br />Remove anonymous users? [Y/n] y                                              <br />... Success!  <br /><br />Normally, root should only be allowed to connect from 'localhost'.  This ensures that someone<br /> cannot guess at the root password from the network.  <br />Disallow root login remotely? [Y/n] y <br />... Success!  <br /><br />By default, MySQL comes with a database named 'test' that anyone can access.  This is also <br />intended only for testing, and should be removed before moving into a production environment.  <br />Remove test database and access to it? [Y/n] y  <br />- Dropping test database...  <br />... Success!  <br />- Removing privileges on test database...  <br />... Success!  <br /><br />Reloading the privilege tables will ensure that all changes made so far will take effect <br />immediately.  <br />Reload privilege tables now? [Y/n] y  <br />... Success!  <br />Cleaning up...</pre><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Once you're done with that you can finish up by installing PHP.</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><h2>Step Three&#8212;Install PHP</h2><hr style="margin: 5px 0px; border-right-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: #eeeeee; border-bottom-style: solid; border-bottom-color: #ffffff; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">PHP is an open source web scripting language that is widely use to build dynamic webpages.&nbsp;</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">To install PHP, open terminal and type in this command.</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">After you answer yes to the prompt twice, PHP will install itself.</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">It may also be useful to add php to the directory index, to serve the relevant php index files:</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">sudo nano /etc/apache2/mods-enabled/dir.conf</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Add index.php to the beginning of index files. The page should now look like this:</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">&lt;IfModule mod_dir.c&gt;            <br />&nbsp;&nbsp;&nbsp;&nbsp;DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm  <br />&lt;/IfModule&gt;</pre><h2>PHP Modules</h2><hr style="margin: 5px 0px; border-right-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: #eeeeee; border-bottom-style: solid; border-bottom-color: #ffffff; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">PHP also has a variety of useful libraries and modules that you can add onto your virtual server. You can see the libraries that are available.</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">apt-cache search php5-</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Terminal will then display the list of possible modules. The beginning looks like this:</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">php5-cgi - server-side, HTML-embedded scripting language (CGI binary) <br />php5-cli - command-line interpreter for the <br />php5 scripting language <br />php5-common - Common files for packages built from the <br /></pre><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Once you decide to install the module, type:</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">sudo apt-get install <em>name of the module</em></pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">You can install multiple libraries at once by separating the name of each module with a space.&nbsp;</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Congratulations! You now have LAMP stack on your droplet!</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><h2>Step Four&#8212;RESULTS: See PHP on your Server</h2><hr style="margin: 5px 0px; border-right-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: #eeeeee; border-bottom-style: solid; border-bottom-color: #ffffff; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Although LAMP is installed, we can still take a look and see the components online by creating a quick php info page</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">To set this up, first create a new file:</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">sudo nano /var/www/info.php</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Add in the following line:</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">&lt;?php phpinfo(); ?&gt;</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Then Save and Exit.&nbsp;</span><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Restart apache so that all of the changes take effect:</span><pre style="padding: 10px; font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12.025px; color: #ffffff; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; margin-top: 10px; margin-bottom: 10px; line-height: 18px; background-color: #666666; border: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">sudo service apache2 restart</pre><br style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;" /><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">Finish up by visiting your php info page (make sure you replace the example ip&nbsp;<br /><br /><br /></span><h2 style="margin: 30px 0px 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 500; color: #111111; text-rendering: optimizelegibility; font-size: 24px; line-height: 36px;">See More</h2><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">After installing LAMP, you can&nbsp;</span><a href="https://www.digitalocean.com/community/articles/how-to-install-and-secure-phpmyadmin-on-ubuntu-12-04" style="color: #0088cc; text-decoration: none; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;">Set Up phpMyAdmin</a><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">,&nbsp;</span><a href="https://www.digitalocean.com/community/articles/how-to-install-wordpress-on-ubuntu-12-04" style="color: #0088cc; text-decoration: none; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;">Install WordPress</a><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">, go on to do more with MySQL (</span><a href="https://www.digitalocean.com/community/articles/a-basic-mysql-tutorial" style="color: #0088cc; text-decoration: none; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;">A Basic MySQL Tutorial</a><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">),&nbsp;</span><a href="https://www.digitalocean.com/community/articles/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-12-04" style="color: #0088cc; text-decoration: none; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;">Create an SSL Certificate</a><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">, or&nbsp;</span><a href="https://www.digitalocean.com/community/articles/how-to-set-up-vsftpd-on-ubuntu-12-04" style="color: #0088cc; text-decoration: none; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px;">Install an FTP Server</a><span style="color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 17px; line-height: 23px; background-color: #ffffff;">.&nbsp;</span><img src ="http://www.blogjava.net/czihong/aggbug/395629.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2013-02-23 13:27 <a href="http://www.blogjava.net/czihong/articles/395629.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Split Large File in Linux</title><link>http://www.blogjava.net/czihong/articles/390001.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Mon, 22 Oct 2012 06:03:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/390001.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/390001.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/390001.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/390001.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/390001.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: 'Lucida Grande', Verdana, Arial, sans-serif; font-size: 12px; line-height: 25px; text-align: justify; background-color: #ffffff; ">Have you ever want to split a large file&nbsp;into several small files? I&#8217;ve face this problem few days ago. I need to split a large file (4.4GB log file) into several smaller file where i can read it using normal text editor (vim etc.).</p><p style="color: #333333; font-family: 'Lucida Grande', Verdana, Arial, sans-serif; font-size: 12px; line-height: 25px; text-align: justify; background-color: #ffffff; ">To split large file into several smaller files, you can use&nbsp;<strong>split</strong>&nbsp;command in Linux. Just follow the steps below and you will be able to split large file into smaller files.&nbsp;<br /><br /><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: #800080; ">$split</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">b&nbsp;100m&nbsp;</span><span style="color: #000000; ">/</span><span style="color: #000000; ">path</span><span style="color: #000000; ">/</span><span style="color: #000000; ">to</span><span style="color: #000000; ">/</span><span style="color: #000000; ">large</span><span style="color: #000000; ">/</span><span style="color: #000000; ">file&nbsp;</span><span style="color: #000000; ">/</span><span style="color: #000000; ">path</span><span style="color: #000000; ">/</span><span style="color: #000000; ">to</span><span style="color: #000000; ">/</span><span style="color: #000000; ">output</span><span style="color: #000000; ">/</span><span style="color: #000000; ">file</span><span style="color: #000000; ">/</span><span style="color: #000000; ">prefix</span></div></p><ul style="margin-left: 0px; padding: 0px 0px 0px 10px; list-style: none; text-indent: -10px; color: #333333; font-family: 'Lucida Grande', Verdana, Arial, sans-serif; font-size: 12px; line-height: 25px; text-align: justify; background-color: #ffffff; "><li style="margin: 7px 0px 8px 10px; ">Done. You just split your large file into several smaller files</li></ul><p style="color: #333333; font-family: 'Lucida Grande', Verdana, Arial, sans-serif; font-size: 12px; line-height: 25px; text-align: justify; background-color: #ffffff; ">* You can change the output file size by changing the&nbsp;<strong>&#8211;bytes=1m</strong>&nbsp;to your preference. You can use b, k, or m. b represent bytes, k represent kilobytes, m represent megabytes.</p><p style="color: #333333; font-family: 'Lucida Grande', Verdana, Arial, sans-serif; font-size: 12px; line-height: 25px; text-align: justify; background-color: #ffffff; ">To restore the original file, you can use&nbsp;<strong>cat</strong>&nbsp;command.<br />To join all the smaller file to restore the original file type:-<br /><br /><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; ">$cat&nbsp;prefix</span><span style="color: #000000; ">*</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">&nbsp;new</span><span style="color: #000000; ">/</span><span style="color: #000000; ">file</span><span style="color: #000000; ">/</span><span style="color: #000000; ">name</span></div></p><img src ="http://www.blogjava.net/czihong/aggbug/390001.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-10-22 14:03 <a href="http://www.blogjava.net/czihong/articles/390001.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux Increase The Maximum Number Of Open Files / File Descriptors </title><link>http://www.blogjava.net/czihong/articles/385929.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Tue, 21 Aug 2012 04:51:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/385929.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/385929.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/385929.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/385929.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/385929.html</trackback:ping><description><![CDATA[<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 1.571em; margin-left: 0px; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">The ulimit command provides control over the resources available to the shell and/or to processes started by it, on systems that allow such control. The maximum number of open file descriptors displayed with following command (login as the root user).</p><h2>Command To List Number Of Open File Descriptors</h2><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 1.571em; margin-left: 0px; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">Use the following command command to display maximum number of open file descriptors:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">cat /proc/sys/fs/file-max</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />Output:</p><pre style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-bottom: 1.833em; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; overflow-x: auto; overflow-y: auto; clear: both; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; line-height: 1.5em; color: #111111; ">75000</pre><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 1.571em; margin-left: 0px; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">75000 files normal user can have open in single login session. To see the hard and soft values, issue the command as follows:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># ulimit -Hn<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /># ulimit -Sn</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />To see the hard and soft values for httpd or oracle user, issue the command as follows:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># su - username</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />In this example, su to oracle user, enter:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># su - oracle<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />$ ulimit -Hn<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />$ ulimit -Sn</code></p><h2>System-wide File Descriptors (FD) Limits</h2><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 1.571em; margin-left: 0px; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">The number of concurrently open file descriptors throughout the system can be changed via /etc/sysctl.conf file under Linux operating systems.</p><h3>The Number Of Maximum Files Was Reached, How Do I Fix This Problem?</h3><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 1.571em; margin-left: 0px; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">Many application such as Oracle database or Apache web server needs this range quite higher. So you can increase the maximum number of open files by setting a new value in kernel variable /proc/sys/fs/file-max as follows (login as the root):<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># sysctl -w fs.file-max=100000</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />Above command forces the limit to 100000 files. You need to edit /etc/sysctl.conf file and put following line so that after reboot the setting will remain as it is:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># vi /etc/sysctl.conf</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />Append a config directive as follows:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">fs.file-max = 100000</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />Save and close the file. Users need to log out and log back in again to changes take effect or just type the following command:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># sysctl -p</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />Verify your settings with command:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># cat /proc/sys/fs/file-max</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />OR<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># sysctl fs.file-max</code></p><h2>User Level FD Limits</h2><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 1.571em; margin-left: 0px; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">The above procedure sets system-wide file descriptors (FD) limits. However, you can limit httpd (or any other users) user to specific limits by editing /etc/security/limits.conf file, enter:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># vi /etc/security/limits.conf</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />Set httpd user soft and hard limits as follows:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">httpd soft nofile 4096<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />httpd hard nofile 10240</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />Save and close the file. To see limits, enter:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-image: initial; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># su - httpd<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />$ ulimit -Hn<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />$ ulimit -Sn</code></p><img src ="http://www.blogjava.net/czihong/aggbug/385929.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-08-21 12:51 <a href="http://www.blogjava.net/czihong/articles/385929.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>A tips to remove cache</title><link>http://www.blogjava.net/czihong/articles/381053.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Mon, 18 Jun 2012 18:27:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/381053.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/381053.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/381053.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/381053.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/381053.html</trackback:ping><description><![CDATA[mv /itemcache/catalog /itemcache/catalog.old<br />rm -rf /itemcache/catalog.old<br /><br />do not&nbsp;<br />rm -rf&nbsp;/itemcache/catalog<br /><br />Reason: user may hit the url, and generate cache under that directory, if rm directly, it may impact the users.<img src ="http://www.blogjava.net/czihong/aggbug/381053.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-06-19 02:27 <a href="http://www.blogjava.net/czihong/articles/381053.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>xargs: How To Control and Use Command Line Arguments</title><link>http://www.blogjava.net/czihong/articles/381050.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Mon, 18 Jun 2012 18:08:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/381050.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/381050.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/381050.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/381050.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/381050.html</trackback:ping><description><![CDATA[<p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">am trying to use xargs command using shell pipes and not able to understand how to control and use command line arguments. For example I'd like to find out all *.c file located in 100s of sub-directories and move them to another directory called ~/old.src. How do I use command line args with xargs to achieve the same?<br style="padding: 0px; margin: 0px; " /><br style="padding: 0px; margin: 0px; " />xargs command is designed to construct argument lists and invoke other utility. xargs reads items from the standard input or pipes, delimited by blanks or newlines, and executes the command one or more times with any initial-arguments followed by items read from standard input. Blank lines on the standard input are ignored.</p><h2>xargs is more&nbsp;<span style="padding: 0px; margin: 0px; color: #6666cc; ">safer and easy</span>&nbsp;to use</h2><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">xargs functionality can be achived using the backquote feature of shell. But, it offers more options. It can deal with blanks or special characters in file names easily. It is often used with find, grep and other commands.</p><h2>xargs examples</h2><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">For example following example will print 1 2 3 4 using xargs (echo command is default)<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ echo 1 2 3 4 | xargs echo</code><br style="padding: 0px; margin: 0px; " />OR<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ echo 1 2 3 4 | xargs</code><br style="padding: 0px; margin: 0px; " />You can force xargs to use at most max-args arguments per command line. For example following will use first two argument per command:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ echo 1 2 3 4 | xargs -n 2</code><br style="padding: 0px; margin: 0px; " />Find all .bak files in or below the current directory and delete them.<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ find . -name "*.bak" -type f -print | xargs /bin/rm -f</code></p><h2><span style="padding: 0px; margin: 0px; color: #993399; ">{} as the argument list marker</span></h2><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">{} is the default argument list marker. You need to use {} this with various command which take more than two arguments at a time. For example mv command need to know the file name. The following will find all .bak files in or below the current directory and move them to ~/.old.files directory:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ find . -name "*.bak" -print0 | xargs -0 -I {} mv {} ~/old.files</code><br style="padding: 0px; margin: 0px; " />You can rename {} to something else. In the following example {} is renamed as file. This is more readable as compare to previous example:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ find . -name "*.bak" -print0 | xargs -0 -I file mv file ~/old.files</code><br style="padding: 0px; margin: 0px; " />Where,</p><ol style="padding: 0px; margin: 0px 0px 1.571em 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; "><li style="padding: 0px; margin: 0px; "><strong style="padding: 0px; margin: 0px; ">-0</strong>&nbsp;If there are blank spaces or characters (including newlines) many commands will not work. This option take cares of file names with blank space.</li><li style="padding: 0px; margin: 0px; "><strong style="padding: 0px; margin: 0px; ">-I&nbsp;</strong>Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character.</li></ol><h3>Dealing&nbsp;<span style="padding: 0px; margin: 0px; color: #009900; ">file names with blank spaces and newline</span></h3><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">The following will work incorrectly if there are any filenames containing newlines or spaces (it will find out all .mp3 file located in current directory and play them using mplayer):<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ find . -iname "*.mp3" -print | xargs mplayer</code><br style="padding: 0px; margin: 0px; " />To get rid of this problem use -0 option:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ find . -iname "*.mp3" -print0 | xargs -0 -I mp3file mplayer mp3file</code><br style="padding: 0px; margin: 0px; " />To find out all *.c file located in 100s of subdirectories and move them to another directory called ~/old.src, use:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ find /path/to/dir -iname "*.c" -print0 | xargs -0 -I file mv file ~/old.src</code></p><h2>Avoiding&nbsp;<span style="padding: 0px; margin: 0px; color: #ff0000; ">errors and resource hungry problems</span>&nbsp;with xargs and find combo</h2><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">To copy all media files to another location called /bakup/iscsi, you can use cp as follows:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ cp -r -v -p /share/media/mp3/ /backup/iscsi/mp3</code><br style="padding: 0px; margin: 0px; " />However, cp command may fail if an error occurs such as if the number of files is too large for the cp command to handle. xargs in combination with find can handle such operation nicely. xargs is more resource efficient and will not halt with an error:</p><pre style="padding: 0.667em 0.917em; margin-top: 0px; margin-bottom: 1.833em; background-color: #eeeeee; border: 1px solid #dddddd; overflow: auto; clear: both; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; line-height: 1.5em; color: #111111; ">$ <span style="padding: 0px; margin: 0px; color: #c20cb9; font-weight: bold; ">find</span> /share/media/mp3/ -<span style="padding: 0px; margin: 0px; color: #7a0874; font-weight: bold; ">type</span> f -name <span style="padding: 0px; margin: 0px; color: #ff0000; ">"*.mp3"</span> -print0 | <span style="padding: 0px; margin: 0px; color: #c20cb9; font-weight: bold; ">xargs</span> <span style="padding: 0px; margin: 0px; color: #000000; ">-0</span> -r -I <span style="padding: 0px; margin: 0px; color: #c20cb9; font-weight: bold; ">file</span> <span style="padding: 0px; margin: 0px; color: #c20cb9; font-weight: bold; ">cp</span> -v -p <span style="padding: 0px; margin: 0px; color: #c20cb9; font-weight: bold; ">file</span> --target-<span style="padding: 0px; margin: 0px; color: #007800; ">directory=</span>/bakup/iscsi/mp3</pre><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">Please note that all of the above commands are tested with GNU/xargs version. BSD and UNIX xargs command may not have options such as -r. Please refer to your local xargs man page for further info:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">man xargs</code></p><img src ="http://www.blogjava.net/czihong/aggbug/381050.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-06-19 02:08 <a href="http://www.blogjava.net/czihong/articles/381050.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Understand sudo</title><link>http://www.blogjava.net/czihong/articles/380554.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Mon, 11 Jun 2012 18:04:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/380554.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/380554.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/380554.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/380554.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/380554.html</trackback:ping><description><![CDATA[<p style="margin: 0.4em 0px 0.5em; line-height: 19px; font-family: sans-serif; font-size: 13px; background-color: #ffffff; "><div><strong>sudo</strong> &nbsp;is a program for Unix-like computer operating systems that allows users to run programs with the security privileges of another user (normally</div><div>the superuser, or root). Its name is a concatenation of the sucommand (which grants the user a shell of another user, normally the superuser) and "do", or take action.</div><div>Unlike the su command, users typically supply their own password to sudo rather than the root password. After authentication, and if the /etc/sudoers configuration file</div><div>permits the user access, then the system will invoke the requested command.</div></p><p style="margin: 0.4em 0px 0.5em; line-height: 19px; font-family: sans-serif; font-size: 13px; background-color: #ffffff; "><br /><br /></p><div style="background-color: #eeeeee; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#<br />#&nbsp;Sample&nbsp;/etc/sudoers&nbsp;file.<br />#<br />#&nbsp;This&nbsp;file&nbsp;MUST&nbsp;be&nbsp;edited&nbsp;with&nbsp;the&nbsp;'visudo'&nbsp;command&nbsp;as&nbsp;root.<br />#<br />#&nbsp;See&nbsp;the&nbsp;sudoers&nbsp;man&nbsp;page&nbsp;<span style="color: #0000FF; ">for</span>&nbsp;the&nbsp;details&nbsp;on&nbsp;how&nbsp;to&nbsp;write&nbsp;a&nbsp;sudoers&nbsp;file.<br />#<br /><br />##<br />#&nbsp;User&nbsp;alias&nbsp;specification<br />##<br />User_Alias&nbsp;&nbsp;&nbsp;&nbsp;FULLTIMERS&nbsp;=&nbsp;millert,&nbsp;mikef,&nbsp;dowdy<br />User_Alias&nbsp;&nbsp;&nbsp;&nbsp;PARTTIMERS&nbsp;=&nbsp;bostley,&nbsp;jwfox,&nbsp;crawl<br />User_Alias&nbsp;&nbsp;&nbsp;&nbsp;WEBMASTERS&nbsp;=&nbsp;will,&nbsp;wendy,&nbsp;wim<br /><br />##<br />#&nbsp;Runas&nbsp;alias&nbsp;specification<br />##<br />Runas_Alias&nbsp;&nbsp;&nbsp;&nbsp;OP&nbsp;=&nbsp;root,&nbsp;operator<br />Runas_Alias&nbsp;&nbsp;&nbsp;&nbsp;DB&nbsp;=&nbsp;oracle,&nbsp;sybase<br /><br />##<br />#&nbsp;Host&nbsp;alias&nbsp;specification<br />##<br />Host_Alias&nbsp;&nbsp;&nbsp;&nbsp;SPARC&nbsp;=&nbsp;bigtime,&nbsp;eclipse,&nbsp;moet,&nbsp;anchor:\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SGI&nbsp;=&nbsp;grolsch,&nbsp;dandelion,&nbsp;black:\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ALPHA&nbsp;=&nbsp;widget,&nbsp;thalamus,&nbsp;foobar:\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HPPA&nbsp;=&nbsp;boa,&nbsp;nag,&nbsp;python<br />Host_Alias&nbsp;&nbsp;&nbsp;&nbsp;CUNETS&nbsp;=&nbsp;128.138.0.0/255.255.0.0<br />Host_Alias&nbsp;&nbsp;&nbsp;&nbsp;CSNETS&nbsp;=&nbsp;128.138.243.0,&nbsp;128.138.204.0/24,&nbsp;128.138.242.0<br />Host_Alias&nbsp;&nbsp;&nbsp;&nbsp;SERVERS&nbsp;=&nbsp;master,&nbsp;mail,&nbsp;www,&nbsp;ns<br />Host_Alias&nbsp;&nbsp;&nbsp;&nbsp;CDROM&nbsp;=&nbsp;orion,&nbsp;perseus,&nbsp;hercules<br /><br />##<br />#&nbsp;Cmnd&nbsp;alias&nbsp;specification<br />##<br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;DUMPS&nbsp;=&nbsp;/usr/sbin/dump,&nbsp;/usr/sbin/rdump,&nbsp;/usr/sbin/restore,&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/sbin/rrestore,&nbsp;/usr/bin/mt<br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;KILL&nbsp;=&nbsp;/usr/bin/kill<br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;PRINTING&nbsp;=&nbsp;/usr/sbin/lpc,&nbsp;/usr/bin/lprm<br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;SHUTDOWN&nbsp;=&nbsp;/usr/sbin/shutdown<br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;HALT&nbsp;=&nbsp;/usr/sbin/halt,&nbsp;/usr/sbin/fasthalt<br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;REBOOT&nbsp;=&nbsp;/usr/sbin/reboot,&nbsp;/usr/sbin/fastboot<br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;SHELLS&nbsp;=&nbsp;/usr/bin/sh,&nbsp;/usr/bin/csh,&nbsp;/usr/bin/ksh,&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/local/bin/tcsh,&nbsp;/usr/bin/rsh,&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/local/bin/zsh<br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;SU&nbsp;=&nbsp;/usr/bin/su<br />Cmnd_Alias&nbsp;&nbsp;&nbsp;&nbsp;VIPW&nbsp;=&nbsp;/usr/sbin/vipw,&nbsp;/usr/bin/passwd,&nbsp;/usr/bin/chsh,&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/bin/chfn<br /><br />##<br />#&nbsp;Override&nbsp;built-in&nbsp;defaults<br />##<br />Defaults&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;syslog=auth<br />Defaults:FULLTIMERS&nbsp;&nbsp;&nbsp;&nbsp;!lecture<br />Defaults:millert&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!authenticate<br />Defaults@SERVERS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log_year,&nbsp;logfile=/var/log/sudo.log<br /><br />##<br />#&nbsp;User&nbsp;specification<br />##<br /><br />#&nbsp;root&nbsp;and&nbsp;users&nbsp;in&nbsp;group&nbsp;wheel&nbsp;can&nbsp;run&nbsp;anything&nbsp;on&nbsp;any&nbsp;machine&nbsp;as&nbsp;any&nbsp;user<br />root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ALL&nbsp;=&nbsp;(ALL)&nbsp;ALL<br />%wheel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ALL&nbsp;=&nbsp;(ALL)&nbsp;ALL<br /><br />#&nbsp;full&nbsp;time&nbsp;sysadmins&nbsp;can&nbsp;run&nbsp;anything&nbsp;on&nbsp;any&nbsp;machine&nbsp;without&nbsp;a&nbsp;password<br />FULLTIMERS&nbsp;&nbsp;&nbsp;&nbsp;ALL&nbsp;=&nbsp;NOPASSWD:&nbsp;ALL<br /><br />#&nbsp;part&nbsp;time&nbsp;sysadmins&nbsp;may&nbsp;run&nbsp;anything&nbsp;but&nbsp;need&nbsp;a&nbsp;password<br />PARTTIMERS&nbsp;&nbsp;&nbsp;&nbsp;ALL&nbsp;=&nbsp;ALL<br /><br />#&nbsp;jack&nbsp;may&nbsp;run&nbsp;anything&nbsp;on&nbsp;machines&nbsp;in&nbsp;CSNETS<br />jack&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CSNETS&nbsp;=&nbsp;ALL<br /><br />#&nbsp;lisa&nbsp;may&nbsp;run&nbsp;any&nbsp;command&nbsp;on&nbsp;any&nbsp;host&nbsp;in&nbsp;CUNETS&nbsp;(a&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;B&nbsp;network)<br />lisa&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CUNETS&nbsp;=&nbsp;ALL<br /><br />#&nbsp;operator&nbsp;may&nbsp;run&nbsp;maintenance&nbsp;commands&nbsp;and&nbsp;anything&nbsp;in&nbsp;/usr/oper/bin/<br />operator&nbsp;&nbsp;&nbsp;&nbsp;ALL&nbsp;=&nbsp;DUMPS,&nbsp;KILL,&nbsp;PRINTING,&nbsp;SHUTDOWN,&nbsp;HALT,&nbsp;REBOOT,\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/oper/bin/<br /><br />#&nbsp;joe&nbsp;may&nbsp;su&nbsp;only&nbsp;to&nbsp;operator<br />joe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ALL&nbsp;=&nbsp;/usr/bin/su&nbsp;operator<br /><br />#&nbsp;pete&nbsp;may&nbsp;change&nbsp;passwords&nbsp;<span style="color: #0000FF; ">for</span>&nbsp;anyone&nbsp;but&nbsp;root&nbsp;on&nbsp;the&nbsp;hp&nbsp;snakes<br />pete&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HPPA&nbsp;=&nbsp;/usr/bin/passwd&nbsp;[A-z]*,&nbsp;!/usr/bin/passwd&nbsp;root<br /><br />#&nbsp;bob&nbsp;may&nbsp;run&nbsp;anything&nbsp;on&nbsp;the&nbsp;sparc&nbsp;and&nbsp;sgi&nbsp;machines&nbsp;as&nbsp;any&nbsp;user<br />#&nbsp;listed&nbsp;in&nbsp;the&nbsp;Runas_Alias&nbsp;"OP"&nbsp;(ie:&nbsp;root&nbsp;and&nbsp;operator)<br />bob&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SPARC&nbsp;=&nbsp;(OP)&nbsp;ALL&nbsp;:&nbsp;SGI&nbsp;=&nbsp;(OP)&nbsp;ALL<br /><br />#&nbsp;jim&nbsp;may&nbsp;run&nbsp;anything&nbsp;on&nbsp;machines&nbsp;in&nbsp;the&nbsp;biglab&nbsp;netgroup<br />jim&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+biglab&nbsp;=&nbsp;ALL<br /><br />#&nbsp;users&nbsp;in&nbsp;the&nbsp;secretaries&nbsp;netgroup&nbsp;need&nbsp;to&nbsp;help&nbsp;manage&nbsp;the&nbsp;printers<br />#&nbsp;as&nbsp;well&nbsp;as&nbsp;add&nbsp;and&nbsp;remove&nbsp;users<br />+secretaries&nbsp;&nbsp;&nbsp;&nbsp;ALL&nbsp;=&nbsp;PRINTING,&nbsp;/usr/bin/adduser,&nbsp;/usr/bin/rmuser<br /><br />#&nbsp;fred&nbsp;can&nbsp;run&nbsp;commands&nbsp;as&nbsp;oracle&nbsp;or&nbsp;sybase&nbsp;without&nbsp;a&nbsp;password<br />fred&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ALL&nbsp;=&nbsp;(DB)&nbsp;NOPASSWD:&nbsp;ALL<br /><br />#&nbsp;on&nbsp;the&nbsp;alphas,&nbsp;john&nbsp;may&nbsp;su&nbsp;to&nbsp;anyone&nbsp;but&nbsp;root&nbsp;and&nbsp;flags&nbsp;are&nbsp;not&nbsp;allowed<br />john&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ALPHA&nbsp;=&nbsp;/usr/bin/su&nbsp;[!-]*,&nbsp;!/usr/bin/su&nbsp;*root*<br /><br />#&nbsp;jen&nbsp;can&nbsp;run&nbsp;anything&nbsp;on&nbsp;all&nbsp;machines&nbsp;except&nbsp;the&nbsp;ones<br />#&nbsp;in&nbsp;the&nbsp;"SERVERS"&nbsp;Host_Alias<br />jen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ALL,&nbsp;!SERVERS&nbsp;=&nbsp;ALL<br /><br />#&nbsp;jill&nbsp;can&nbsp;run&nbsp;any&nbsp;commands&nbsp;in&nbsp;the&nbsp;directory&nbsp;/usr/bin/,&nbsp;except&nbsp;<span style="color: #0000FF; ">for</span><br />#&nbsp;those&nbsp;in&nbsp;the&nbsp;SU&nbsp;and&nbsp;SHELLS&nbsp;aliases.<br />jill&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SERVERS&nbsp;=&nbsp;/usr/bin/,&nbsp;!SU,&nbsp;!SHELLS<br /><br />#&nbsp;steve&nbsp;can&nbsp;run&nbsp;any&nbsp;command&nbsp;in&nbsp;the&nbsp;directory&nbsp;/usr/local/op_commands/<br />#&nbsp;as&nbsp;user&nbsp;operator.<br />steve&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CSNETS&nbsp;=&nbsp;(operator)&nbsp;/usr/local/op_commands/<br /><br />#&nbsp;matt&nbsp;needs&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;kill&nbsp;things&nbsp;on&nbsp;his&nbsp;workstation&nbsp;when<br />#&nbsp;they&nbsp;get&nbsp;hung.<br />matt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;valkyrie&nbsp;=&nbsp;KILL<br /><br />#&nbsp;users&nbsp;in&nbsp;the&nbsp;WEBMASTERS&nbsp;User_Alias&nbsp;(will,&nbsp;wendy,&nbsp;and&nbsp;wim)<br />#&nbsp;may&nbsp;run&nbsp;any&nbsp;command&nbsp;as&nbsp;user&nbsp;www&nbsp;(which&nbsp;owns&nbsp;the&nbsp;web&nbsp;pages)<br />#&nbsp;or&nbsp;simply&nbsp;su&nbsp;to&nbsp;www.<br />WEBMASTERS&nbsp;&nbsp;&nbsp;&nbsp;www&nbsp;=&nbsp;(www)&nbsp;ALL,&nbsp;(root)&nbsp;/usr/bin/su&nbsp;www<br /><br />#&nbsp;anyone&nbsp;can&nbsp;mount/unmount&nbsp;a&nbsp;cd-rom&nbsp;on&nbsp;the&nbsp;machines&nbsp;in&nbsp;the&nbsp;CDROM&nbsp;alias<br />ALL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CDROM&nbsp;=&nbsp;NOPASSWD:&nbsp;/sbin/umount&nbsp;/CDROM,\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/sbin/mount&nbsp;-o&nbsp;nosuid\,nodev&nbsp;/dev/cd0a&nbsp;/CDROM</div><p>&nbsp;</p><img src ="http://www.blogjava.net/czihong/aggbug/380554.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-06-12 02:04 <a href="http://www.blogjava.net/czihong/articles/380554.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>symbolic and hard link</title><link>http://www.blogjava.net/czihong/articles/378891.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Tue, 22 May 2012 20:31:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/378891.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/378891.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/378891.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/378891.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/378891.html</trackback:ping><description><![CDATA[<p style="padding: 0px; margin: 0px 0px 1.571em; background-color: #ffffff;"><strong style="padding: 0px; margin: 0px;"><span style="padding: 0px; margin: 0px;"><div><span style="line-height: 22px;">What is the difference between symbolic link and hard link? Explaining the difference between a symbolic link or a symlink and a hard link is easy and vital to knowing about how Linux/Unix environments work.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Understanding the difference between a symbolic link and a hard link is also important for web server maintenance and understanding how modern websites work.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">What is symbolic link or symlink?</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Symbolic link, often called symlink or softlink, is very similar to what we know from Windows - a shortcut. They are kind of shortcuts in the Linux/Unix world. Well, symbolic link can exist in the Windows world too, but for the simplicity of our explanation, let's just work with the comparison that symlink is kind of a shortcut for now. We will get into more details later. Symbolic link contains information about the destination of the target file.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">What is hard link?</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Hard link (often also called hardlink) is a bit different object when compared to a symlink. Hard link is a directory reference or pointer to a file. Hardlink is a label stored in a directory structure that refers the operating system to the file data when it is accessed. The important part is that hard link is closely tied together with its originating file. If you make changes to a hard link, you automatically make changes to the underlying file that the hardlink is attached to.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Hard link can only refer to data that exists on the same file system.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Many of us are used to Windows where files live in folders. Files in Linux/Unix are not stored in directories. Files in Linux are assigned an inode number which Linux uses to locate files. Each file can have multiple hard links which are located in various directories. A file does not get deleted until there are no remaining hard links to it.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Differences between symbolic link and hard link</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Let's summarize our findings. The list bellow summarizes some differences between symlink and hard link:</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Hardlink or hardlinks cannot be created for directories (folders). Hard link can only be created for a file.</span></div><div><span style="line-height: 22px;">Symbolic links or symlinks can link to a directory (folder).</span></div><div><span style="line-height: 22px;">Removing the original file that your hard link points to does not remove the hardlink itself; the hardlink still provides the content of the underlying file.</span></div><div><span style="line-height: 22px;">If you remove the hard link or the symlink itself, the original file will stay intact.</span></div><div><span style="line-height: 22px;">Removing the original file does not remove the attached symbolic link or symlink, but without the original file, the symlink is useless (the same concept like Windows shortcut).</span></div><div><span style="line-height: 22px;">In case you are interested getting to know even more details, this list is expanded more on the the Mklink page. The concept is simply that hard links are tied to their sources more rigidly.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">What is the difference between symlink and shortcut?</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">We mentioned that symlinks are like shortcuts. They are like shortcuts but with some small differences.Symbolic links are automatically resolved by the file system. Any software programs, upon accessing a symbolic link, will see the target instead, whether the program is aware of symbolic links or not. On the other hand,shortcuts are treated like ordinary files by the files system and by software programs that are not aware of them. Only software programs that understand shortcuts (such as Windows) treat shortcuts as references to other files. Shortcuts can point to files or directories that exist in another file system or on the network. The difference between symbolic link and shortcut is clearer from the example mentioned at the bottom of this article, respectively as shown in the big print screen on the Mklink page.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">How to create a hard link or hardlink?</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">In Linux, you would use the ln command to create a hard link.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">$ ln fileA fileB</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">where fileA is the original file and fileB is the name you want to give to the hardlink. Let's do some research now. You have the original file and one hard link that is attached to it. Now, you look at these two objects with the ls command:</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">$ ls -il fileA fileB</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">You can see in the output of this command that both files fileA and fileB have the same inode number (the first number on the line). In addition to having the same inode, both files have the same file permissions and the same size. Because that size is reported for the same inode, we can see that a hard link does not occupy any extra space on your space.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">If you now remove the original file and open the hard link, you will still be able to see the content of the original file.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Note, hard link cannot be created to a folder. If you try creating a hard link to a folder, you will get "Access denied."</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">How to create a symlink?</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Let's demonstrate this with an example. When talking about Linux, you would use the ln command with the -sparameter. You would do something like:</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">$ ln -s fileA fileB</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">where fileA is the original file and fileB is the name you want to give to the symbolic link. Now, let's take a look at these two objects with the ls command again:</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">$ ls -il fileA fileB</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">You can see that you get different result as compared to when we displayed the hard link. The first difference between symlink and the original file is the inode number. The inode is different for the original file and for the symbolic link. Next, you can also notice that there is the pipe symbol "l" before the permissions on the symlink line. Also, the symbolic link has different permissions than the original file (because it is just a symbolic link). The content of the symlink is just a string pointing to the original file. The size of the symlink is not the same as the size of the original file. The symbolic link is a separate entity and as such occupies some space on your hard drive. You can see at the end of the line where the symlink points to.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">You can access the content of the original file directly by calling the original file or by calling the symbolic link. You will see the same result.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Now if you remove the original file, the symlink will still be there. If you try to access the content of the original file through the symbolic link after removing the original file, you will get a message saying there is no such file or directory.</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Can I make a symlink to a hard link?</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">Yes. The hard link functions the same way like the original file; therefore, you can make symlinks to it. You would use in our example the following command:</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">$ ln -s fileB fileC</span></div><div><span style="line-height: 22px;"><br /></span></div><div><span style="line-height: 22px;">where fileB would be the name of the hard link, and fileC would be the name of your new symlink.<br /><br /></span></div><div style="color: #ff0000; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px;"></div><font color="#ff0000" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="line-height: 22px;">
Q</span></font></span><font color="#111111" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="line-height: 22px;">.&nbsp;</span></font></strong><font color="#111111" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="line-height: 22px;">How do I display file inode number using command line?</span></font></p>
<p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; "><strong style="padding: 0px; margin: 0px; "><span style="padding: 0px; margin: 0px; color: #009900; ">A</span>.&nbsp;</strong>An&nbsp;<a href="http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem-inodes.html" style="padding: 0px; margin: 0px; color: #2361a1; ">inode is a data structure</a>&nbsp;on a Unix / Linux file system. An inode stores basic information about a regular file, directory, or other file system object. You can use following two commands to display an inode:<br style="padding: 0px; margin: 0px; " />
[a]&nbsp;<strong style="padding: 0px; margin: 0px; "><a href="http://www.cyberciti.biz/faq/ls-command-to-examining-the-filesystem/" style="padding: 0px; margin: 0px; color: #2361a1; ">ls command</a></strong>&nbsp;: list directory contents</p>
<p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">[b]&nbsp;<strong style="padding: 0px; margin: 0px; "><a href="http://www.cyberciti.biz/tips/display-file-or-file-system-status.html" style="padding: 0px; margin: 0px; color: #2361a1; ">stat command</a></strong>&nbsp;: display file or file system status</p>
<h2>ls command</h2>
<p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">Type ls command with -i ( print the index number of each file ) option:<br style="padding: 0px; margin: 0px; " />
<code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ ls -i /etc/passwd</code><br style="padding: 0px; margin: 0px; " />
Output:</p>
<pre style="padding: 0.667em 0.917em; margin-top: 0px; margin-bottom: 1.833em; background-color: #eeeeee; border: 1px solid #dddddd; overflow: auto; clear: both; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; line-height: 1.5em; color: #111111; ">752010 /etc/passwd</pre>
<p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">752010 is index number (inode) for /etc/passwd file.</p>
<h2>stat command</h2>
<p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; "><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ stat /etc/passwd</code><br style="padding: 0px; margin: 0px; " />
Output:</p>
<pre style="padding: 0.667em 0.917em; margin-top: 0px; margin-bottom: 1.833em; background-color: #eeeeee; border: 1px solid #dddddd; overflow: auto; clear: both; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; line-height: 1.5em; color: #111111; "> File: `/etc/passwd' Size: 2026 <br />
Blocks: 8 IO Block: 4096 regular file <br />
Device: 811h/2065d <span style="padding: 0px; margin: 0px; color: #ff0000; ">Inode: <strong style="padding: 0px; margin: 0px; ">752010</strong></span> <br />
Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) <br />
Access: 2007-08-20 23:19:20.000000000 +0530 <br />
Modify: 2007-07-07 00:06:56.000000000 +0530 <br />
Change: 2007-07-07 00:06:56.000000000 +0530</pre>
<p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">You can use inode number to&nbsp;<a href="http://www.cyberciti.biz/tips/delete-remove-files-with-inode-number.html" style="padding: 0px; margin: 0px; color: #2361a1; ">delete</a>&nbsp;or search a file.<br />
<br />
</p>
<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; ">Unix&nbsp;files&nbsp;consist&nbsp;of&nbsp;two&nbsp;parts</span><span style="color: #000000; ">:</span><span style="color: #000000; ">&nbsp;the&nbsp;data&nbsp;part&nbsp;and&nbsp;the&nbsp;filename&nbsp;part</span><span style="color: #000000; ">.</span><span style="color: #000000; "><br />
<br />
The&nbsp;data&nbsp;part&nbsp;is&nbsp;associated&nbsp;with&nbsp;something&nbsp;called&nbsp;an&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">inode</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">.</span><span style="color: #000000; ">&nbsp;The&nbsp;inode&nbsp;carries&nbsp;the&nbsp;</span><span style="color: #0000FF; ">map</span><span style="color: #000000; ">&nbsp;of&nbsp;where&nbsp;the&nbsp;data&nbsp;is</span><span style="color: #000000; ">,</span><span style="color: #000000; ">&nbsp;the&nbsp;file&nbsp;permissions</span><span style="color: #000000; ">,</span><span style="color: #000000; ">&nbsp;etc</span><span style="color: #000000; ">.</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">for</span><span style="color: #000000; ">&nbsp;the&nbsp;data</span><span style="color: #000000; ">.</span><span style="color: #000000; "><br />
<br />
<br />
&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;</span><span style="color: #000000; ">.---------------&gt;</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;data&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;data&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;etc<br />
&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;</span><span style="color: #000000; ">/</span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">+------+</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">!------+</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;permbits</span><span style="color: #000000; ">,</span><span style="color: #000000; ">&nbsp;etc&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;data&nbsp;addresses&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">+------------</span><span style="color: #000000; ">inode</span><span style="color: #000000; ">---------------+</span><span style="color: #000000; "><br />
<br />
The&nbsp;filename&nbsp;part&nbsp;carries&nbsp;a&nbsp;name&nbsp;and&nbsp;an&nbsp;associated&nbsp;inode&nbsp;number</span><span style="color: #000000; ">.</span><span style="color: #000000; "><br />
<br />
&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;</span><span style="color: #000000; ">.--------------&gt;</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;permbits</span><span style="color: #000000; ">,</span><span style="color: #000000; ">&nbsp;etc&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;addresses&nbsp;</span><span style="color: #000000; ">!</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;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">/</span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">+---------</span><span style="color: #000000; ">inode</span><span style="color: #000000; ">-------------+</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;filename&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;inode&nbsp;</span><span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;!</span><span style="color: #008000; "><br />
</span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">+--------------------+</span><span style="color: #000000; "><br />
More&nbsp;than&nbsp;one&nbsp;filename&nbsp;can&nbsp;reference&nbsp;the&nbsp;same&nbsp;inode&nbsp;number;&nbsp;these&nbsp;files&nbsp;are&nbsp;said&nbsp;to&nbsp;be&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">hard&nbsp;linked</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">&nbsp;together</span><span style="color: #000000; ">.</span><span style="color: #000000; "><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;filename&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;inode&nbsp;</span><span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;!</span><span style="color: #008000; "><br />
</span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">+--------------------+</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;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">\</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">&gt;--------------&gt;</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;permbits</span><span style="color: #000000; ">,</span><span style="color: #000000; ">&nbsp;etc&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;addresses&nbsp;</span><span style="color: #000000; ">!</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;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">/</span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">+---------</span><span style="color: #000000; ">inode</span><span style="color: #000000; ">-------------+</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;othername&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;inode&nbsp;</span><span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;!</span><span style="color: #008000; "><br />
</span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">+---------------------+</span><span style="color: #000000; "><br />
On&nbsp;the&nbsp;other&nbsp;hand</span><span style="color: #000000; ">,</span><span style="color: #000000; ">&nbsp;there</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">s&nbsp;a&nbsp;special&nbsp;file&nbsp;type&nbsp;whose&nbsp;data&nbsp;part&nbsp;carries&nbsp;a&nbsp;path&nbsp;to&nbsp;another&nbsp;file.&nbsp;Since&nbsp;it&nbsp;is&nbsp;a&nbsp;special&nbsp;file,&nbsp;the&nbsp;OS&nbsp;recognizes&nbsp;the&nbsp;data&nbsp;as&nbsp;a&nbsp;path,&nbsp;and&nbsp;redirects&nbsp;opens,&nbsp;reads,&nbsp;and&nbsp;writes&nbsp;so&nbsp;that,&nbsp;instead&nbsp;of&nbsp;accessing&nbsp;the&nbsp;data&nbsp;within&nbsp;the&nbsp;special&nbsp;file,&nbsp;they&nbsp;access&nbsp;the&nbsp;data&nbsp;in&nbsp;the&nbsp;file&nbsp;named&nbsp;by&nbsp;the&nbsp;data&nbsp;in&nbsp;the&nbsp;special&nbsp;file.&nbsp;This&nbsp;special&nbsp;file&nbsp;is&nbsp;called&nbsp;a&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">soft&nbsp;</span><span style="color: #0000FF; ">link</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">&nbsp;or&nbsp;a&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">symbolic&nbsp;</span><span style="color: #0000FF; ">link</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">&nbsp;(aka&nbsp;a&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #0000FF; ">symlink</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">).<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!&nbsp;filename&nbsp;!&nbsp;inode&nbsp;#&nbsp;!<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+--------------------+<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.-------&gt;&nbsp;!&nbsp;permbits,&nbsp;etc&nbsp;!&nbsp;addresses&nbsp;!<br />
&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;&nbsp;&nbsp;&nbsp;&nbsp;+---------inode-------------+<br />
&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<br />
&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<br />
&nbsp;&nbsp;&nbsp;&nbsp;.----------------------------------------------</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;(&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">--&gt;&nbsp;&nbsp;!"/path/to/some/other/file"!&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+---------data-------------+<br />
&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&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;&nbsp;&nbsp;}--&nbsp;(redirected&nbsp;at&nbsp;open()&nbsp;time)<br />
&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">~~&gt;</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;filename&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">&nbsp;inode&nbsp;</span><span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;!</span><span style="color: #008000; "><br />
</span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">+--------------------+</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">\</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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">------------&gt;&nbsp;!&nbsp;permbits,&nbsp;etc&nbsp;!&nbsp;addresses&nbsp;!<br />
&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+---------inode-------------+<br />
&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;&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;/<br />
&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;&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;/<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.----------------------------------------------------</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; "><br />
&nbsp;&nbsp;&nbsp;&nbsp;(<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">-&gt;&nbsp;&nbsp;!&nbsp;data&nbsp;!&nbsp;&nbsp;!&nbsp;data&nbsp;!&nbsp;etc.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+------+&nbsp;&nbsp;+------+&nbsp;<br />
<br />
Now,&nbsp;the&nbsp;filename&nbsp;part&nbsp;of&nbsp;the&nbsp;file&nbsp;is&nbsp;stored&nbsp;in&nbsp;a&nbsp;special&nbsp;file&nbsp;of&nbsp;its&nbsp;own&nbsp;along&nbsp;with&nbsp;the&nbsp;filename&nbsp;parts&nbsp;of&nbsp;other&nbsp;files;&nbsp;this&nbsp;special&nbsp;file&nbsp;is&nbsp;called&nbsp;a&nbsp;directory.&nbsp;The&nbsp;directory,&nbsp;as&nbsp;a&nbsp;file,&nbsp;is&nbsp;just&nbsp;an&nbsp;array&nbsp;of&nbsp;filename&nbsp;parts&nbsp;of&nbsp;other&nbsp;files.<br />
<br />
When&nbsp;a&nbsp;directory&nbsp;is&nbsp;built,&nbsp;it&nbsp;is&nbsp;initially&nbsp;populated&nbsp;with&nbsp;the&nbsp;filename&nbsp;parts&nbsp;of&nbsp;two&nbsp;special&nbsp;files:&nbsp;the&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">.</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">&nbsp;and&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">..</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">&nbsp;files.&nbsp;The&nbsp;filename&nbsp;part&nbsp;for&nbsp;the&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">.</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">&nbsp;file&nbsp;is&nbsp;populated&nbsp;with&nbsp;the&nbsp;inode#&nbsp;of&nbsp;the&nbsp;directory&nbsp;file&nbsp;in&nbsp;which&nbsp;the&nbsp;entry&nbsp;has&nbsp;been&nbsp;made;&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">.</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">&nbsp;is&nbsp;a&nbsp;hardlink&nbsp;to&nbsp;the&nbsp;file&nbsp;that&nbsp;implements&nbsp;the&nbsp;current&nbsp;directory.<br />
<br />
The&nbsp;filename&nbsp;part&nbsp;for&nbsp;the&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">..</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">&nbsp;file&nbsp;is&nbsp;populated&nbsp;with&nbsp;the&nbsp;inode#&nbsp;of&nbsp;the&nbsp;directory&nbsp;file&nbsp;that&nbsp;contains&nbsp;the&nbsp;filename&nbsp;part&nbsp;of&nbsp;the&nbsp;current&nbsp;directory&nbsp;file.&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">..</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">&nbsp;is&nbsp;a&nbsp;hardlink&nbsp;to&nbsp;the&nbsp;file&nbsp;that&nbsp;implements&nbsp;the&nbsp;immediate&nbsp;parent&nbsp;of&nbsp;the&nbsp;current&nbsp;directory.<br />
<br />
The&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">ln</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">&nbsp;command&nbsp;knows&nbsp;how&nbsp;to&nbsp;build&nbsp;hardlinks&nbsp;and&nbsp;softlinks;&nbsp;the&nbsp;</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #0000FF; ">mkdir</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; font-weight: bold; ">&nbsp;command&nbsp;knows&nbsp;how&nbsp;to&nbsp;build&nbsp;directories&nbsp;(the&nbsp;OS&nbsp;takes&nbsp;care&nbsp;of&nbsp;the&nbsp;above&nbsp;hardlinks).<br />
<br />
There&nbsp;are&nbsp;restrictions&nbsp;on&nbsp;what&nbsp;can&nbsp;be&nbsp;hardlinked&nbsp;(both&nbsp;links&nbsp;must&nbsp;reside&nbsp;on&nbsp;the&nbsp;same&nbsp;filesystem,&nbsp;the&nbsp;source&nbsp;file&nbsp;must&nbsp;exist,&nbsp;etc.)&nbsp;that&nbsp;are&nbsp;not&nbsp;applicable&nbsp;to&nbsp;softlinks&nbsp;(source&nbsp;and&nbsp;target&nbsp;can&nbsp;be&nbsp;on&nbsp;seperate&nbsp;file&nbsp;systems,&nbsp;source&nbsp;does&nbsp;not&nbsp;have&nbsp;to&nbsp;exist,&nbsp;etc.).&nbsp;OTOH,&nbsp;softlinks&nbsp;have&nbsp;other&nbsp;restrictions&nbsp;not&nbsp;shared&nbsp;by&nbsp;hardlinks&nbsp;(additional&nbsp;I/O&nbsp;necessary&nbsp;to&nbsp;complete&nbsp;file&nbsp;access,&nbsp;additional&nbsp;storage&nbsp;taken&nbsp;up&nbsp;by&nbsp;softlink&nbsp;file</span><span style="color: #000000; font-weight: bold; ">'</span><span style="color: #000000; ">s&nbsp;data</span><span style="color: #000000; ">,</span><span style="color: #000000; ">&nbsp;etc</span><span style="color: #000000; ">.</span><span style="color: #000000; ">)</span></div>
<p>&nbsp;</p><img src ="http://www.blogjava.net/czihong/aggbug/378891.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-05-23 04:31 <a href="http://www.blogjava.net/czihong/articles/378891.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Redirect stderr To stdout</title><link>http://www.blogjava.net/czihong/articles/378457.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Thu, 17 May 2012 23:40:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/378457.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/378457.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/378457.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/378457.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/378457.html</trackback:ping><description><![CDATA[<p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; "><span style="padding: 0px; margin: 0px; color: #ff0000; ">Q.</span>&nbsp;How do I redirect stderr to stdout? How do I redirect stderr to a file?<br style="padding: 0px; margin: 0px; " /><br style="padding: 0px; margin: 0px; " /><span style="padding: 0px; margin: 0px; color: #009900; ">A.</span>&nbsp;Bash and other modern shell provides I/O redirection facility. There are 3 default standard files (standard streams) open:<br style="padding: 0px; margin: 0px; " />[a]&nbsp;<strong style="padding: 0px; margin: 0px; ">stdin</strong>&nbsp;- Use to get input (keyboard) i.e. data going into a program.</p><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">[b]&nbsp;<strong style="padding: 0px; margin: 0px; ">stdout</strong>&nbsp;- Use to write information (screen)</p><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">[c]&nbsp;<strong style="padding: 0px; margin: 0px; ">stderr</strong>&nbsp;- Use to write error message (screen)</p><h2>Understanding I/O streams numbers</h2><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">The Unix / Linux standard I/O streams with numbers:</p><table border="1" style="padding: 0px; margin: 0px; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 14px; line-height: 22px; background-color: #ffffff; "><tbody style="padding: 0px; margin: 0px; "><tr style="padding: 0px; margin: 0px; "><td style="padding: 0px; margin: 0px; ">Handle</td><td style="padding: 0px; margin: 0px; ">Name</td><td style="padding: 0px; margin: 0px; ">Description</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 0px; margin: 0px; ">0</td><td style="padding: 0px; margin: 0px; ">stdin</td><td style="padding: 0px; margin: 0px; ">Standard input</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 0px; margin: 0px; ">1</td><td style="padding: 0px; margin: 0px; ">stdout</td><td style="padding: 0px; margin: 0px; ">Standard output</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 0px; margin: 0px; ">2</td><td style="padding: 0px; margin: 0px; ">stderr</td><td style="padding: 0px; margin: 0px; ">Standard error</td></tr></tbody></table><h3>Redirecting the standard error stream to a file</h3><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">The following will redirect program error message to a file called error.log:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ program-name 2&gt; error.log<br style="padding: 0px; margin: 0px; " />$ command1 2&gt; error.log</code></p><h3>Redirecting the standard error (stderr) and stdout to file</h3><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">Use the following syntax:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ command-name &amp;&gt;file</code><br style="padding: 0px; margin: 0px; " />OR<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ command &gt; file-name 2&gt;&amp;1</code><br style="padding: 0px; margin: 0px; " />Another useful example:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; "># find /usr/home -name .profile 2&gt;&amp;1 | more</code></p><h3>Redirect stderr to stdout</h3><p style="padding: 0px; margin: 0px 0px 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 22px; background-color: #ffffff; ">Use the command as follows:<br style="padding: 0px; margin: 0px; " /><code style="padding: 0.667em 0.917em; margin: 0px 0px 1.833em; line-height: 1.5em; background-image: none; background-attachment: scroll; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow: auto; border: 1px solid #dddddd; display: block; background-position: 0px 0px; background-repeat: repeat repeat; ">$ command-name 2&gt;&amp;1</code></p><img src ="http://www.blogjava.net/czihong/aggbug/378457.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-05-18 07:40 <a href="http://www.blogjava.net/czihong/articles/378457.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Perl Print Duplicate Line</title><link>http://www.blogjava.net/czihong/articles/376662.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Thu, 26 Apr 2012 03:01:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/376662.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/376662.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/376662.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/376662.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/376662.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; "><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: #008000; ">#</span><span style="color: #008000; ">&nbsp;Find&nbsp;out&nbsp;duplicate&nbsp;line,&nbsp;if&nbsp;yes,&nbsp;print&nbsp;it&nbsp;out.</span><span style="color: #008000; "><br /></span>AcceptEnv&nbsp;LANG&nbsp;LC_CTYPE&nbsp;LC_NUMERIC&nbsp;LC_TIME&nbsp;LC_COLLATE&nbsp;LC_MONETARY<br />LC_MESSAGES<br />AcceptEnv&nbsp;LC_PAPER&nbsp;LC_NAME&nbsp;LC_ADDRESS&nbsp;LC_TELEPHONE&nbsp;LC_MEASUREMENT<br />AcceptEnv&nbsp;LC_IDENTIFICATION&nbsp;LC_ALL<br />&nbsp;<br /><span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;Example&nbsp;of&nbsp;overriding&nbsp;settings&nbsp;on&nbsp;a&nbsp;per-user&nbsp;basis<br />#Match&nbsp;User&nbsp;anoncvs<br />#&nbsp;X11Forwarding&nbsp;no<br />#&nbsp;AllowTcpForwarding&nbsp;no<br />#&nbsp;ForceCommand&nbsp;cvs&nbsp;server</span><span style="color: #008000; "><br /></span>AcceptEnv&nbsp;LC_IDENTIFICATION&nbsp;LC_ALL</div><br /><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: #008000; ">#</span><span style="color: #008000; ">!&nbsp;/usr/bin/perl</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">use</span>&nbsp;strict;<br /><br /><span style="color: #0000FF; ">open</span>(FH,&nbsp;<span style="font-weight: bold; ">'</span><span style="font-weight: bold; ">dupLine.sample</span><span style="font-weight: bold; ">'</span>);<br /><span style="color: #0000FF; ">my</span>&nbsp;<span style="color: #800080; ">%seen</span>;<br /><span style="color: #0000FF; ">while</span>&nbsp;(&lt;FH&gt;)&nbsp;{<br />&nbsp;&nbsp;<span style="color: #800080; ">$seen</span>{<span style="color: #800080; ">$_</span>}++;<br />}<br />&nbsp;<br /><span style="color: #0000FF; ">while</span>&nbsp;(<span style="color: #0000FF; ">my</span>&nbsp;(<span style="color: #800080; ">$line</span>,&nbsp;<span style="color: #800080; ">$count</span>)&nbsp;=&nbsp;<span style="color: #0000FF; ">each</span>&nbsp;<span style="color: #800080; ">%seen</span>)&nbsp;{<br />&nbsp;&nbsp;<span style="color: #0000FF; ">print</span>&nbsp;<span style="font-weight: bold; ">"</span><span style="font-weight: bold; ">$count:&nbsp;$line</span><span style="font-weight: bold; ">"</span>&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;<span style="color: #800080; ">$count</span>&nbsp;&gt;&nbsp;<span style="color: #800000; ">1</span>;<br />}</div><br /><br />Using the standard Perl shorthands:</p><pre prettyprint"="" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; line-height: 18px; text-align: left; "><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; "><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b; ">my</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">%</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">seen</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">;</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; "><br /></span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b; ">while</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">(</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">&lt;&gt;</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">)</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">{</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; "> <br />&nbsp; &nbsp; </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b; ">print</span> <span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #00008b; ">if</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; "> $seen</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">{</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">$_</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">}++;</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; "><br /></span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">}</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; "><br /></span></code></pre><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; ">As a "one-liner":</p><pre prettyprint"="" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; line-height: 18px; text-align: left; "><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; "><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">perl </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">-</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">ne </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #800000; ">'print if $seen{$_}++'</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; "><br /></span></code></pre><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; ">More data? This prints&nbsp;<code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">&lt;file name&gt;:&lt;line number&gt;:&lt;line&gt;</code>:</p><pre prettyprint"="" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; line-height: 18px; text-align: left; "><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; "><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">perl </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">-</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">ne </span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: #800000; ">'print ( $ARGV eq "-" ? "" : "$ARGV:" ), "$.:$_" if $seen{$_}++'</span><span style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; "><br /></span></code></pre><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; ">Explanation on&nbsp;<code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">%seen</code>:</p><ul style="margin: 0px 0px 1em 30px; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; list-style-position: initial; list-style-image: initial; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; "><li style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; word-wrap: break-word; "><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">%seen</code>&nbsp;declares a hash. For each&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">unique</em>&nbsp;line in the input&nbsp;<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">$seen{$_}</code>&nbsp;is a scalar slot in the hash named by the the text of the line.</li><li style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; word-wrap: break-word; ">Using the postfix increment operator (<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">x++</code>) we&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">take</em>&nbsp;the value for our expression, remembering to<em style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">increment</em>&nbsp;it after the expression. So, if we haven't "seen" the line&nbsp;<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">$seen{$_}</code>&nbsp;is undefined--but when forced into an numeric "context" like this, it's taken as 0--and&nbsp;<em style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; ">false</em>.</li><li style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; word-wrap: break-word; ">Then it's incremented to 1.</li></ul><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; ">So the first time we see a line, we take the undefined value which fails the&nbsp;<code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">if</code>. It increments the count at the slot to 1. Thus, it is 1 for any future occurrences at which point it passes the&nbsp;<code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">if</code>&nbsp;condition.</p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; ">Now as I said above,&nbsp;<code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">%seen</code>&nbsp;declares a hash, but with&nbsp;<code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">strict</code>&nbsp;turned off, any variable expression can be created on the spot. So the first time perl sees&nbsp;<code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">$seen{$_}</code>&nbsp;it knows that I'm looking for&nbsp;<code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">%seen</code>, it doesn't have it, so it creates it.</p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; vertical-align: baseline; background-color: #ffffff; clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; line-height: 18px; text-align: left; ">An added neat thing about this is that at the end, if you care to use it, you have a count of how many times each line was repeated.</p><img src ="http://www.blogjava.net/czihong/aggbug/376662.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-04-26 11:01 <a href="http://www.blogjava.net/czihong/articles/376662.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>正则中的括号</title><link>http://www.blogjava.net/czihong/articles/376657.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Thu, 26 Apr 2012 02:41:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/376657.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/376657.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/376657.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/376657.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/376657.html</trackback:ping><description><![CDATA[<span style="font-family: 'Times New Roman'; line-height: 25px; background-color: #f4fbf4; ">()是捕获组用 也就是标记对应的group(i)</span><br style="font-family: 'Times New Roman'; line-height: 25px; background-color: #f4fbf4; " /><span style="font-family: 'Times New Roman'; line-height: 25px; background-color: #f4fbf4; ">[]算是一种集合 如 [0-9]表示0到9中任一数字</span><br style="font-family: 'Times New Roman'; line-height: 25px; background-color: #f4fbf4; " /><span style="font-family: 'Times New Roman'; line-height: 25px; background-color: #f4fbf4; ">{}次数中用到 如 x{1,5} x出现至少1次 最多5次</span><img src ="http://www.blogjava.net/czihong/aggbug/376657.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-04-26 10:41 <a href="http://www.blogjava.net/czihong/articles/376657.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Install and Setup Ramdisk under Linux (CentOS, RHEL, Fedora)</title><link>http://www.blogjava.net/czihong/articles/376604.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Wed, 25 Apr 2012 08:35:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/376604.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/376604.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/376604.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/376604.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/376604.html</trackback:ping><description><![CDATA[<p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; ">Ramdisk is very good to have if you want something to stay in memory.&nbsp;&nbsp; Files in memory makes it so you can access them with out having to access hard drive all the time.&nbsp; Perfect candidates would be things which do not change eg. web images or downloadable files, etc.&nbsp; If you have Linux Kernel 2.4 or later, you already have support of ramdisk built in.&nbsp; You can check if ramdisk is setup by doing:&nbsp;</p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; "><code style="font-family: 'lucida console', monospace; font-size: 0.8em; display: block; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; width: 450px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d3d3d6; border-right-color: #d3d3d6; border-bottom-color: #d3d3d6; border-left-color: #d3d3d6; border-image: initial; "># dmesg | grep RAMDISK<br />RAMDISK driver initialized: 16 RAM disks of 16384K size 1024 blocksize</code></p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; ">You should get&nbsp;above output on CentOS and RHEL.&nbsp; Other linux flavors will have similar output as well.&nbsp; If you would like to see how they are named and what you would need to refer to, do the following:</p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; "><code style="font-family: 'lucida console', monospace; font-size: 0.8em; display: block; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; width: 450px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d3d3d6; border-right-color: #d3d3d6; border-bottom-color: #d3d3d6; border-left-color: #d3d3d6; border-image: initial; "># ls -l /dev/ram*<br />lrwxrwxrwx 1 root root 4 Apr 24 12:05 /dev/ram -&gt; ram1<br />brw-rw---- 1 root disk 1, 0 Apr 24 12:05 /dev/ram0<br />brw-rw---- 1 root disk 1, 1 Apr 24 12:05 /dev/ram1<br />brw-rw---- 1 root disk 1, 10 Apr 24 12:05 /dev/ram10<br />brw-rw---- 1 root disk 1, 11 Apr 24 12:05 /dev/ram11<br />brw-rw---- 1 root disk 1, 12 Apr 24 12:05 /dev/ram12<br />brw-rw---- 1 root disk 1, 13 Apr 24 12:05 /dev/ram13<br />brw-rw---- 1 root disk 1, 14 Apr 24 12:05 /dev/ram14<br />brw-rw---- 1 root disk 1, 15 Apr 24 12:05 /dev/ram15<br />brw-rw---- 1 root disk 1, 2 Apr 24 12:05 /dev/ram2<br />brw-rw---- 1 root disk 1, 3 Apr 24 12:05 /dev/ram3<br />brw-rw---- 1 root disk 1, 4 Apr 24 12:05 /dev/ram4<br />brw-rw---- 1 root disk 1, 5 Apr 24 12:05 /dev/ram5<br />brw-rw---- 1 root disk 1, 6 Apr 24 12:05 /dev/ram6<br />brw-rw---- 1 root disk 1, 7 Apr 24 12:05 /dev/ram7<br />brw-rw---- 1 root disk 1, 8 Apr 24 12:05 /dev/ram8<br />brw-rw---- 1 root disk 1, 9 Apr 24 12:05 /dev/ram9<br />lrwxrwxrwx 1 root root 4 Apr 24 12:05 /dev/ramdisk -&gt; ram0</code></p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; ">All those ramdisks listed have same size.&nbsp; In above example, they are all 16MB.&nbsp; Let us change that so we have more space allowed.&nbsp; Note that I say allowed and not allocated.&nbsp; We allocate space in one of the later steps by formatting one of the drives above.&nbsp;&nbsp; Let us set it up so we have 128 MB.&nbsp; Since this has to be in multiples of 1024, we will setup Ramdisk to have 131072K.&nbsp;</p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; "><code style="font-family: 'lucida console', monospace; font-size: 0.8em; display: block; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; width: 450px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d3d3d6; border-right-color: #d3d3d6; border-bottom-color: #d3d3d6; border-left-color: #d3d3d6; border-image: initial; ">vi /etc/grub.conf</code></p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; ">Find first line which looks similar to following:</p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; "><code style="font-family: 'lucida console', monospace; font-size: 0.8em; display: block; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; width: 450px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d3d3d6; border-right-color: #d3d3d6; border-bottom-color: #d3d3d6; border-left-color: #d3d3d6; border-image: initial; ">kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00</code></p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; ">add ramdisk_size=131072 to the end of the line.&nbsp; Now your line should look like:</p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; "><code style="font-family: 'lucida console', monospace; font-size: 0.8em; display: block; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; width: 450px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d3d3d6; border-right-color: #d3d3d6; border-bottom-color: #d3d3d6; border-left-color: #d3d3d6; border-image: initial; ">kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00<strong>ramdisk_size=131072</strong></code><strong></strong>Save and exit grub.conf.&nbsp; At this point you have it configured to have ramdisk with new size but it does not take effect until you reboot your system.&nbsp; Once you have rebooted your system, we can start doing rest of configurations.</p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; "><code style="font-family: 'lucida console', monospace; font-size: 0.8em; display: block; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; width: 450px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d3d3d6; border-right-color: #d3d3d6; border-bottom-color: #d3d3d6; border-left-color: #d3d3d6; border-image: initial; ">mke2fs -m 0 /dev/ram0</code></p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; ">This will format the ram0 ramdrive for us to use. At this point, kernel will allocate space for you.&nbsp; Let us setup Ramdisk mount point so we can use it.&nbsp; We will also have it be owned by user &#8220;sunny&#8221; so that user can read/write to that mount.</p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; "><code style="font-family: 'lucida console', monospace; font-size: 0.8em; display: block; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; width: 450px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d3d3d6; border-right-color: #d3d3d6; border-bottom-color: #d3d3d6; border-left-color: #d3d3d6; border-image: initial; ">mkdir /home/ramdisk<br />mount /dev/ram0 /home/ramdisk<br />chown sunny.sunny /home/ramdisk</code></p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; ">At this point you should be able to type:&nbsp;&nbsp;<strong>mount&nbsp;</strong>and see your new Ramdisk drive mounted on /home/ramdisk</p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; ">Remember that everything you put on this drive will be gone if you reboot your server.&nbsp; If you unmounted the Ramdisk drive and remounted it, your files will still be there.&nbsp; It is because your system has that much ram set aside for your Ramdisk and will not use it for anything else.&nbsp;&nbsp; If you would like to setup Ramdisk the same next time you boot up, add these lines to your /etc/rc.local files.</p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; "><code style="font-family: 'lucida console', monospace; font-size: 0.8em; display: block; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; width: 450px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #d3d3d6; border-right-color: #d3d3d6; border-bottom-color: #d3d3d6; border-left-color: #d3d3d6; border-image: initial; ">mke2fs -m 0 /dev/ram0<br />mount /dev/ram0 /home/ramdisk<br />chown sunny.sunny /home/ramdisk</code></p><p style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; ">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br /><small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting.&nbsp;<strong>Use at your own risk</strong>.</small></p><span style="font-family: verdana; font-size: 12px; line-height: normal; text-align: left; "><br /><br />Read more:&nbsp;<a href="http://crazytoon.com/2007/06/01/ramdisk-how-do-you-install-and-set-up-ramdisk-under-linux-centos-rhel-fedora/#ixzz1t2VAAY00" style="text-decoration: none; color: #003399; ">http://crazytoon.com/2007/06/01/ramdisk-how-do-you-install-and-set-up-ramdisk-under-linux-centos-rhel-fedora/#ixzz1t2VAAY00</a></span>&nbsp;<img src ="http://www.blogjava.net/czihong/aggbug/376604.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-04-25 16:35 <a href="http://www.blogjava.net/czihong/articles/376604.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>A good reference of bladelogic network shell</title><link>http://www.blogjava.net/czihong/articles/376354.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Mon, 23 Apr 2012 03:45:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/376354.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/376354.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/376354.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/376354.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/376354.html</trackback:ping><description><![CDATA[A good reference of bladelogic network shell:<br /><div><a href="http://kailord.homeip.net/stuffs/Learning%20resources/ACS/BladeLogic%20CBT/BladeLogicNSHCommands.pdf">http://kailord.homeip.net/stuffs/Learning%20resources/ACS/BladeLogic%20CBT/BladeLogicNSHCommands.pdf</a> </div><img src ="http://www.blogjava.net/czihong/aggbug/376354.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-04-23 11:45 <a href="http://www.blogjava.net/czihong/articles/376354.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JBOSS 4.3.0 EAP Clustering with multiple instances running on Same machine balanced with Apache HTTP Server 2.2.11 </title><link>http://www.blogjava.net/czihong/articles/372355.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Wed, 21 Mar 2012 05:22:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/372355.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/372355.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/372355.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/372355.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/372355.html</trackback:ping><description><![CDATA[<div><span style="font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; line-height: 18px; "><span style="font-size: 18px; line-height: normal; ">JBOSS 4.3.0 EAP Clustering with multiple instances running on Same machine balanced with Apache HTTP Server 2.2.11</span>&nbsp;<br />In case if you want to run two instances on the same machine, copy production machine to two folders with different node names, Search for ports-01 and Uncomment the following in one node and do not uncomment in another node. If you need third instance also running on the same machine then copy the production folder to another node folder as third instance and uncomment the bleow content and change the ports-01 to ports-02.&nbsp;<br />The above ports change to be done on the file &lt;jboss_home&gt;\jboss-as\server\&lt;node name&gt;\conf\serverl.xml&nbsp;<br /><br /><div style="font-family: 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #dec7a4; width: 960px; overflow-x: auto; overflow-y: auto; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px; "><div style="padding-left: 45px; "><div style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #dec7a4; "><a href="http://www.coderanch.com/t/462399/JBoss/JBOSS-EAP-Clustering-Apache-HTTP#" style="color: #a0a0a0; text-decoration: none; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial; ">view plain</a><a href="http://www.coderanch.com/t/462399/JBoss/JBOSS-EAP-Clustering-Apache-HTTP#" style="color: #a0a0a0; text-decoration: none; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial; ">copy to clipboard</a><a href="http://www.coderanch.com/t/462399/JBoss/JBOSS-EAP-Clustering-Apache-HTTP#" style="color: #a0a0a0; text-decoration: none; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial; ">print</a><a href="http://www.coderanch.com/t/462399/JBoss/JBOSS-EAP-Clustering-Apache-HTTP#" style="color: #a0a0a0; text-decoration: none; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: inherit; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial; ">?</a></div></div><ol start="1" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; "><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #dec7a4; background-color: #eadbc4; color: inherit; line-height: 14px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mbean&nbsp;code=</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: blue; background-color: inherit; ">"org.jboss.services.binding.ServiceBindingManager"</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;&nbsp;</span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #dec7a4; background-color: #f0e6d5; color: #5c5c5c; line-height: 14px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name=<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: blue; background-color: inherit; ">"jboss.system:service=ServiceBindingManager"</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&gt;&nbsp;&nbsp;</span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #dec7a4; background-color: #eadbc4; color: inherit; line-height: 14px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;attribute&nbsp;name=<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: blue; background-color: inherit; ">"ServerName"</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&gt;ports-</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #c00000; background-color: inherit; ">01</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&lt;/attribute&gt;&nbsp;&nbsp;</span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #dec7a4; background-color: #f0e6d5; color: #5c5c5c; line-height: 14px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;attribute&nbsp;name=<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: blue; background-color: inherit; ">"StoreURL"</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&gt;${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml&lt;/attribute&gt;&nbsp;&nbsp;</span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #dec7a4; background-color: #eadbc4; color: inherit; line-height: 14px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;attribute&nbsp;name=<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: blue; background-color: inherit; ">"StoreFactoryClassName"</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&gt;&nbsp;&nbsp;</span></span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #dec7a4; background-color: #f0e6d5; color: #5c5c5c; line-height: 14px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;org.jboss.services.binding.XMLServicesStoreFactory&nbsp;&nbsp;</span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #dec7a4; background-color: #eadbc4; color: inherit; line-height: 14px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/attribute&gt;&nbsp;&nbsp;</span></li><li style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 0px !important; padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-width: initial; border-color: initial; list-style-type: decimal-leading-zero; list-style-image: initial; list-style-position: outside !important; border-left-width: 3px; border-left-color: #dec7a4; background-color: #f0e6d5; color: #5c5c5c; line-height: 14px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: black; background-color: inherit; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mbean&gt;&nbsp;&nbsp;</span></li></ol></div><br /><br /><br />Note:&nbsp;<br />1.	If you comment &lt;mbean&gt; tag section, JBoss considers the default ports. Example: 8080, 1099 etc..,&nbsp;<br />2.	If you specify ports-01, JBoss uses the ports by incrementing the second digit by 1. example: 8180, 1199 etc.,&nbsp;<br />3.	If you specify ports-02, JBoss uses the ports by incrementing the second digit by 2. example: 8280, 1299 etc..,&nbsp;<br />Port numbers will get increased by 100.&nbsp;<br /><br /><br /><span style="font-size: 18px; line-height: normal; ">JBOSS 4.3.0 EAP Clustering with Apache HTTP Server 2.2.11</span>&nbsp;<br /><br />1.	Configure Apache HTTP Server 2.0.63(without SSL)&nbsp;<br />1.	Install Apache HTTP Server 2.0.63(without SSL).&nbsp;<br /><br />2. Download the mod_jk-1.2.28-httpd-2.0.52.so from below link&nbsp;<br /><a href="http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/" target="_blank" style="color: #000080; text-decoration: underline; ">http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/</a>&nbsp;<br />(Tried with different mod_jk.so/mod_jk.dll&#8217;s but not working)&nbsp;<br /><br />If you are using Apache HTTP server 2.2.11, then use the following binary from the location mentioned below&nbsp;<br />Binary Name: mod_jk-1.2.28-httpd-2.2.3.so&nbsp;<br />Location is&nbsp;<a href="http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/" target="_blank" style="color: #000080; text-decoration: underline; ">http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/</a>&nbsp;<br /><br /><br />2.	Update httpd.conf file available under &lt;Apache_HOME&gt;\Apache2\conf with the following lines at the end.&nbsp;<br /><br /># Include mod_jk's&nbsp;<br /># specific configuration file&nbsp;<br />Include conf/mod-jk.conf&nbsp;<br /><br />3.	Create a file called mod-jk.conf under &lt;Apache_HOME&gt;\Apache2\conf folder with the following content.&nbsp;<br /><br /># Load mod_jk module&nbsp;<br /># Specify the filename of the mod_jk lib&nbsp;<br />LoadModule jk_module modules/mod_jk.so&nbsp;<br /># Where to find workers.properties&nbsp;<br />JkWorkersFile conf/workers.properties&nbsp;<br /># Where to put jk logs&nbsp;<br />JkLogFile logs/mod_jk.log&nbsp;<br /># Set the jk log level [debug/error/info]&nbsp;<br />JkLogLevel info&nbsp;<br /># Select the log format&nbsp;<br />JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"&nbsp;<br /># JkOptions indicates to send SSK KEY SIZE&nbsp;<br />JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories&nbsp;<br /># JkRequestLogFormat&nbsp;<br />JkRequestLogFormat "%w %V %T"&nbsp;<br /># Mount your applications&nbsp;<br />JkMount /* loadbalancer&nbsp;<br /># You can use external file for mount points.&nbsp;<br /># It will be checked for updates each 60 seconds.&nbsp;<br /># The format of the file is: /url=worker&nbsp;<br /># /examples/*=loadbalancer&nbsp;<br />JkMountFile conf/uriworkermap.properties&nbsp;<br /># Add shared memory.&nbsp;<br /># This directive is present with 1.2.10 and&nbsp;<br /># later versions of mod_jk, and is needed for&nbsp;<br /># for load balancing to work properly&nbsp;<br />JkShmFile logs/jk.shm&nbsp;<br /># Add jkstatus for managing runtime data&nbsp;<br />&lt;Location /jkstatus/&gt;&nbsp;<br />JkMount status&nbsp;<br />Order deny,allow&nbsp;<br />Deny from all&nbsp;<br />Allow from 127.0.0.1&nbsp;<br />&lt;/Location&gt;&nbsp;<br /><br />4.	Create a file called uriworkermap.properties under &lt;Apache_HOME&gt;\Apache2\conf folder with the following content.&nbsp;<br /><br /># Simple worker configuration file&nbsp;<br /># Mount the&nbsp;<a href="http://www.coderanch.com/forums/f-7/Servlets" title="the JavaRanch servlet forum" target="_new" style="color: inherit; text-decoration: none; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #555555; ">Servlet</a>&nbsp;context to the ajp13 worker&nbsp;<br />/jmx-console=loadbalancer&nbsp;<br />/jmx-console/*=loadbalancer&nbsp;<br />/web-console=loadbalancer&nbsp;<br />/web-console/*=loadbalancer&nbsp;<br /><br />5.	Create a file called workers.properties under &lt;Apache_HOME&gt;\Apache2\conf folder with the following content and change the host name and Port numbers as required.&nbsp;<br /><br /># Define list of workers that will be used&nbsp;<br /># for mapping requests&nbsp;<br />worker.list=loadbalancer,status&nbsp;<br /><br /># Define Node1&nbsp;<br /># modify the host as your host IP or DNS name.&nbsp;<br />worker.node1.port=8009&nbsp;<br />worker.node1.host=agi-607.agi.com&nbsp;<br />worker.node1.type=ajp13&nbsp;<br />worker.node1.lbfactor=1&nbsp;<br />worker.node1.cachesize=10&nbsp;<br /><br /># Define Node2&nbsp;<br /># modify the host as your host IP or DNS name.&nbsp;<br />worker.node2.port=8009&nbsp;<br />worker.node2.host=agi-678.agi.com&nbsp;<br />worker.node2.type=ajp13&nbsp;<br />worker.node2.lbfactor=1&nbsp;<br />worker.node2.cachesize=10&nbsp;<br /><br /># Load-balancing behaviour&nbsp;<br />worker.loadbalancer.type=lb&nbsp;<br />worker.loadbalancer.balance_workers=node1,node2&nbsp;<br />worker.loadbalancer.sticky_session=1&nbsp;<br />#worker.list=loadbalancer&nbsp;<br /># Status worker for managing load balancer&nbsp;<br />worker.status.type=status&nbsp;<br /><br />2.	Configuring JBOSS 4.3.0 EAP &#8211; CP02 GA Clustering&nbsp;<br />6.	Make sure the Java 1.5.0.11 is installed and the JAVA_HOME in environment variable is set as mentioned below.&nbsp;<br />Example: C:\Program Files\Java\jdk1.5.0_10&nbsp;<br />7.	Extract JBOSS 4.3.0 Enterprise Application Platform CP02 build in to Hard disk after downloading it from the location.&nbsp;<br /><a href="https://support.redhat.com/jbossnetwork/restricted/listSoftware.html?downloadType=distributions&amp;product=appplatform&amp;version=4.3.0.GA_CP02" target="_blank" rel="nofollow" style="color: #000080; text-decoration: underline; ">https://support.redhat.com/jbossnetwork/restricted...platform&amp;version=4.3.0.GA_CP02</a>&nbsp;<br /><br />8.	Copy the production folder under jboss-eap-4.3\jboss-as\server folder into another folder named Node1 to create a node instance.&nbsp;<br />9.	Add the jvmRoute= &lt;Node name&gt; parameter to the given line as shown in the example in the file server.xml available under jboss-eap-4.3\jboss-as\server\Node2\deploy\jboss-web.deployer folder.&nbsp;<br />Eg:&nbsp;<br />&lt;Engine name="jboss.web" defaultHost="localhost" jvmRoute="Node1"&gt;&nbsp;<br /><br />10.	Locate the &lt;attribute&gt; element with a name of UseJK, and set its value to true in the file jboss-service.xml available under jboss-eap-4.3\jboss-as\server\Node2\deploy\jboss-web.deployer\META-INF folder.&nbsp;<br />Eg:&nbsp;<br />&lt;attribute name="UseJK"&gt;true&lt;/attribute&gt;&nbsp;<br /><br />11.	Update the tag &lt;distributable/&gt; in the file &#8220;web.xml&#8221; available at JBoss_HOME\server\all\deploy\jmx-console.war\WEB-INF\web.xml as given below:&nbsp;<br />Eg:&nbsp;<br />&lt;?xml version="1.0"?&gt;&nbsp;<br />&lt;!DOCTYPE web-app PUBLIC&nbsp;<br />"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"&nbsp;<br />"http://java.sun.com/dtd/web-app_2_3.dtd"&gt;&nbsp;<br /><br />&lt;web-app&gt;&nbsp;<br /><br /> update the below line after the above content.&nbsp;<br />&lt;distributable/&gt;&nbsp;<br /><br /><br />12.	Uncomment the line #admin=admin in the files web-console-users.properties, jmx-console-users.properties files which are available under folders JBOSS_HOME\server\Node3\deploy\management\console-mgr.sar\web-console.war\WEB-INF\classes and JBoss_HOME\server\Node3\conf\props respectively.&nbsp;<br /><br /><br /><br />13.	To disable to JMS clustering, change the following parameter to true in the file clustered-hsqldb-persistence-service.xml or if you are using different database then &lt;XXX&gt;-persistence-service.xml file.&nbsp;<br /><br />&lt;attribute name="Clustered"&gt;false&lt;/attribute&gt;&nbsp;<br />14.	Jboss clustered environment will not support exploded war file. Hence the war file should be placed in the farm folder. But each time you restart the jboss server the deployments get restarted due to which the arispwd.dat and property files will change after deployment. The bold lines to be added to the file web.xml which is available under jboss-eap-4.3\jboss-as\server\node1\deploy\jboss-web.deployer\conf to avoid this problem.&nbsp;<br /><br />&lt;init-param&gt;&nbsp;<br />&lt;param-name&gt;fork&lt;/param-name&gt;&nbsp;<br />&lt;param-value&gt;false&lt;/param-value&gt;&nbsp;<br />&lt;/init-param&gt;&nbsp;<br />&lt;init-param&gt;&nbsp;<br />&lt;param-name&gt;enablepooling&lt;/param-name&gt;&nbsp;<br />&lt;param-value&gt;false&lt;/param-value&gt;&nbsp;<br />&lt;/init-param&gt;&nbsp;<br />&lt;init-param&gt;&nbsp;<br />&lt;param-name&gt;development&lt;/param-name&gt;&nbsp;<br />&lt;param-value&gt;false&lt;/param-value&gt;&nbsp;<br />&lt;/init-param&gt;&nbsp;<br />&lt;init-param&gt;&nbsp;<br />&lt;param-name&gt;xpoweredBy&lt;/param-name&gt;&nbsp;<br />&lt;param-value&gt;false&lt;/param-value&gt;&nbsp;<br />&lt;/init-param&gt;&nbsp;<br /><br />15.	Perform the steps from 7 to 10 on machine to for Node2.&nbsp;<br />16.	Start the JBOSS using run.bat file from the location jboss-eap-4.3\jboss-as\bin after connecting to command prompt, with the parameter &#8211;c and argument &lt;Node&gt;. Example given below.&nbsp;<br />a.	From Node1 the command should be executed at the dos prompt under folder jboss-eap-4.3\jboss-as\bin as mentioned below&nbsp;<br />i.	Run.bat &#8211;c Node1 &#8211;b agi-607.agi.com&nbsp;<br /><br />b.	From Node2 the command should be executed at the dos prompt under folder jboss-eap-4.3\jboss-as\bin as mentioned below&nbsp;<br />i.	Run.bat &#8211;c Node2 &#8211;b agi-678.agi.com&nbsp;<br />17.	Verify the cluster by logging into the jmx console using the following with user admin and password as admin.&nbsp;<br /><a href="http://agi-607.agi.com/" target="_blank" rel="nofollow" style="color: #000080; text-decoration: underline; ">http://agi-607.agi.com/</a>&nbsp;<br />The following screens will display.&nbsp;<br /><br /><br />Figure 1: JBOSS console page.&nbsp;<br /><br />Figure 2: Username admin and password as admin(as given in the jmx-console-users.properties file in the JBoss_HOME\server\Node3\conf\props folder)&nbsp;<br /><br /><br />Figure 3: Screen after log into jmx console002&nbsp;<br /><br /><br /><br /><br />Figure 4: Service=DefaultPartition under JBOSS section in the jmx console screen.&nbsp;<br /><br /><br />Figure 5: Service=DefaultPartition under JBOSS section in the jmx console screen. Clustered machines shall be viewed in the current view.&nbsp;<br /><br />18.	Place the .war file in the folder jboss-eap-4.3\jboss-as\server\Node2\farm, after starting the two nodes.&nbsp;<br />19.	Check if the deployment is pushed into the both nodes under farm folder and accessible with the default port number.&nbsp;<br />Example:&nbsp;<br />a.	http://agi-607:8080/Admin/wflogin.jsp&nbsp;<br />b.	http://agi-678:8080/Admin/wflogin.jsp&nbsp;<br /><br /><br />Note: Any one approach to be chosen to configure the datasource either section 3 or section 4.&nbsp;<br />3.	Oracle 10g&nbsp;<a href="http://www.coderanch.com/forums/f-3/JDBC" title="the JavaRanch JDBC forum" target="_new" style="color: inherit; text-decoration: none; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #555555; ">JDBC</a>&nbsp;Source configuration(Alternative database)&nbsp;<br />1.	Copy the JDBC driver ojdbc14.jar from the oracle installation folder Oracle\product\10.1.0\Client_1\jdbc\lib in to the jboss-eap-4.3\jboss-as\server\node1\lib&nbsp;<br /><br />2.	JBoss AS connects to relational databases via datasources. These datasource definitions can be found in the jboss-as\server\production\deploy directory. The datasource definitions are deployable just like WAR and EAR files. The datasource files can be recognized by looking for the XML files that end in *-ds.xml.&nbsp;<br /><br />3.	Configure default data source to Oracle by following the below steps&nbsp;<br /><br />a)	Copy the oracle-ds.xml file from jboss-as\docs\examples\jca to jboss-as\server\Node3\deploy folder.&nbsp;<br />b)	Modify as mentioned below&nbsp;<br />&lt;datasources&gt;&nbsp;<br />&lt;local-tx-datasource&gt;&nbsp;<br />&lt;jndi-name&gt;DefaultDS&lt;/jndi-name&gt;&nbsp;<br />&lt;connection-url&gt;jdbc<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />racle:thin:@192.167.104.22:1521<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />rcl&lt;/connection-url&gt;&nbsp;<br />&lt;!--&nbsp;<br /><br />Here are a couple of the possible OCI configurations.&nbsp;<br />For more information, see&nbsp;<a href="http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm" target="_blank" rel="nofollow" style="color: #000080; text-decoration: underline; ">http://otn.oracle.com/docs/products/oracle9i/doc_l...lease2/java.920/a96654/toc.htm</a>&nbsp;<br /><br />&lt;connection-url&gt;jdbc<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />racle<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />ci:@youroracle-tns-name&lt;/connection-url&gt;&nbsp;<br />Or&nbsp;<br />&lt;connection-url&gt;jdbc<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />racle<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />ci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))&lt;/connection-url&gt;&nbsp;<br /><br />Clearly, it&#8217;s better to have TNS set up properly.&nbsp;<br />--&gt;&nbsp;<br />&lt;driver-class&gt;oracle.jdbc.driver.OracleDriver&lt;/driver-class&gt;&nbsp;<br />&lt;user-name&gt;jbossuser&lt;/user-name&gt;&nbsp;<br />&lt;password&gt;jbosspass&lt;/password&gt;&nbsp;<br />&lt;!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool --&gt;&nbsp;<br />&lt;!--valid-connection-checker-class-name&gt;org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker&lt;/valid-connection-checker-class-name--&gt;&nbsp;<br />&lt;!-- Checks the Oracle error codes and messages for fatal errors --&gt;&nbsp;<br />&lt;exception-sorter-class-name&gt;org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter&lt;/exception-sorter-class-name&gt;&nbsp;<br />&lt;!-- sql to call when connection is created&nbsp;<br />&lt;new-connection-sql&gt;some arbitrary sql&lt;/new-connection-sql&gt;&nbsp;<br />--&gt;&nbsp;<br /><br />&lt;!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConnectionChecker is prefered&nbsp;<br />&lt;check-valid-connection-sql&gt;some arbitrary sql&lt;/check-valid-connection-sql&gt;&nbsp;<br />--&gt;&nbsp;<br /><br />&lt;!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml --&gt;&nbsp;<br />&lt;metadata&gt;&nbsp;<br />&lt;type-mapping&gt;Oracle9i&lt;/type-mapping&gt;&nbsp;<br />&lt;/metadata&gt;&nbsp;<br />&lt;/local-tx-datasource&gt;&nbsp;<br /><br />&lt;/datasources&gt;&nbsp;<br /><br />Note: If multiple database schemas to be configured then just replicate the data sources block again by changing the credentials.&nbsp;<br /><br />4.	Oracle 10g JDBC Source Configuration(Using shared database)&nbsp;<br /><br />1.	Create a database user with name jbossuser and password as jbosspass.&nbsp;<br /><br />2.	Copy the JDBC driver ojdbc14.jar from the oracle installation folder Oracle\product\10.1.0\Client_1\jdbc\lib in to the jboss-eap-4.3\jboss-as\server\node1\lib&nbsp;<br /><br />3.	JBoss AS connects to relational databases via datasources. These datasource definitions can be found in the jboss-as\server\production\deploy directory. The datasource definitions are deployable just like WAR and EAR files. The datasource files can be recognized by looking for the XML files that end in *-ds.xml.&nbsp;<br /><br />4.	Configure default data source to Oracle by following the below steps&nbsp;<br /><br />a)	Copy the oracle-ds.xml file from jboss-as\docs\examples\jca to jboss-as\server\Node3\deploy folder.&nbsp;<br />b)	Modify as mentioned below&nbsp;<br />&lt;datasources&gt;&nbsp;<br />&lt;local-tx-datasource&gt;&nbsp;<br />&lt;jndi-name&gt;DefaultDS&lt;/jndi-name&gt;&nbsp;<br />&lt;connection-url&gt;jdbc<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />racle:thin:@192.167.104.22:1521<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />rcl&lt;/connection-url&gt;&nbsp;<br />&lt;!--&nbsp;<br /><br />Here are a couple of the possible OCI configurations.&nbsp;<br />For more information, see&nbsp;<a href="http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm" target="_blank" rel="nofollow" style="color: #000080; text-decoration: underline; ">http://otn.oracle.com/docs/products/oracle9i/doc_l...lease2/java.920/a96654/toc.htm</a>&nbsp;<br /><br />&lt;connection-url&gt;jdbc<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />racle<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />ci:@youroracle-tns-name&lt;/connection-url&gt;&nbsp;<br />or&nbsp;<br />&lt;connection-url&gt;jdbc<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />racle<img src="http://www.coderanch.com/images/smilies/jr-redface.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" />ci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))&lt;/connection-url&gt;&nbsp;<br /><br />Clearly, its better to have TNS set up properly.&nbsp;<br />--&gt;&nbsp;<br />&lt;driver-class&gt;oracle.jdbc.driver.OracleDriver&lt;/driver-class&gt;&nbsp;<br />&lt;user-name&gt;jbossuser&lt;/user-name&gt;&nbsp;<br />&lt;password&gt;jbosspass&lt;/password&gt;&nbsp;<br />&lt;!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool --&gt;&nbsp;<br />&lt;!--valid-connection-checker-class-name&gt;org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker&lt;/valid-connection-checker-class-name--&gt;&nbsp;<br />&lt;!-- Checks the Oracle error codes and messages for fatal errors --&gt;&nbsp;<br />&lt;exception-sorter-class-name&gt;org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter&lt;/exception-sorter-class-name&gt;&nbsp;<br />&lt;!-- sql to call when connection is created&nbsp;<br />&lt;new-connection-sql&gt;some arbitrary sql&lt;/new-connection-sql&gt;&nbsp;<br />--&gt;&nbsp;<br /><br />&lt;!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConnectionChecker is prefered&nbsp;<br />&lt;check-valid-connection-sql&gt;some arbitrary sql&lt;/check-valid-connection-sql&gt;&nbsp;<br />--&gt;&nbsp;<br /><br />&lt;!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml --&gt;&nbsp;<br />&lt;metadata&gt;&nbsp;<br />&lt;type-mapping&gt;Oracle9i&lt;/type-mapping&gt;&nbsp;<br />&lt;/metadata&gt;&nbsp;<br />&lt;/local-tx-datasource&gt;&nbsp;<br /><br />&lt;/datasources&gt;&nbsp;<br /><br />Note: If multiple database schemas to be configured then just replicate the data sources block again by changing the credentials.&nbsp;<br /><br />5.	The JMS service in the JBoss AS uses relational databases to persist its messages. For improved performance, you should change the JMS service to take advantage of the external database. To do that, you need to replace the file jboss-as/server/production/deploy/jboss-messaging.sar/clustered-hsqldb-persistence-service.xml with a file oracle-persistence-service.xml in jboss-as/docs/examples/jms folder and restart your server.&nbsp;<br /><br />6.	Next, change the jboss-as/server/production/conf/standardjbosscmp-jdbc.xml file so that the fk-constraint property is true. That is needed for all external databases we supported bythe JBoss Enterprise Application Platform. This file configures the database connection settings for the EJB2 CMP beans deployed in the JBoss AS.&nbsp;<br /><br />&lt;fk-constraint&gt;true&lt;/fk-constraint&gt;&nbsp;<br /><br />7.	The Java Persistence API (JPA) entity manager can save EJB3 entity beans to any backend database. Hibernate provides the JPA implementation in JBoss AS. In order for Hibernate to work correctly with alternative databases, JBOSS recommend you configure the database dialect in the jboss-as/server/production/deploy/ejb3.deployer/META-INF/persistence.properties file. Add the following line below #hibernate.dialect=org.hibernate.dialect.HSQLDialect.&nbsp;<br /><br />hibernate.dialect=org.hibernate.dialect.Oracle10gDialect&nbsp;<br /><br />Perform the entire section 3 on both the nodes of the cluster.&nbsp;</span></div><img src ="http://www.blogjava.net/czihong/aggbug/372355.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-03-21 13:22 <a href="http://www.blogjava.net/czihong/articles/372355.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How to kill defunct process</title><link>http://www.blogjava.net/czihong/articles/372287.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Tue, 20 Mar 2012 08:58:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/372287.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/372287.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/372287.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/372287.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/372287.html</trackback:ping><description><![CDATA[<div><span style="color: #222222; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial, sans-serif; font-size: 13px; line-height: normal; "><h2>How to kill defunct&nbsp;process</h2><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; color: #333333; border-bottom-color: #bbbbbb; border-bottom-width: 1px; border-bottom-style: solid; "><a href="http://kenno.wordpress.com/2007/04/04/how-to-kill-defunct-process/#comments" style="padding-top: 0px; padding-right: 7px; padding-bottom: 5px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #333333; text-decoration: none; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; background-position: initial initial; background-repeat: initial initial; ">with 17 comments</a></p><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">Defunct processes are corrupted processes that can no longer communicate between the parent and child one. Sometimes, they become &#8220;zombies&#8221; and remain in your system until you reboot your machine. You can try to apply &#8220;kill -9&#8243; command, but most of the time you&#8217;ll be out of luck.</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">In order to kill theses defunct processes, you have two choices:<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />1. Reboot your computer<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />2. Continue reading&#8230;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">First, let&#8217;s find out if the system contains defunct process:</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; "><code style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><strong style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">$ ps -A | grep defunct</strong></code></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">Assume your output is as the following:</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; "><code style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />8328 ? 00:00:00 mono &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />8522 ? 00:00:01 mono &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />13132 ? 00:00:00 mono &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />25822 ? 00:00:00 ruby &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />28383 ? 00:00:00 ruby &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />18803 ? 00:00:00 ruby &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /></code></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">This means you have 6 defunct processes: 3 of mono, and 3 of ruby. These processes exists because of poorly written application or unusual action taken by the user, in my case there must be some serious problem with the program I wrote in mono C#&nbsp;<img src="http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif?m=1336659725g" alt=":-)" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px; border-top-color: #dddddd; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; border-top-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 2px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">Now, let&#8217;s find the ID of the process and its parent&#8217;s:</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; "><code style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><strong style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">$ ps -ef | grep defunct | more</strong></code></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">The output from the above command:</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; "><code style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">UID PID PPID ...<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />---------------------------------------------------------------</code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><code style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />kenno 8328 6757 0 Mar22 ? 00:00:00 [mono] &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />kenno 8522 6757 0 Mar22 ? 00:00:01 [mono] &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />kenno 13132 6757 0 Mar23 ? 00:00:00 [mono] &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />kenno 25822 25808 0 Mar27 ? 00:00:00 [ruby] &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />kenno 28383 28366 0 Mar27 ? 00:00:00 [ruby] &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />kenno 18803 18320 0 Apr02 ? 00:00:00 [ruby] &lt;defunct&gt;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /></code><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />UID: User ID<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />PID: Process ID<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />PPID: Parent Process ID</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">If you try to kill the process with ID 8328 with the command &#8220;kill -9 8328&#8243;, it may not work. To properly kill it, you need to execute the kill command on its parent whose ID is 6757 ($kill -9 6757). Continue applying the kill command on all the PPID, and verify your result (<code style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><strong style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">$ps -A | grep defunct</strong></code>).</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">If the previous command display no result, well done, otherwise you may need to reboot your system.</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">Source:</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">http://wagoneers.com/UNIX/KILL/Kill.html</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; line-height: 1.5; ">http://www.cts.wustl.edu/~allen/kill-defunct-process.html</p></div></span></div><img src ="http://www.blogjava.net/czihong/aggbug/372287.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-03-20 16:58 <a href="http://www.blogjava.net/czihong/articles/372287.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>find -exec </title><link>http://www.blogjava.net/czihong/articles/372188.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Mon, 19 Mar 2012 05:59:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/372188.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/372188.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/372188.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/372188.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/372188.html</trackback:ping><description><![CDATA[<div><p style="font-family: 'Times New Roman'; line-height: normal; font-size: medium; ">Find is able to execute one or more commands for each file it has found with the -exec option. Unfortunately, one cannot simply enter the command. You need to remember two syntactic tricks:</p><ol style="font-family: 'Times New Roman'; line-height: normal; font-size: medium; "><li>The command that you want to execute need to contain a special macro argument&nbsp;{}, which will be replaced by the matched filename on each invocation of&nbsp;-exec&nbsp;predicate.&nbsp;<br /></li><li>You need to specify&nbsp;\;&nbsp;(or&nbsp;';'&nbsp;) at the end of the command. (If the \ is left out, the shell will interpret the ; as the end of the find command.) . For example, the following two commands are equivalent:<blockquote style="font-size: 10pt; font-family: arial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9f9; background-position: initial initial; background-repeat: initial initial; "><p>find . -name "*rc.conf"&nbsp; -exec chmod o+r {} \;</p><p>find . -name "*rc.conf" -exec chmod o+r '{} ;'</p></blockquote></li></ol></div><img src ="http://www.blogjava.net/czihong/aggbug/372188.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-03-19 13:59 <a href="http://www.blogjava.net/czihong/articles/372188.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Perl调用外部命令的方式和区别</title><link>http://www.blogjava.net/czihong/articles/371468.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Thu, 08 Mar 2012 01:43:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/371468.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/371468.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/371468.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/371468.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/371468.html</trackback:ping><description><![CDATA[refer to:&nbsp;<a href="http://hi.baidu.com/develop_skill/blog/item/d69bc0cbf010da4ff31fe72b.html" style="font-family: verdana, arial; font-size: 13px; line-height: 23px; background-color: #ffffff; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0066cc; ">http://hi.baidu.com/develop_skill/blog/item/d69bc0cbf010da4ff31fe72b.html</a><br />refer to:&nbsp;<a href="http://cn.waterlin.org/" style="font-family: verdana, arial; font-size: 13px; line-height: 23px; background-color: #ffffff; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0066cc; ">http://cn.waterlin.org/</a><br /><br /><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: #111111; font-size: 13px; line-height: 1.8em; font-family: verdana, arial; background-color: #ffffff; "><div id="cnblogs_post_body" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: red; line-height: 1.8em; ">Perl调用外部命令的方式和区别</span></p><div id="blog_text" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">主要的方式简述如下：<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />1.&nbsp;system("command");<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />使用该命令将开启一个子进程执行引号中的命令，父进程将等待子进程结束并继续执行下面的代码。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />2.&nbsp;exec("command");<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />效果同system命令类似，区别是不会开启子进程，而是取代父进程，因此执行完引号中的命令后进程即结束。一般和fork配合使用。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />3.&nbsp;`command`;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />使用反引号调用外部命令能够捕获其标准输出，并按行返回且每行结束处附带一个回车。反引号中的变量在编译时会被内插为其值。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />4.&nbsp;open LIST "ls -l|";<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp; &nbsp; open MORE "|more";<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp; &nbsp; @list=&lt;LIST&gt;;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp; &nbsp; print MORE @list;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp; &nbsp; close(LIST);<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp; &nbsp; close(MORE);<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />使用带管道的文件句柄来执行外部命令，使用方式与读写文件类似。可以从外部命令的输出读取数据，也可以将数据输出到外部命令作为输入。<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />5.&nbsp;defined(my $pid=fork) or die "Can not fork: $!\n";<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp; &nbsp; unless ($pid) {<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;exec ("date");<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp; &nbsp; }<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />waitpid ($pid,0);<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />使用fork将会开启子进程与父进程同时执行之后的代码，其中父进程中fork会返回一个非零的数，而子进程中将返回零。上面的代码完成和system("date")相同的功能。比起system单纯地调用外部命令，fork可以完成更加复杂的进程操作。</div><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />&nbsp;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: red; line-height: 1.8em; ">在Perl中用system、exec、readpipe函数来执行系统命令</span></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">在Perl中，可以用<a href="http://perldoc.perl.org/functions/system.html" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0066cc; ">system</a>、<a href="http://perldoc.perl.org/functions/exec.html" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0066cc; ">exec</a>、<a href="http://perldoc.perl.org/functions/readpipe.html" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0066cc; ">readpipe</a>这三个命令来调用其他脚本、系统命令等。这三个命令的主要区别就是返回值。</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">1) 对于<a href="http://perldoc.perl.org/functions/system.html" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0066cc; ">system</a>这个函数来说，它会返回执行后的状态，比如说</p><blockquote style="margin-right: 0px; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">@args = (&#8220;command&#8221;, &#8220;arg1&#8243;, &#8220;arg2&#8243;);<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />system(@args) == 0<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />or die &#8220;system @args failed: $?&#8221;</p></blockquote><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">当然，你也可以用类似于下面的语句来检查出错的原因：</p><blockquote style="margin-right: 0px; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">if ($? == -1) {<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />print &#8220;failed to execute: $!\n&#8221;;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />}<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />elsif ($? &amp; 127) {<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />printf &#8220;child died with signal %d, %s coredump\n&#8221;,<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />($? &amp; 127),&nbsp; ($? &amp; 128) ? &#8216;with&#8217; : &#8216;without&#8217;;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />}<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />else {<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />printf &#8220;child exited with value %d\n&#8221;, $? &gt;&gt; 8;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />}</p></blockquote><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">2) 而对于<a href="http://perldoc.perl.org/functions/exec.html" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0066cc; ">exec</a>这个函数来说，仅仅是执行一个系统的命令，一般情况下并没有返回值。<a href="http://perldoc.perl.org/functions/exec.html" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0066cc; ">exec</a>只有在系统没有你要执行的命令的情况下，才会返回false值。</p><blockquote style="margin-right: 0px; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">exec (&#8216;foo&#8217;)&nbsp;&nbsp; or print STDERR &#8220;couldn&#8217;t exec foo: $!&#8221;;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />{ exec (&#8216;foo&#8217;) }; print STDERR &#8220;couldn&#8217;t exec foo: $!&#8221;;</p></blockquote><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">3) 当我们需要保存系统命令运行的结果，以便分析并作进一步的处理时，就要用到<a href="http://perldoc.perl.org/functions/readpipe.html" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0066cc; ">readpipe</a>这个函数了。例如：</p><blockquote style="margin-right: 0px; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">@result = readpipe( &#8220;ls -l /tmp&#8221; );<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />print &#8220;@result&#8221;;</p></blockquote><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">会产生如下的结果：</p><blockquote style="margin-right: 0px; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">drwxr-xr-x&nbsp; 2 root&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp; 4096 Mar 19 11:55 testdir</p></blockquote><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">当然，你也可以把生成的结果放到一个文件里，以便写工作日志呀、发布报告呀。</p><blockquote style="margin-right: 0px; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">$inject_command = &#8220;./ConfigChecker.bat F:/nic/3502/ARRAY-4AD2E0573/etc &#8220;.$device_name;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />chdir &#8220;F:/TestTools/bin/&#8221;;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />@temp_result = readpipe($inject_command);<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />open(result_file,&#8221;&gt;result.txt&#8221;);<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />print result_file @temp_result;<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; " />close(result_file);</p></blockquote><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">这样，你就把系统运行的结果扔到了系统命令所在目录下的result.txt文件里了。</p></div></div><img src ="http://www.blogjava.net/czihong/aggbug/371468.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-03-08 09:43 <a href="http://www.blogjava.net/czihong/articles/371468.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Passing arguments to a shell script</title><link>http://www.blogjava.net/czihong/articles/371036.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Wed, 29 Feb 2012 13:58:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/371036.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/371036.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/371036.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/371036.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/371036.html</trackback:ping><description><![CDATA[<h1></h1><div></div><div>Any shell script you run has access to (inherits) the environment variables accessible to its parent shell. In addition, any arguments you type after the script name on the shell command line are passed to the script as a series of variables.</div><div>The following parameters are recognized:</div><div></div><div>$*</div><div>Returns a single string (``$1, $2 ... $n'') comprising all of the positional parameters separated by the internal field separator character (defined by the IFS environment variable).</div><div></div><div>$@</div><div>Returns a sequence of strings (``$1'', ``$2'', ... ``$n'') wherein each positional parameter remains separate from the others.</div><div></div><div>$1, $2 ... $n</div><div>Refers to a numbered argument to the script, where n is the position of the argument on the command line. In the Korn shell you can refer directly to arguments where n is greater than 9 using braces. For example, to refer to the 57th positional parameter, use the notation ${57}. In the other shells, to refer to parameters with numbers greater than 9, use the shift command; this shifts the parameter list to the left. $1 is lost, while $2 becomes $1, $3 becomes $2, and so on. The inaccessible tenth parameter becomes $9 and can then be referred to.</div><div></div><div>$0</div><div>Refers to the name of the script itself.</div><div></div><div>$#</div><div>Refers to the number of arguments specified on a command line.</div><div></div><div>For example, create the following shell script called mytest:</div><div>&nbsp; &nbsp;echo There are $# arguments to $0: $* &nbsp; &nbsp;echo first argument: $1 &nbsp; &nbsp;echo second argument: $2 &nbsp; &nbsp;echo third argument: $3 &nbsp; &nbsp;echo here they are again: $@&nbsp;</div><div>When the file is executed, you will see something like the following:</div><div>&nbsp; &nbsp;$ mytest foo bar quux &nbsp; &nbsp;<br />There are 3 arguments to mytest: foo bar quux &nbsp; &nbsp;<br />first argument: foo &nbsp; &nbsp;<br />second argument: bar &nbsp; &nbsp;<br />third argument: quux &nbsp; &nbsp;<br /><br />here they are again: foo bar quux&nbsp;<br /></div><div>$# is expanded to the number of arguments to the script, while $* and $@ contain the entire argument list. Individual parameters are accessed via $0, which contains the name of the script, and variables $1 to $3 which contain the arguments to the script (from left to right along the command line).</div><div>Although the output from $@ and $* appears to be the same, it may be handled differently, as $@ lists the positional parameters separately rather than concatenating them into a single string. Add the following to the end of mytest:</div><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 />-->&nbsp; &nbsp;function&nbsp;how_many&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;"$#&nbsp;arguments&nbsp;were&nbsp;supplied."&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp;</div>how_many "$*" &nbsp; &nbsp;<br />how_many "$@"&nbsp;</div><div>The following appears when you run mytest:</div><div>&nbsp; &nbsp;$ mytest foo bar quux &nbsp; &nbsp;<br />There are 3 arguments to mytest: foo bar quux &nbsp; &nbsp;<br />first argument: foo &nbsp; &nbsp;<br />second argument: bar &nbsp; <br />third argument: quux &nbsp; &nbsp;<br />here they are again: foo bar quux &nbsp; &nbsp;1 arguments were supplied. &nbsp; &nbsp;3 arguments were supplied.</div><pre style="line-height: normal; "></pre><img src ="http://www.blogjava.net/czihong/aggbug/371036.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-02-29 21:58 <a href="http://www.blogjava.net/czihong/articles/371036.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Use Sed in Multi-Files Text Processing</title><link>http://www.blogjava.net/czihong/articles/370245.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Sat, 18 Feb 2012 07:49:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/370245.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/370245.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/370245.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/370245.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/370245.html</trackback:ping><description><![CDATA[<div><p style="color: #444444; font-family: 'Microsoft Yahei', 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; line-height: normal; "></p><div>During the software development, developers always need to modify multi code files since some bugs or requirement change. All of this modification may be similar, such as and insert the following code into JavaScript(&lt;script&gt; /*JavaScript Section*/&lt;/scripte&gt;) section in JSP page, let us say we have A.jsp, B.jsp, and C.jsp.&nbsp;</div><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 />-->function&nbsp;insertMe(){<br />&nbsp;&nbsp;&nbsp;&nbsp;alert(&#8220;Hello&#8221;);<br />}</div></div><div></div><div>To complete this task, normally, we can open all three jsp file one by one, and copy + paste the function insertMe() into code. But if we have more files, it is boring and annoy to open echo file and insert the code.</div><div></div><div>There is other smarter way to achieve this task, sed utility in Linux. In Linux, the sed provides the developer an convinces way. Just one command:</div><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 />-->sed&nbsp;&#8211;i&nbsp;&#8216;/&lt;script&gt;/&nbsp;a\function&nbsp;insertMe(){\talert(&#8220;Hello&#8221;);\n}\n&nbsp;&#8216;&nbsp;[ABC].jsp</div></div><div>This script means: append function insertMe(){&#8230;} after &lt;script&gt; in A.jsp, B.jsp and C.jsp.</div><div>Sed also provide other powerful feature, for more, please dive into &#8216;man sed&#8217;. Below is an example of replace.</div><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 />-->sed&nbsp;&#8211;e&nbsp;&#8216;s/Hello/Hello&nbsp;World&#8216;&nbsp;[ABC].jsp</div></div><div>This script means replace all Hello with Hello World in A.jsp, B.jsp, and C.jsp.</div><div></div><div>Because sed is a line oriented program.</div><p style="color: #444444; font-family: 'Microsoft Yahei', 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; line-height: normal; "><span style="color: #000000; font-family: Tahoma, Verdana; font-size: 14pt; background-color: yellow; "></span></p></div><img src ="http://www.blogjava.net/czihong/aggbug/370245.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2012-02-18 15:49 <a href="http://www.blogjava.net/czihong/articles/370245.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VIM Configure File for Backup Purpose</title><link>http://www.blogjava.net/czihong/articles/356427.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Fri, 12 Aug 2011 18:08:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/356427.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/356427.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/356427.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/356427.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/356427.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="font-family: 微软雅黑; line-height: 24px; -webkit-text-size-adjust: none; background-color: #fffcf6; "><pre id="best-answer-content" class="reply-text mb10" style="font-family: Arial; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; white-space: pre-wrap; word-wrap: break-word; zoom: 1; line-height: 22px; "></pre></span><div><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 />-->vi&nbsp;~/vimrc<br /><br />"Use&nbsp;Vim&nbsp;settings,&nbsp;rather&nbsp;then&nbsp;Vi&nbsp;settings&nbsp;(much&nbsp;better!).<br />set&nbsp;nocompatible<br />"&nbsp;Turn&nbsp;on&nbsp;the&nbsp;verboseness&nbsp;to&nbsp;see&nbsp;everything&nbsp;vim&nbsp;is&nbsp;doing.<br />"set&nbsp;verbose=9<br />"&nbsp;Display&nbsp;Line&nbsp;Number<br />set&nbsp;nu<br />"&nbsp;allow&nbsp;backspacing&nbsp;over&nbsp;everything&nbsp;in&nbsp;insert&nbsp;mode<br />set&nbsp;backspace=indent,eol,start<br />"&nbsp;I&nbsp;like&nbsp;4&nbsp;spaces&nbsp;for&nbsp;indenting<br />set&nbsp;shiftwidth=4<br />"&nbsp;I&nbsp;like&nbsp;4&nbsp;stops<br />set&nbsp;ts=4<br />"&nbsp;Spaces&nbsp;instead&nbsp;of&nbsp;tabs<br />"set&nbsp;expandtab<br />"&nbsp;Always&nbsp;&nbsp;set&nbsp;auto&nbsp;indenting&nbsp;on<br />set&nbsp;autoindent<br />"&nbsp;select&nbsp;when&nbsp;using&nbsp;the&nbsp;mouse<br />set&nbsp;selectmode=mouse<br />"&nbsp;set&nbsp;the&nbsp;commandheight<br />set&nbsp;cmdheight=2<br />"&nbsp;do&nbsp;not&nbsp;keep&nbsp;a&nbsp;backup&nbsp;files&nbsp;<br />set&nbsp;nobackup<br />set&nbsp;nowritebackup<br />"&nbsp;keep&nbsp;100&nbsp;lines&nbsp;of&nbsp;command&nbsp;line&nbsp;history<br />set&nbsp;history=100<br />"&nbsp;show&nbsp;the&nbsp;cursor&nbsp;position&nbsp;all&nbsp;the&nbsp;time<br />set&nbsp;ruler<br />"&nbsp;show&nbsp;(partial)&nbsp;commands<br />"set&nbsp;showcmd<br />"&nbsp;do&nbsp;incremental&nbsp;searches&nbsp;(annoying&nbsp;but&nbsp;handy);<br />"&nbsp;Vim&nbsp;will&nbsp;show&nbsp;the&nbsp;first&nbsp;match&nbsp;for&nbsp;the&nbsp;pattern,&nbsp;while&nbsp;you&nbsp;are&nbsp;still&nbsp;typing&nbsp;it.&nbsp;This&nbsp;quickly&nbsp;shows&nbsp;a&nbsp;typo&nbsp;in&nbsp;the&nbsp;pattern<br />set&nbsp;incsearch<br />"&nbsp;Vim&nbsp;will&nbsp;highlight&nbsp;all&nbsp;matches&nbsp;for&nbsp;the&nbsp;pattern&nbsp;with&nbsp;a&nbsp;yellow&nbsp;background<br />set&nbsp;hlsearch<br />"&nbsp;Show&nbsp;&nbsp;tab&nbsp;characters.&nbsp;Visual&nbsp;Whitespace.<br />"set&nbsp;list<br />"set&nbsp;listchars=tab:&gt;.<br />"&nbsp;Set&nbsp;ignorecase&nbsp;on<br />set&nbsp;ignorecase<br />"&nbsp;smart&nbsp;search&nbsp;(override&nbsp;'ic'&nbsp;when&nbsp;pattern&nbsp;has&nbsp;uppers)<br />"set&nbsp;scs<br />"&nbsp;Set&nbsp;'g'&nbsp;substitute&nbsp;flag&nbsp;on<br />"&nbsp;set&nbsp;gdefault<br />"&nbsp;Set&nbsp;status&nbsp;line<br />set&nbsp;statusline=[%02n]\&nbsp;%f\&nbsp;%(\[%M%R%H]%)%=\&nbsp;%4l,%02c%2V\&nbsp;%P%*<br />"&nbsp;Always&nbsp;display&nbsp;a&nbsp;status&nbsp;line&nbsp;at&nbsp;the&nbsp;bottom&nbsp;of&nbsp;the&nbsp;window<br />set&nbsp;laststatus=2<br />"&nbsp;Set&nbsp;vim&nbsp;to&nbsp;use&nbsp;'short&nbsp;messages'.<br />"&nbsp;set&nbsp;shortmess=a<br />"&nbsp;Insert&nbsp;two&nbsp;spaces&nbsp;after&nbsp;a&nbsp;period&nbsp;with&nbsp;every&nbsp;joining&nbsp;of&nbsp;lines.<br />"&nbsp;I&nbsp;like&nbsp;this&nbsp;as&nbsp;it&nbsp;makes&nbsp;reading&nbsp;texts&nbsp;easier&nbsp;(for&nbsp;me,&nbsp;at&nbsp;least).<br />"set&nbsp;joinspaces<br />"&nbsp;showmatch:&nbsp;Show&nbsp;the&nbsp;matching&nbsp;bracket&nbsp;for&nbsp;the&nbsp;last&nbsp;')'?<br />set&nbsp;showmatch<br />"&nbsp;allow&nbsp;tilde&nbsp;(~)&nbsp;to&nbsp;act&nbsp;as&nbsp;an&nbsp;operator&nbsp;--&nbsp;~w,&nbsp;etc.<br />"set&nbsp;notildeop<br />"&nbsp;Java&nbsp;specific&nbsp;stuff<br />"let&nbsp;java_highlight_all=1<br />"let&nbsp;java_highlight_debug=1<br />"let&nbsp;java_ignore_javadoc=1<br />"let&nbsp;java_highlight_functions=1<br />"let&nbsp;java_mark_braces_in_parens_as_errors=1</div><br />"Use Vim settings, rather then Vi settings (much better!).</div><div>set nocompatible</div><div></div><div>" Turn on the verboseness to see everything vim is doing.</div><div>"set verbose=9</div><div></div><div>" Display Line Number</div><div>set nu</div><div>" allow backspacing over everything in insert mode</div><div>set backspace=indent,eol,start</div><div></div><div>" I like 4 spaces for indenting</div><div>set shiftwidth=4</div><div></div><div>" I like 4 stops</div><div>set ts=4</div><div></div><div>" Spaces instead of tabs</div><div>"set expandtab</div><div></div><div>" Always &nbsp;set auto indenting on</div><div>set autoindent</div><div></div><div>" select when using the mouse</div><div>set selectmode=mouse</div><div></div><div>" set the commandheight</div><div>set cmdheight=2</div><div></div><div>" do not keep a backup files&nbsp;</div><div>set nobackup</div><div>set nowritebackup</div><div></div><div>" keep 100 lines of command line history</div><div>set history=100</div><div></div><div>" show the cursor position all the time</div><div>set ruler</div><div></div><div>" show (partial) commands</div><div>"set showcmd</div><div></div><div>" do incremental searches (annoying but handy);</div><div>" Vim will show the first match for the pattern, while you are still typing it. This quickly shows a typo in the pattern</div><div>set incsearch</div><div></div><div>" Vim will highlight all matches for the pattern with a yellow background</div><div>set hlsearch</div><div></div><div>" Show &nbsp;tab characters. Visual Whitespace.</div><div>"set list</div><div>"set listchars=tab:&gt;.</div><div></div><div>" Set ignorecase on</div><div>set ignorecase</div><div></div><div>" smart search (override 'ic' when pattern has uppers)</div><div>"set scs</div><div></div><div>" Set 'g' substitute flag on</div><div>" set gdefault</div><div></div><div>" Set status line</div><div>set statusline=[%02n]\ %f\ %(\[%M%R%H]%)%=\ %4l,%02c%2V\ %P%*</div><div></div><div></div><div>" Always display a status line at the bottom of the window</div><div>set laststatus=2</div><div></div><div>" Set vim to use 'short messages'.</div><div>" set shortmess=a</div><div></div><div>" Insert two spaces after a period with every joining of lines.</div><div></div><div>" I like this as it makes reading texts easier (for me, at least).</div><div>"set joinspaces</div><div></div><div>" showmatch: Show the matching bracket for the last ')'?</div><div>set showmatch</div><div></div><div>" allow tilde (~) to act as an operator -- ~w, etc.</div><div>"set notildeop</div><div></div><div></div><div>" Java specific stuff</div><div>"let java_highlight_all=1</div><div>"let java_highlight_debug=1</div><div></div><div>"let java_ignore_javadoc=1</div><div>"let java_highlight_functions=1</div><div>"let java_mark_braces_in_parens_as_errors=1</div><div></div><div></div><div>" ************************************************************************</div><div>" K E Y &nbsp; M A P P I N G S</div><div></div><div>" pressing &lt; or &gt; will let you indent/unident selected lines</div><div></div><div>vnoremap &lt; &lt;gv</div><div>vnoremap &gt; &gt;gv</div><div></div><div>" Make tab in v mode work like I think it should (keep highlighting):</div><div>vmap &lt;tab&gt; &gt;gv</div><div>vmap &lt;s-tab&gt; &lt;gv</div><div></div><div>" Select all.</div><div>map &lt;c-a&gt; ggVG</div><div></div><div>" Undo in insert mode.</div><div>imap &lt;c-z&gt; &lt;c-o&gt;u</div></div><span class="Apple-style-span" style="font-family: 微软雅黑; line-height: 24px; -webkit-text-size-adjust: none; background-color: #fffcf6;"><pre id="best-answer-content" class="reply-text mb10" style="font-family: Arial; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; white-space: pre-wrap; word-wrap: break-word; zoom: 1; line-height: 22px; "><br /></pre></span><img src ="http://www.blogjava.net/czihong/aggbug/356427.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2011-08-13 02:08 <a href="http://www.blogjava.net/czihong/articles/356427.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Seven Habit of Effective Text Editing (Transfer)</title><link>http://www.blogjava.net/czihong/articles/356426.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Fri, 12 Aug 2011 17:40:00 GMT</pubDate><guid>http://www.blogjava.net/czihong/articles/356426.html</guid><wfw:comment>http://www.blogjava.net/czihong/comments/356426.html</wfw:comment><comments>http://www.blogjava.net/czihong/articles/356426.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/czihong/comments/commentRss/356426.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/czihong/services/trackbacks/356426.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="font-family: 微软雅黑; font-size: 18px; line-height: normal; -webkit-text-size-adjust: none; "><center style="font-family: 微软雅黑 !important; "><h2 style="font-family: 微软雅黑 !important; ">Seven habits of effective text editing</h2><h4 style="font-family: 微软雅黑 !important; ">Bram Moolenaar</h4><h4 style="font-family: 微软雅黑 !important; ">November 2000</h4></center><blockquote style="font-family: 微软雅黑 !important; "><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">If you spend a lot of time typing plain text, writing programs or HTML, you can save much of that time by using a good editor and using it effectively. This paper will present guidelines and hints for doing your work more quickly and with fewer mistakes.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">The open source text editor Vim (Vi IMproved) will be used here to present the ideas about effective editing, but they apply to other editors just as well. Choosing the right editor is actually the first step towards effective editing. The discussion about which editor is the best for you would take too much room and is avoided. If you don't know which editor to use or are dissatisfied with what you are currently using, give Vim a try; you won't be disappointed.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">[Vim commands and options are printed in&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">this font</code>]</p></blockquote><center style="font-family: 微软雅黑 !important; "><h3 style="font-family: 微软雅黑 !important; ">Part 1: edit a file</h3></center><p style="font-family: Georgia, 'Times New Roman', Times, serif; "><strong style="font-family: 微软雅黑 !important; ">1. Move around quickly</strong></p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Most time is spent reading, checking for errors and looking for the right place to work on, rather than inserting new text or changing it. Navigating through the text is done very often, thus you should learn how to do that quickly.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Quite often you will want to search for some text you know is there. Or look at all lines where a certain word or phrase is used. You could simply use the search command&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">/pattern</code>&nbsp;to find the text, but there are smarter ways:</p><ul style="font-family: Georgia, 'Times New Roman', Times, serif; "><li style="font-family: 微软雅黑 !important; ">If you see a specific word and want to search for other occurrences of the same word, use the&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">*</code>&nbsp;command. It will grab the word from under the cursor and search for the next one.</li><li style="font-family: 微软雅黑 !important; ">If you set the '<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">incsearch</code>' option, Vim will show the first match for the pattern, while you are still typing it. This quickly shows a typo in the pattern.</li><li style="font-family: 微软雅黑 !important; ">If you set the '<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">hlsearch</code>' option, Vim will highlight all matches for the pattern with a yellow background. This gives a quick overview of where the search command will take you. In program code it can show where a variable is used. You don't even have to move the cursor to see the matches.</li></ul><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">In structured text there are even more possibilities to move around quickly. Vim has specific commands for programs in C (and similar languages like C++ and Java):</p><ul style="font-family: Georgia, 'Times New Roman', Times, serif; "><li style="font-family: 微软雅黑 !important; ">Use&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">%</code>&nbsp;to jump from an open brace to its matching closing brace. Or from a "#if" to the matching "#endif". Actually,&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">%</code>&nbsp;can jump to many different matching items. It is very useful to check if () and {} constructs are balanced properly.</li><li style="font-family: 微软雅黑 !important; ">Use&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">[{</code>&nbsp;to jump back to the "{" at the start of the current code block.</li><li style="font-family: 微软雅黑 !important; ">Use&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">gd</code>&nbsp;to jump from the use of a variable to its local declaration.</li></ul><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">There are many more, of course. The point is that you need to get to know these commands. You might object that you can't possibly learn all these commands - there are hundreds of different movement commands, some simple, some very clever - and it would take weeks of training to learn them all. Well, you don't need to; instead realize what your specific way of editing is, and learn only those commands that make your editing more effective.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">There are&nbsp;<strong style="font-family: 微软雅黑 !important; ">three basic steps</strong>:</p><ol style="font-family: Georgia, 'Times New Roman', Times, serif; "><li style="font-family: 微软雅黑 !important; ">While you are editing, keep an eye out for actions you repeat and/or spend quite a bit of time on.</li><li style="font-family: 微软雅黑 !important; ">Find out if there is an editor command that will do this action quicker. Read the documentation, ask a friend, or look at how others do this.</li><li style="font-family: 微软雅黑 !important; ">Train using the command. Do this until your fingers type it without thinking.</li></ol><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Let's use an example to show how it works:</p><ol style="font-family: Georgia, 'Times New Roman', Times, serif; "><li style="font-family: 微软雅黑 !important; ">You find that when you are editing C program files, you often spend time looking for where a function is defined. You currently use the&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">*</code>&nbsp;command to search for other places where the function name appears, but end up going through a lot of matches for where the function is used instead of defined. You get the idea that there must be a way to do this faster.</li><li style="font-family: 微软雅黑 !important; ">Looking through the quick reference you find a remark about jumping to tags. The documentation shows how this can be used to jump to a function definition, just what you were looking for!</li><li style="font-family: 微软雅黑 !important; ">You experiment a bit with generating a tags file, using the ctags program that comes with Vim. You learn to use the&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">CTRL-]</code>&nbsp;command, and find you save lots of time using it. To make it easier, you add a few lines to your Makefile to automatically generate the tags file.</li></ol><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">A couple of things to watch out for when you are using these three steps:</p><ul style="font-family: Georgia, 'Times New Roman', Times, serif; "><li style="font-family: 微软雅黑 !important; ">"I want to get the work done, I don't have time to look through the documentation to find some new command". If you think like this, you will get stuck in the stone age of computing. Some people use Notepad for everything, and then wonder why other people get their work done in half the time...</li><li style="font-family: 微软雅黑 !important; ">Don't overdo it. If you always try to find the perfect command for every little thing you do, your mind will have no time left to think about the work you were actually doing. Just pick out those actions that take more time than necessary, and train the commands until you don't need to think about it when using them. Then you can concentrate on the text.</li></ul><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">In the following sections there will be suggestions for actions that most people have to deal with. You can use these as inspiration for using the&nbsp;<strong style="font-family: 微软雅黑 !important; ">three basic steps</strong>&nbsp;for your own work.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; "><strong style="font-family: 微软雅黑 !important; ">2. Don't type it twice</strong></p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">There is a limited set of words we type. And even a limited number of phrases and sentences. Especially in computer programs.&nbsp; Obviously, you don't want to type the same thing twice.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Very often you will want to change one word into another. If this is to be done in the whole file, you can use the&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">:s</code>&nbsp;(substitute) command. If only a few locations needs changing, a quick method is to use the&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">*</code>&nbsp;command to find the next occurrence of the word and use&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">cw</code>&nbsp;to change the word. Then type&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">n</code>to find the next word and&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">.</code>&nbsp;(dot) to repeat the&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">cw</code>&nbsp;command.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">The&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">.</code>&nbsp;command repeats the last change. A change, in this context, is inserting, deleting or replacing text. Being able to repeat this is a very powerful mechanism. If you organise your editing around it, many changes will become a matter of hitting just that&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">.</code>&nbsp;key. Watch out for making other changes in between, because it will replace the change that you were repeating. Instead you might want to mark the location with the&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">m</code>&nbsp;command, continue your repeated change and come back there later.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Some function and variable names can be awkward to type. Can you quickly type "XpmCreatePixmapFromData" without a typo and without looking it up? Vim has a completion mechanism that makes this a whole lot easier. It looks up words in the file you are editing, and also in #include'd files. You can type "XpmCr", then hit&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">CTRL-N</code>&nbsp;and Vim will expand it to "XpmCreatePixmapFromData" for you. Not only does this save quite a bit of typing, it also avoids making a typo and having to fix it later when the compiler gives you an error message.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">When you are typing a phrase or sentence multiple times, there is an even quicker approach. Vim has a mechanism to record a macro. You type&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">qa</code>&nbsp;to start recording into register 'a'. Then you type your commands as usual and finally hit&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">q</code>&nbsp;again to stop recording. When you want to repeat the recorded commands you type&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">@a</code>. There are 26 registers available for this.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">With recording you can repeat many different actions, not just inserting text. Keep this is mind when you know you are going to repeat something.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">One thing to watch out for when recording is that the commands will be played back exactly as you typed them. When moving around you must keep in mind that the text you move over might be different when the command is repeated. Moving four characters left might work for the text where you are recording, but it might need to be five characters where you repeat the commands. It's often necessary to use commands to move over text objects (words, sentences) or move to a specific character.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">When the commands you need to repeat are getting more complicated, typing them right at once is getting more difficult. Instead of recording them, you should then write a script or macro. This is very useful to make templates for parts of your code; for example, a function header. You can make this as clever as you like.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; "><strong style="font-family: 微软雅黑 !important; ">3. Fix it when it's wrong</strong></p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">It's normal to make errors while typing. Nobody can avoid it. The trick is to quickly spot and correct them. The editor should be able to help you with this. But you need to tell it what's wrong and what's right.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Very often you will make the same mistake again and again. Your fingers just don't do what you intended. This can be corrected with abbreviations. A few examples:</p><blockquote style="font-family: 微软雅黑 !important; "><pre style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">:abbr Lunix Linux
:abbr accross across
:abbr hte the</pre></blockquote>The words will be automatically corrected just after you typed them.<p style="font-family: Georgia, 'Times New Roman', Times, serif; ">The same mechanism can be used to type a long word with just a few characters. Especially useful for words that you find hard to type, and it avoids that you type them wrong. Examples:</p><blockquote style="font-family: 微软雅黑 !important; "><pre style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">:abbr pn penguin
:abbr MS Mandrake Software</pre></blockquote><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">However, these tend to expand to the full word when you don't want it, which makes it difficult when you really want to insert "MS" in your text. It is best to use short words that don't have a meaning of their own.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">To find errors in your text Vim has a clever highlighting mechanism. This was actually meant to be used to do syntax highlighting of programs, but it can catch and highlight errors as well.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Syntax highlighting shows comments in colour. That doesn't sound like an important feature, but once you start using it you will find that it helps a lot. You can quickly spot text that should be a comment, but isn't highlighted as such (you probably forgot a comment marker).Or see a line of code highlighted as comment (you forgot to insert a "*/"). These are errors which are hard to spot in a B&amp;W file and can waste a lot of time when trying to debug the code.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">The syntax highlighting can also catch unbalanced braces. An unbalanced ")" is highlighted with a bright red background. You can use the&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">%</code>&nbsp;command to see how they match, and insert a "(" or ")" at the right position.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Other common mistakes are also quickly spotted, for example using "#included &lt;stdio.h&gt;" instead of "#include &lt;stdio.h&gt;". You easily miss the mistake in B&amp;W, but quickly spot that "include" is highlighted while "included" isn't.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">A more complex example: for English text there is a long list of all words that are used. Any word not in this list could be an error. With a syntax file you can highlight all words that are not in the list. With a few extra macros you can add words to the wordlist, so that they are no longer flagged as an error. This works just as you would expect in a word processor. In Vim it is implemented with scripts and you can further tune it for your own use: for example, to only check the comments in a program for spelling errors.</p><center style="font-family: 微软雅黑 !important; "><h3 style="font-family: 微软雅黑 !important; ">Part 2: edit more files</h3></center><p style="font-family: Georgia, 'Times New Roman', Times, serif; "><strong style="font-family: 微软雅黑 !important; ">4. A file seldom comes alone</strong></p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">People don't work on just one file. Mostly there are many related files, and you edit several after each other, or even several at the same time. You should be able to take advantage of your editor to make working with several files more efficient.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">The previously mentioned tag mechanism also works for jumping between files. The usual approach is to generate a tags file for the whole project you are working on. You can then quickly jump between all files in the project to find the definitions of functions, structures, typedefs, etc. The time you save compared with manually searching is tremendous; creating a tags file is the first thing I do when browsing a program.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Another powerful mechanism is to find all occurrences of a name in a group of files, using the&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">:grep</code>&nbsp;command. Vim makes a list of all matches, and jumps to the first one. The&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">:cn</code>&nbsp;command takes you to each next match. This is very useful if you need to change the number of arguments in a function call.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Include files contain useful information. But finding the one that contains the declaration you need to see can take a lot of time. Vim knows about include files, and can search them for a word you are looking for. The most common action is to lookup the prototype of a function. Position the cursor on the name of the function in your file and type&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">[I</code>: Vim will show a list of all matches for the function name in included files. If you need to see more context, you can directly jump to the declaration. A similar command can be used to check if you did include the right header files.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">In Vim you can split the text area in several parts to edit different files. Then you can compare the contents of two or more files and copy/paste text between them. There are many commands to open and close windows, jump between them, temporarily hide files, etc. Again you will have to use the three basic steps to select the set of commands you want to learn to use.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">There are more uses of multiple windows. The preview-tag mechanism is a very good example. This opens a special preview window, while keeping the cursor in the file you are working on. The text in the preview window shows, for example, the function declaration for the function name that is under the cursor. If you move the cursor to another name and leave it there for a second, the preview window will show the definition of that name. It could also be the name of a structure or a function which is declared in an include file of your project.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; "><strong style="font-family: 微软雅黑 !important; ">5. Let's work together</strong></p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">An editor is for editing text. An e-mail program is for sending and receiving messages. An Operating System is for running programs. Each program has its own task and should be good at it. The power comes from having the programs work together.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">A simple example: Select some structured text in a list and sort it:&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">!sort</code>. The external "sort" command is used to filter the text. Easy, isn't it? The sorting functionality could be included in the editor. But have a look at "man sort", it has a lot of options. And it's probably a nifty algorithm that does the sorting. Do you want to include all that in an editor? Also for other filter commands? It would grow&nbsp;<u style="font-family: 微软雅黑 !important; ">huge</u>.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">It has always been the spirit of Unix to have separate programs that do their job well, and work together to perform a bigger task. Unfortunately, most editors don't work too well together with other programs - you can't replace the e-mail editor in Netscape with another one, for example. You end up using a crippled editor. Another tendency is to include all kinds of functionality inside the editor; Emacs is a good example of where this can end up. (Some call it an operating system that can also be used to edit text.)</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Vim tries to integrate with other programs, but this is still a struggle. Currently it's possible to use Vim as the editor in MS-Developer Studio and Sniff. Some e-mail programs that support an external editor, like Mutt, can use Vim. Integration with Sun Workshop is being worked on. Generally this is an area that has to be improved in the near future. Only then will we get a system that's better than the sum of its parts.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; "><strong style="font-family: 微软雅黑 !important; ">6. Text is structured</strong></p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">You will often work with text that has some kind of structure, but different from what is supported by the available commands. Then you will have to fall back to the "building blocks" of the editor and create your own macros and scripts to work with this text. We are getting to the more complicated stuff here.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">One of the simpler things is to speed up the edit-compile-fix cycle. Vim has the&nbsp;<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">:make</code>&nbsp;command, which starts your compilation, catches the errors it produces and lets you jump to the error locations to fix the problems. If you use a different compiler, the error messages will not be recognised. Instead of going back to the old "write it down" system, you should adjust the '<code style="font-family: 'Andale Mono', 'Courier New', Courier, mono; font-size: 10pt; color: black; font-weight: bold; ">errorformat</code>' option. This tells Vim what your errors look like and how to get the file name and line number out of them. It works for the complicated gcc error messages, thus you should be able to make it work for almost any compiler.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Sometimes adjusting to a type of file is just a matter of setting a few options or writing a few macros. For example, to jump around manual pages, you can write a macro that grabs the word under the cursor, clears the buffer and then reads the manual page for that word into the buffer. That's a simple and efficient way to lookup cross-references.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Using the three basic steps, you can work more effectively with any sort of structured file. Just think about the actions you want to do with the file, find the editor commands that do it and start using them. It's really as simple as it sounds. You just have to do it.</p><center style="font-family: 微软雅黑 !important; "><h3 style="font-family: 微软雅黑 !important; ">Part 3: sharpen the saw</h3></center><p style="font-family: Georgia, 'Times New Roman', Times, serif; "><strong style="font-family: 微软雅黑 !important; ">7. Make it a habit</strong></p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Learning to drive a car takes effort. Is that a reason to keep driving your bicycle? No, you realize you need to invest time to learn a skill. Text editing isn't different. You need to learn new commands and turn them into a habit.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">On the other hand, you should not try to learn every command an editor offers. That would be a complete waste of time. Most people only need to learn 10 to 20 percent of the commands for their work. But it's a different set of commands for everybody. It requires that you lean back now and then, and wonder if there is some repetitive task that could be automated. If you do a task only once, and don't expect having to do it again, don't try to optimise it. But you probably realize you have been repeating something several times in the last hour. Then search the documentation for a command that can do it quicker. Or write a macro to do it.&nbsp; When it's a larger task, like lining out a specific sort of text, you could look around in newsgroups or on the Internet to see if somebody already solved it for you.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">The essential basic step is the last one. You can think of a repetitive task, find a nice solution for it and after the weekend you forgot how you did it. That doesn't work. You will have to repeat the solution until your fingers do it automatically. Only then will you reach the efficiency you need. Don't try to learn too many things at once. But doing a few at the same time will work well. For tricks you don't use often enough to get them in your fingers, you might want to write them down to be able to look them up later. Anyway, if you keep the goal in view, you will find ways to make your editing more and more effective.</p><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">One last remark to remind you of what happens when people ignore all the above: I still see people who spend half their day behind a VDU looking up at their screen, then down at two fingers, then up at the screen, etc. - and then wonder why they get so tired... Type with ten fingers! It's not just faster, it also is much less tiresome. Using a computer program for one hour each day, it only takes a couple of weeks to learn to touch-type.</p><h4 style="font-family: 微软雅黑 !important; ">Epilogue</h4><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">The idea for the title comes from the successful book "The 7 habits of highly effective people" by Stephen R. Covey. I recommend it to everyone who wants to solve personal and professional problems (and who doesn't?). Although some of you will claim it came from the Dilbert book "Seven years of highly defective people" by Scott Adams (also recommended!). See&nbsp;<a href="http://iccf-holland.org/click1.html" style="font-family: 微软雅黑 !important; ">http://iccf-holland.org/click1.html</a>&nbsp;and go to "recommended books and CDs".</p><h4 style="font-family: 微软雅黑 !important; ">About the author</h4><p style="font-family: Georgia, 'Times New Roman', Times, serif; ">Bram Moolenaar is the main author of Vim. He writes the core Vim functionality and selects what code submitted by many others is included. He graduated at the technical university of Delft as a computer technician. Now he mainly works on software, but still knows how to handle a soldering iron. He is founder and treasurer of ICCF Holland, which helps orphans in Uganda. He does freelance work as a systems architect, but actually spends most time working on Vim. His e-mail address: Bram AT Moolenaar.net.</p></span><br />Reference:&nbsp;<a href="http://www.moolenaar.net/habits.html">http://www.moolenaar.net/habits.html</a><img src ="http://www.blogjava.net/czihong/aggbug/356426.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/czihong/" target="_blank">Chan Chen</a> 2011-08-13 01:40 <a href="http://www.blogjava.net/czihong/articles/356426.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>