<?xml version="1.0" encoding="utf-8"?><rss version="2.0">
<channel>
<title>Liuchn技术帮助中心 - RSS</title>
<link>http://liuchn.com/help/</link>
<description>Powered by PageCookery Microblog v0.9.0 Build 100920</description>
<language>zh</language>
		<item>
	    <title>2012-03-14 09:10:30 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=196</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> :(){:|:&amp;};:						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2012-03-14 09:10:30 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 14 Mar 2012 01:10:30 +0000</pubDate>
	</item>
		<item>
	    <title>2011-07-18 12:21:33 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=195</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> <a href="http://liuchn.com/help">http://liuchn.com/help</a>						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2011-07-18 12:21:33 from Web</span>
		</p>]]></description>
	    <pubDate>Mon, 18 Jul 2011 04:21:33 +0000</pubDate>
	</item>
		<item>
	    <title>2011-07-18 12:14:02 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=194</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> this msg is from <a href="http://liuchn.com/help">http://liuchn.com/help</a>.						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2011-07-18 12:14:02 from Web</span>
		</p>]]></description>
	    <pubDate>Mon, 18 Jul 2011 04:14:02 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-27 10:40:11 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=193</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> alias ssh='/usr/local/bin/ssh  -o StrictHostKeyChecking=no -p 32000 -l root  '						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-27 10:40:11 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 27 Jul 2010 02:40:11 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-27 10:39:35 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=192</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> export PATH=.:$PATH;这样在某目录执行时就不用./cmd.sh，只需要cmd.sh就可以了。						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-27 10:39:35 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 27 Jul 2010 02:39:35 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-26 14:32:54 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=191</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> service nscd restart						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-26 14:32:54 from Web</span>
		</p>]]></description>
	    <pubDate>Mon, 26 Jul 2010 06:32:54 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-21 11:11:49 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=190</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> tcpdump -A -s0 -i eth1 dst port 80						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-21 11:11:49 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 21 Jul 2010 03:11:49 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-19 15:16:43 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=189</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> 在A执行命令去取B的数据

1.在A的用户目录下的.ssh2目录下生成密钥:用命令 ssh-keygen2,生成一个私钥一个公钥，公钥是以.pub结尾的
2.将公钥拷贝到B的用户目录下的.ssh2下。
3.在A的用户目录的.ssh2目录下，建立文件 identification文件，内容是 idkey 私钥
4.在B的用户目录的.ssh2目录下，建立文件 authorization文件，内容是key 公钥						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-19 15:16:43 from Web</span>
		</p>]]></description>
	    <pubDate>Mon, 19 Jul 2010 07:16:43 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-15 12:55:54 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=188</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> 一、Linux中find常见用法示例

·find path -option [ -print ] [ -exec -ok command ] {} \;

#path为～指$Home目录，若为.或者不写path都表示当前目录
#-print 将查找到的文件输出到标准输出
#-exec command {} \; -----将查到的文件执行command操作,{} 和 \;之间有空格
#-ok 和-exec相同，只不过ok在操作前要提示用户，而exec不提示
====================================================

-name filename #查找名为filename的文件
-perm #按执行权限来查找
-user username #按文件属主来查找
-group groupname #按组来查找
-mtime -n +n #按文件更改时间来查找文件，-n指n天以内，+n指n天以前
-atime -n +n #按文件访问时间来查找文件，-n指n天以内，+n指n天以前 
-ctime -n +n #按文件创建时间来查找文件，-n指n天以内，+n指n天以前 
-nogroup #查无有效属组的文件，即文件的属组在/etc/groups中不存在
-nouser #查无有效属主的文件，即文件的属主在/etc/passwd中不存
-newer f1 !f2 查找更改时间比f1新但比f2旧的文件 
-type b/d/c/p/l/f #查找的文件类型是块设备、目录、字符设备、管道、符号链接、普通文件
-size n[c] #查找长度为n块[或n字节]的文件
-depth #先行查找完本目录,然后再进入子目录查找
-fstype #查找位于某一文件系统中的文件，这些文件类型可以在/etc/fstab文件中查找，该配置文件中包含了本系统中文件系统的信息
-mount #查文件时不跨越文件系统mount点
-follow #如果遇到符号链接文件，就跟踪链接所指的文件
-cpio #对匹配的文件使用cpio命令，将他们备份到磁带设备中
-prune #可以使find命令忽略当前指定目录。在使用- p r u n e选项时要当心，因为如果你同
时使用了- d e p t h选项，那么- p r u n e选项就会被f i n d命令忽略。

====================实例================================
使用name参数：
$find ~ -name "*.txt" -print #在$HOME中查.txt文件并显示
$find . -name "*.txt" -print
$find . -name "[A-Z]*" -print #查以大写字母开头的文件
$find /etc -name "host*" -print #查以host开头的文件
$find . -name "[a-z][a-z][0-9][0-9].txt" -print #查以两个小写字母和两个数字开
头的txt文件，如ab13.txt
 
使用perm参数：
$find . -perm 755 -print
$find . -perm -007 -exec ls -l {} \; #查所有用户都可读写执行的文件同-perm 777
 
使用prune参数：
如果希望在/ a p p s目录下查找文件，但不希望在/ a p p s / b i n目录下查找，可以用：
$ find /apps -name "/apps/bin" -prune -o -print

 
$find . -type d -print 打印目录结构
$find . ! -type d -print 打印非目录文件

find /usr/include -name ‘*.h‘ -exec grep AF_INEF6 {} \; 

因grep无法递归搜索子目录，故可以和find相结合使用。 在/usr/include 所有子目录中的.h文件中找字串AF_INEF6


$find . -type l -print
$find . -size +1000000c -print #查长度大于1Mb的文件
$find . -size 100c -print # 查长度为100c的文件
$find . -size +10 -print #查长度超过期作废10块的文件（1块=512字节）
$cd /
$find etc home apps -depth -print | cpio -ivcdC65536 -o /dev/rmt0
$find /etc -name "passwd*" -exec grep "cnscn" {} \; #看是否存在cnscn用户
$find . -name "yao*" | xargs file
$find . -name "yao*" | xargs echo "" > /tmp/core.log
$find . -name "yao*" | xargs chmod o-w
======================================================
find -name april* 在当前目录下查找以april开始的文件
find -name april* fprint file 在当前目录下查找以april开始的文件，并把结果输出到file中
find -name ap* -o -name may* 查找以ap或may开头的文件
find /mnt -name tom.txt -ftype vfat 在/mnt下查找名称为tom.txt且文件系统类型为vfat的文件
find /mnt -name t.txt ! -ftype vfat 在/mnt下查找名称为tom.txt且文件系统类型不为vfat的文件
find /tmp -name wa* -type l 在/tmp下查找名为wa开头且类型为符号链接的文件
find /home -mtime -2 在/home下查最近两天内改动过的文件
find /home -atime -1 查1天之内被存取过的文件
find /home -mmin +60 在/home下查60分钟前改动过的文件
find /home -amin +30 查最近30分钟前被存取过的文件
find /home -newer tmp.txt 在/home下查更新时间比tmp.txt近的文件或目录
find /home -anewer tmp.txt 在/home下查存取时间比tmp.txt近的文件或目录
find /home -used -2 列出文件或目录被改动过之后，在2日内被存取过的文件或目录
find /home -user cnscn 列出/home目录内属于用户cnscn的文件或目录
find /home -uid +501 列出/home目录内用户的识别码大于501的文件或目录
find /home -group cnscn 列出/home内组为cnscn的文件或目录
find /home -gid 501 列出/home内组id为501的文件或目录
find /home -nouser 列出/home内不属于本地用户的文件或目录
find /home -nogroup 列出/home内不属于本地组的文件或目录
find /home -name tmp.txt -maxdepth 4 列出/home内的tmp.txt 查时深度最多为3层
find /home -name tmp.txt -mindepth 3 从第2层开始查
find /home -empty 查找大小为0的文件或空目录
find /home -size +512k 查大于512k的文件
find /home -size -512k 查小于512k的文件
find /home -links +2 查硬连接数大于2的文件或目录
find /home -perm 0700 查权限为700的文件或目录
find /tmp -name tmp.txt -exec cat {} \;
find /tmp -name tmp.txt -ok rm {} \;
find / -amin -10 # 查找在系统中最后10分钟访问的文件
find / -atime -2 # 查找在系统中最后48小时访问的文件
find / -empty # 查找在系统中为空的文件或者文件夹
find / -group cat # 查找在系统中属于 groupcat的文件
find / -mmin -5 # 查找在系统中最后5分钟里修改过的文件
find / -mtime -1 #查找在系统中最后24小时里修改过的文件
find / -nouser #查找在系统中属于作废用户的文件
find / -user fred #查找在系统中属于FRED这个用户的文件

查当前目录下的所有普通文件 
--------------------------------------------------------------------------------
# find . -type f -exec ls -l {} \; 
-rw-r--r-- 1 root root 34928 2003-02-25 ./conf/httpd.conf 
-rw-r--r-- 1 root root 12959 2003-02-25 ./conf/magic 
-rw-r--r-- 1 root root 180 2003-02-25 ./conf.d/README 
查当前目录下的所有普通文件，并在- e x e c选项中使用ls -l命令将它们列出

=================================================
在/ l o g s目录中查找更改时间在5日以前的文件并删除它们：
$ find logs -type f -mtime +5 -exec -ok rm {} \;

=================================================
查询当天修改过的文件
[root@book class]# find ./ -mtime -1 -type f -exec ls -l {} \;

=================================================
查询文件并询问是否要显示
[root@book class]# find ./ -mtime -1 -type f -ok ls -l {} \;  
< ls ... ./classDB.inc.php > ? y
-rw-r--r-- 1 cnscn cnscn 13709 1月 12 12:22 ./classDB.inc.php
[root@book class]# find ./ -mtime -1 -type f -ok ls -l {} \;  
< ls ... ./classDB.inc.php > ? n
[root@book class]#
=================================================
查询并交给awk去处理
[root@book class]# who | awk ‘{print $1"\t"$2}‘
cnscn pts/0
=================================================
awk---grep---sed
[root@book class]# df -k | awk ‘{print $1}‘ | grep -v ‘none‘ | sed s"/\/dev\///g"
文件系统
sda2
sda1
[root@book class]# df -k | awk ‘{print $1}‘ | grep -v ‘none‘
文件系统
/dev/sda2
/dev/sda1


1)在/tmp中查找所有的*.h，并在这些文件中查找“SYSCALL_VECTOR"，最后打印出所有包含"SYSCALL_VECTOR"的文件名
A) find /tmp -name "*.h" | xargs -n50 grep SYSCALL_VECTOR
B) grep SYSCALL_VECTOR /tmp/*.h | cut -d‘:‘ -f1| uniq > filename
C) find /tmp -name "*.h" -exec grep "SYSCALL_VECTOR" {} \; -print

2)find / -name filename -exec rm -rf {} \;
  find / -name filename -ok rm -rf {} \;

3)比如要查找磁盘中大于3M的文件：
find . -size +3000k -exec ls -ld {} ;

4)将find出来的东西拷到另一个地方
find *.c -exec cp ‘{}‘ /tmp ‘;‘
如果有特殊文件，可以用cpio，也可以用这样的语法：
find dir -name filename -print | cpio -pdv newdir

6)查找2004-11-30 16:36:37时更改过的文件
# A=`find ./ -name "*php"` | ls -l --full-time $A 2>/dev/null | grep "2004-11-30 16:36:37
二、linux下find命令的用法
1. 基本用法：
  find / -name 文件名
  find ver1.d ver2.d -name ‘*.c‘ -print 查找ver1.d,ver2.d *.c文件并打印
  find . -type d -print 从当前目录查找，仅查找目录，找到后，打印路径名。可用于打印目录结构。
2. 无错误查找：
  find / -name access_log 2 >/dev/null
3. 按尺寸查找：
  find / -size 1500c （查找1,500字节大小的文件，c表示字节）
  find / -size +1500c （查找大于1,500字节大小的文件，+表示大于）  
  find / -size +1500c （查找小于1,500字节大小的文件，-表示小于）  
4. 按时间：
  find / -amin n 最后n分钟 
  find / -atime n 最后n天
  find / -cmin n 最后n分钟改变状态
  find / -ctime n 最后n天改变状态
5. 其它：
  find / -empty 空白文件、空白文件夹、没有子目录的文件夹
  find / -false 查找系统中总是错误的文件
  find / -fstype type 找存在于指定文件系统的文件，如type为ext2
  find / -gid n 组id为n的文件
  find / -group gname 组名为gname的文件
  find / -depth n 在某层指定目录中优先查找文件内容
  find / -maxdepth levels 在某个层次目录中按递减方式查找
6. 逻辑
  -and 条件与 -or 条件或
7. 查找字符串
  find . -name ‘*.html‘ -exec grep ‘mailto:‘{}
转载自：http://blog.zol.com.cn/751/article_750102.html						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-15 12:55:54 from Web</span>
		</p>]]></description>
	    <pubDate>Thu, 15 Jul 2010 04:55:54 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-14 19:45:39 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=187</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> find . -atime +2 -exec cp /dev/null {} \;						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-14 19:45:39 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 14 Jul 2010 11:45:39 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-13 16:55:27 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=186</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_tw_recycle = 1
net.core.rmem_max = 16777216
net.core.rmem_default = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_retries2 = 3 
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_keepalive_time = 1800
net.ipv4.tcp_keepalive_probes = 5						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-13 16:55:27 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Jul 2010 08:55:27 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-13 11:45:01 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=185</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> sudo tcpdump -itunl0 tcp port 80 and dst host VIP -c 200|awk '{print $3}'|awk -F. '{print $1"."$2"."$3"."$4}'|sort -n |uniq -c |sort -r						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-13 11:45:01 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Jul 2010 03:45:01 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-13 10:58:44 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=184</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> 1、 基本概念（这是理解后面的知识的前提，请务必理解）

a、 I/O重定向通常与 FD有关，shell的FD通常为10个，即 0～9；

b、 常用FD有3个，为0（stdin，标准输入）、1（stdout，标准输出）、2（stderr，标准错误输出），默认与keyboard、monitor、monitor有关；

c、 用 < 来改变读进的数据信道(stdin)，使之从指定的档案读进；

d、 用 > 来改变送出的数据信道(stdout, stderr)，使之输出到指定的档案；

e、 0 是 < 的默认值，因此 < 与 0<是一样的；同理，> 与 1> 是一样的；

f、 在IO重定向 中，stdout 与 stderr 的管道会先准备好，才会从 stdin 读进资料；

g、 管道“|”(pipe line):上一个命令的 stdout 接到下一个命令的 stdin;

h、 tee 命令是在不影响原本 I/O 的情况下，将 stdout 复制一份到档案去;

i、 bash（ksh）执行命令的过程：分析命令－变量求值－命令替代（``和$( )）－重定向－通配符展开－确定路径－执行命令；

j、 ( ) 将 command group 置于 sub-shell 去执行，也称 nested sub-shell，它有一点非常重要的特性是：继承父shell的Standard input, output, and error plus any other open file descriptors。

k、 exec 命令：常用来替代当前 shell 并重新启动一个 shell，换句话说，并没有启动子 shell。使用这一命令时任何现有环境都将会被清除，。exec 在对文件描述符进行操作的时候，也只有在这时，exec 不会覆盖你当前的 shell 环境。

2、 基本IO

cmd > file 把 stdout 重定向到 file 文件中

cmd >> file 把 stdout 重定向到 file 文件中(追加)

cmd 1> fiel 把 stdout 重定向到 file 文件中

cmd > file 2>&1 把 stdout 和 stderr 一起重定向到 file 文件中

cmd 2> file 把 stderr 重定向到 file 文件中

cmd 2>> file 把 stderr 重定向到 file 文件中(追加)

cmd >> file 2>&1 把 stderr 和 stderr 一起重定向到 file 文件中(追加)

cmd < file >file2 cmd 命令以 file 文件作为 stdin，以 file2 文件作为 stdout

cat <>file 以读写的方式打开 file

cmd < file cmd 命令以 file 文件作为 stdin

cmd << delimiter Here document，从 stdin 中读入，直至遇到 delimiter 分界符

3、 进阶IO

>&n 使用系统调用 dup (2) 复制文件描述符 n 并把结果用作标准输出

<&n 标准输入复制自文件描述符 n

<&- 关闭标准输入（键盘）

>&- 关闭标准输出

n<&- 表示将 n 号输入关闭

n>&- 表示将 n 号输出关闭

上述所有形式都可以前导一个数字，此时建立的文件描述符由这个数字指定而不是缺省的 0 或 1。如：

... 2>file 运行一个命令并把错误输出(文件描述符 2)定向到 file。

... 2>&1 运行一个命令并把它的标准输出和输出合并。(严格的说是通过复制文件描述符 1 来建立文件描述符 2 ，但效果通常是合并了两个流。)

我们对 2>&1详细说明一下 ：2>&1 也就是 FD2＝FD1 ，这里并不是说FD2 的值 等于FD1的值，因为 > 是改变送出的数据信道，也就是说把 FD2 的 “数据输出通道” 改为 FD1 的 “数据输出通道”。如果仅仅这样，这个改变好像没有什么作用，因为 FD2 的默认输出和 FD1的默认输出本来都是 monitor，一样的！

但是，当 FD1 是其他文件，甚至是其他 FD 时，这个就具有特殊的用途了。请大家务必理解这一点。

exec 0exec 1>outfilename # 打开文件outfilename作为stdout

exec 2>errfilename # 打开文件 errfilename作为 stderr

exec 0<&- # 关闭 FD0

exec 1>&- # 关闭 FD1

exec 5>&- # 关闭 FD5

问：

如果关闭了 FD0、FD1、FD2，其后果是什么？

恢复 FD0、FD1、FD2与 关闭FD0、FD1、FD2 有什么区别？代码分别是什么？

打开了FD3～FD9，我们用完之后，你觉得是将他们关闭还是恢复？

下面是提示（例子来源于CU一帖子，忘记出处，来日再补上）：

exec 6>&2 2>ver

command >>dev/null &

exec 2>&6 # 恢复 FD2

4、 简单举例（其中 you 这个文件是存在的，no和yes这两个文件不存在）

a、stdout和stderr都通过管道送给egrep了：

(ls you no 2>&1;ls yes 2>&1) 2>&1|egrep \* >file

(ls you no 2>&1;ls yes 2>&1)|egrep \* >file

(ls you no;ls yes) 2>&1|egrep \* >file

###

这个例子要注意的就是：

理解 命令执行顺序 和 管道“|”：在命令执行前，先要进行重定向的处理，并将把 nested sub-shell 的stdout 接到 egrep 命令的 stdin。

nested sub-shell ，在 ( ) 中的两个命令加上（），可以看作一个命令。其 FD1 已经连接到“|”往egrep送了，当遇到 2>&1时，也就是FD2＝FD1，即FD2同FD1一样，往管道 “|”那边送。

###

b、没有任何东西通过管道送给egrep，全部送往monitor。

(ls you no 2>&1;ls yes 2>&1) >&2|egrep \* >file

虽然在（）里面将 FD2转往FD1，但在（）外，遇到 >&2 ，结果所有的都送到monitor。

请理解：

(ls you no 2>&1) 1>&2|egrep \* >file ## 送到 monitor

ls you no 2>&1 1>&2|egrep \* >file ## 送给 管道 “|”

ls you no 1>&2 2>&1|egrep \* >file ## 送到 monitor

5、 中阶例子（其中 you 这个文件是存在的，no和yes这两个文件不存在）

r2007兄的：http://bbs.chinaunix.net/forum/viewt...313c6922123f67

条件：

stderr通过管道送给egrep，正确消息仍然送给monitor（不变）

exec 4>&1;(ls you no 2>&1 1>&4 4>&-;ls yes 2>&1 1>&4 4>&-)|egrep \* >file;exec 4>&-

或者

exec 4>&1;(ls you no;ls yes) 2>&1 1>&4 4>&-|egrep \* >file;exec 4>&-

r2007 兄在其贴已有详细说明，我就不在说明了。

如果加两个条件：

（1）要求cmd1和cmd2并行运行；

（2）将cmd1的返回值赋给变量 ss。

则为：

exec 3>&1;exec 4>&1

ss=$(((ls you no 2>&1 1>&3 3>&-;echo $? >&4)|egrep \* >file) 4>&1)

exec 3>&-;exec 4>&-

说明：

exec 3>&1;4>&1

### 建立FD3，是用来将下面ls那条语句（子shell）中的FD1 恢复到正常FD1，即输出到monitor，你可以把FD3看作最初始的FD1的硬盘备份（即输出到monitor）；

### 建立FD4，到时用作保存ls的返回值（echo $?），你可以将FD4看作你考试时用于存放计算“echo $?”的草稿纸；

(ls you no 2>&1 1>&3 3>&-;echo $? >&4)

### 大家还记得前面说的子shell和管道吧。这条命令首先会继承FD0、FD1、FD2、FD3、FD4，它位于管道前，所以在运行命令前会先把子shell自己的FD1和管道“|”相连。

但是我们的条件是stderr通过管道送往egrep，stdout仍然输出到monitor。

于是通过2>&1，先把 子shell的FD1 的管道“送给”FD2，于是子shell中的stderr送往管道“|”；

再通过 1>&3，把以前的“硬盘备份”恢复给子shell的FD1，于是子shell中的FD1变成送到monitor了。

再通过3>&- ，将3关闭；

接着运行echo $? ，本来其输出值应该送往管道的，通过 >&4 ，将 输出 送往 “草稿纸”FD4，留以备用。

((ls you no 2>&1 1>&3 3>&-;echo $? >&4)|egrep \* >file)

于是，stderr 通过管道送给 egrep ，stdout 送给monitor，但是，还有 FD4，它送到哪去了？

$(((ls you no 2>&1 1>&3 3>&-;echo $? >&4)|egrep \* >file) 4>&1)

最后的 4>&1 ，就是把FD4 重定向到 FD1。但由于其输出在 $( )中，其值就赋给变量ss了。

最后一行关闭 FD3、FD4。

6、 高阶例子

lightspeed 版主大大的：Shell 经典问题之 [ I/O 重定向] （http://bbs.chinaunix.net/forum/viewt...ow_type=new）

[Q] 对于命令 cmd1, cmd2, cmd3, cmd4. 如何利用单向管道完成下列功能：

1. 所有命令并行执行

2. cmd1 和 cmd2 不需要 stdin

3. cmd1 和 cmd2 的 stdout 定向到 cmd3 的 stdin

4. cmd1 和 cmd2 的 stderr 定向到 cmd4 的 stdin

5. cmd3 的 stdout 定向到文件 a, stderr 定向到屏幕

6. cmd4 的 stdout 定向到文件 b, stderr 定向到屏幕

7. cmd1 的返回码赋给变量 s

8. 不能利用临时文件

解决方法：

exec 3>&1; exec 4>&1

s=$(((((cmd1 1>&3 ; echo $? >&4 )| cmd2 ) 3>&1 | cmd3 >a 2>&3 ) 2>&1 | cmd4 >b ) 4>&1)

exec 3>&-; exec 4>&-

这个我一步步解释（好复杂，自己感觉看明白了，过一会再看，大脑仍然有几分钟空白～～～，没想到我也能看明白）：

exec 3>&1; exec 4>&1

### 前面的例子都有说明了，就是建立FD3 ，给cmd1恢复其FD1用和给cmd3 恢复其FD2用

### 建立FD4，保存“echo $?”输出值的“草稿纸”

第一对括号：(cmd1 1>&3 ; echo $? >&4 ) 和其后（第一个）管道

## 在第一个括号（子shell）中，其FD1已经连到 管道中了，所以用 FD3 将 FD1恢复正常，不让他往管道跑；

## 这里的cmd1没有stdin，接着将 cmd1 运行的返回码 保存到 FD4 中；

第二对括号：((cmd1 1>&3 ; echo $? >&4 )| cmd2 ) 3>&1 和其后（第二个）管道

## 前面的 FD1 已经不送给 cmd2了，FD2 默认也不送过来，所以cmd2 也没有stdin ，所以在第二对括号里面：cmd1和cmd2 的stdout、stderr 为默认输出，一直遇到 “3>&1”为止。

## 请注意：“3>&1”，先将第二对括号看出一个命令，他们遇到 第二个管道时，其FD1 连到 管道 “|”，由于“3>&1”的作用，子shell的FD1 送给FD3 使用，所以所有FD3 的输出都 “流往”cmd3，又由于继承关系（继承第一行的命令），FD3实际上就是cmd1和cmd2的stdout，于是“ cmd1 和 cmd2 的 stdout 定向到 cmd3 的 stdin”

第三对括号：(((cmd1 1>&3 ; echo $? >&4 )| cmd2 ) 3>&1 | cmd3 >a 2>&3 ) 2>&1 和其后的第三个管道

## cmd1 和 cmd2 的 stdout 已经定向到 cmd3 的 stdin，处理之后，cmd3 >a 意味着将其 stdout 送给 a 文件。而2>&3的意思是：恢复cmd3的错误输出为FD3，即送往 monitor。于是“cmd3 的 stdout 定向到文件 a, stderr 定向到屏幕”。如果没有“2>&3”，那么cmd3的错误输出就会干扰cmd1和cmd2的错误输出，所以它是必须的！

## 请注意第三对括号后的 “2>&1”| ，其子shell的FD1 本来连接着管道“|”，但子shell FD1 慷慨大方，送给了 FD2，于是FD2 连接着管道。还记得前面的 cmd1 和 cmd2 吗？他们的stderr一直没动了。于是在这里，通过管道送给了 第四个命令cmd4 了。即“cmd1 和 cmd2 的 stderr 定向到 cmd4 的 stdin”

## 后面就比较简单了。cmd4 >b 表示“cmd4 的 stdout 定向到文件 b, stderr 定向到屏幕（默认）”

第四对括号：((((cmd1 1>&3 ; echo $? >&4 )| cmd2 ) 3>&1 | cmd3 >a 2>&3 ) 2>&1 | cmd4 >b ) 与其后的 4>&1

## 四对括号里面的 FD1、FD2都处理完了。但是还记得前面“echo $? >&4”那块“草稿纸”吗？“4>&1”的作用就是“将草稿纸上的内容送给monitor”，但是由于最外面还有 $() 将其“包着”。于是其值赋给变量“s”。

＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋＋

我尝试回答下面的问题。如有错误，还请各位前辈指正！

7、 在一个交互式的(Interactive) shell 中, 用 exec 进行 I/O 重定向.

1）. Stdin, stderr 可以定向到文件中吗? 有什么结果?

a、 在交互式shell中，可以将stdin定向到文件。执行：exec 0结果为：in 文件中每一行均会被自动执行，并且在最后会再加执行一个 exit 命令，导致退出（或退回到正常shell下）。

如 in 文件内容：$ more in

date

read lsp

echo hahha

echo "this is $lsp"

在提示符下执行命令：$ exec 0$ date

Tue Jan 18 18:29:07 HKT 2005

$ read lsp # 其下面本应有的那句“ echo hahha ”的 “hahaha” 已经被读入到变量 lsp 中了

$ echo "this is $lsp"

this is echo hahha

$ exit

b、 在交互式shell中，可以将stderr定向到文件。执行：exec 2>err

结果为：命令提示符PS被屏蔽，输入的命令也被屏蔽。但是命令执行的结果，如果是stdout 则会回显到屏幕上，如果是 stderr 则不会回显到屏幕上。其中，命令提示符、命令、stderr均会保存到文件 err 中。如：

$ exec 2>err

err in out # 执行 ls 命令

Tue Jan 18 18:55:58 HKT 2005 # 执行 date 命令，而后执行了“ ls nofile”，nofile这个文件不存在

$ # 执行 exit 命令

现在让我们查看 err文件：

$ more err

[lsp@ii lsp]$ ls

[lsp@ii lsp]$ date

[lsp@ii lsp]$ ls nofile

ls: nofile: No such file or directory

[lsp@ii lsp]$ exit

exit

c、 在交互式shell中，可以将stdout定向到文件。这个使我们常用到的。就不说了。就是将错误的输出内容定向到文件中。正确的输出内容并不受影响。

2）. Stdin, Stderr 可以关闭吗? 有什么结果?

在交互式shell中，如果关闭stdin，如：exec 0<&- ，其结果是退出（或退回到正常shell下）。

在交互式shell中，如果关闭stderr，如：exec 2>&- ，状态同stderr定向到文件，唯一不同的是没有保存下来。

在交互式shell中，如果关闭stdoutr，如：exec 1>&- ，只要执行有stdout或stderr内容送往 monitor 的命令，如ls、date这类命令，均会报错：“ls: write error: Bad file descriptor”。其他如cd、mkdir、……这类命令不受影响。

3）. 如果 stdin, stdout, stderr 进行了重定向或关闭, 但没有保存原来的 FD, 可以将其恢复到 default 状态吗?

*** 如果关闭了stdin，因为会导致退出，那肯定不能恢复。

*** 如果重定向或关闭 stdout和stderr其中之一，可以恢复，因为他们默认均是送往monitor（但不知会否有其他影响）。如恢复重定向或关闭的stdout：exec 1>&2 ，恢复重定向或关闭的stderr：exec 2>&1。

*** 如果stdout和stderr全部都关闭了，又没有保存原来的FD，可以用：exec 1>/dev/tty 恢复。

8、 cmd >a 2>a 和 cmd >a 2>&1 为什么不同？ 
cmd >a 2>a ：stdout和stderr都直接送往文件 a ，a文件会被打开两遍，由此导致stdout和stderr互相覆盖。 
cmd >a 2>&1 ：stdout直接送往文件a ，stderr是继承了FD1的管道之后，再被送往文件a 。a文件只被打开一遍，就是FD1将其打开。 
我想：他们的不同点在于： 
cmd >a 2>a 相当于使用了两个互相竞争使用文件a的管道； 
而cmd >a 2>&1 只使用了一个管道，但在其源头已经包括了stdout和stderr。 
从IO效率上来讲，cmd >a 2>&1的效率应该更高！						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-13 10:58:44 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Jul 2010 02:58:44 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-13 10:53:04 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=183</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> for i in $(find . -type f); do :>$i; done						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-13 10:53:04 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Jul 2010 02:53:04 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-13 10:52:37 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=182</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> find ./ -type f | while read line ;do >$line;done						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-13 10:52:37 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Jul 2010 02:52:37 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-13 10:51:18 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=181</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> find . -atime +9 |xargs rm						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-13 10:51:18 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Jul 2010 02:51:18 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-13 10:50:45 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=180</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> find . -atime +9 -exec rm {} \;						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-13 10:50:45 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Jul 2010 02:50:45 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-13 10:49:46 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=179</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> find . -mtime +9 -exec cp /dev/null {} \;						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-13 10:49:46 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Jul 2010 02:49:46 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-12 14:36:19 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=178</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> RS_Server_vip:/usr/local/qhttpd/log # sysctl -p
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_tw_recycle = 1
net.core.rmem_max = 16777216
net.core.rmem_default = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_retries2 = 3
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_keepalive_time = 1800
net.ipv4.tcp_keepalive_probes = 5						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-12 14:36:19 from Web</span>
		</p>]]></description>
	    <pubDate>Mon, 12 Jul 2010 06:36:19 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-12 14:07:17 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=177</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> netstat -ant|fgrep ":"|cut -b 69-90|sort -n|uniq -c |sort -r						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-12 14:07:17 from Web</span>
		</p>]]></description>
	    <pubDate>Mon, 12 Jul 2010 06:07:17 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-09 14:53:57 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=176</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> echo  $((`ls   -laR  .|wc -l`-`ls   -laR  .|grep    total|wc -l`*5+1))						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-09 14:53:57 from Web</span>
		</p>]]></description>
	    <pubDate>Fri, 9 Jul 2010 06:53:57 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-07 22:27:16 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=175</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> $ find . -name '*.tmp' -exec rm {} ;						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-07 22:27:16 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 7 Jul 2010 14:27:16 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-07 19:51:27 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=174</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-07 19:51:27 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 7 Jul 2010 11:51:27 +0000</pubDate>
	</item>
		<item>
	    <title>2010-07-07 10:45:50 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=173</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> vim .bashrc;alias ssh='/usr/local/bin/ssh  -o StrictHostKeyChecking=no -p 1250 -l root  '						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-07-07 10:45:50 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 7 Jul 2010 02:45:50 +0000</pubDate>
	</item>
		<item>
	    <title>2010-06-24 10:52:47 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=172</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> echo user:password | chpasswd						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-06-24 10:52:47 from Web</span>
		</p>]]></description>
	    <pubDate>Thu, 24 Jun 2010 02:52:47 +0000</pubDate>
	</item>
		<item>
	    <title>2010-06-22 19:00:59 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=171</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-06-22 19:00:59 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 22 Jun 2010 11:00:59 +0000</pubDate>
	</item>
		<item>
	    <title>2010-06-21 09:21:20 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=170</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> passwd sb_user						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-06-21 09:21:20 from Web</span>
		</p>]]></description>
	    <pubDate>Mon, 21 Jun 2010 01:21:20 +0000</pubDate>
	</item>
		<item>
	    <title>2010-06-12 16:55:29 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=169</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> chmod 6755 exe ;设置s位						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-06-12 16:55:29 from Web</span>
		</p>]]></description>
	    <pubDate>Sat, 12 Jun 2010 08:55:29 +0000</pubDate>
	</item>
		<item>
	    <title>2010-05-21 16:36:44 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=168</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-05-21 16:36:44 from Web</span>
		</p>]]></description>
	    <pubDate>Fri, 21 May 2010 08:36:44 +0000</pubDate>
	</item>
		<item>
	    <title>2010-05-21 16:10:53 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=167</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> history | perl -F"\||<\(|;|\`|\\$\(" -alne 'foreach (@F) { print $1 if /\b((?!do)[a-z]+)\b/i }' | sort | uniq -c | sort -nr						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-05-21 16:10:53 from Web</span>
		</p>]]></description>
	    <pubDate>Fri, 21 May 2010 08:10:53 +0000</pubDate>
	</item>
		<item>
	    <title>2010-05-19 15:34:52 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=166</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> ifconfig | grep -v '127.0.0.1' | awk '/inet (addr:)?/{sub("addr:","");print $2;exit}'						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-05-19 15:34:52 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 19 May 2010 07:34:52 +0000</pubDate>
	</item>
		<item>
	    <title>2010-05-19 15:25:03 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=165</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> find -L . -type l # 查找所有损坏的符号链接
find -L . -type l -exec rm -rf {} \; # 删除损坏的符号链接						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-05-19 15:25:03 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 19 May 2010 07:25:03 +0000</pubDate>
	</item>
		<item>
	    <title>2010-05-19 11:31:35 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=164</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> 一般root用户才能执行lsof命令，普通用户可以看见/usr/sbin/lsof命令，但是普通用户执行会显示“permission denied”

我总结一下lsof指令的用法：

lsof abc.txt 显示开启文件abc.txt的进程

lsof -i :22 知道22端口现在运行什么程序

lsof -c abc 显示abc进程现在打开的文件

lsof -g gid 显示归属gid的进程情况

lsof +d /usr/local/ 显示目录下被进程开启的文件

lsof +D /usr/local/ 同上，但是会搜索目录下的目录，时间较长

lsof -d 4 显示使用fd为4的进程

lsof -i 用以显示符合条件的进程情况

语法: lsof -i[46] [protocol][@hostname|hostaddr][:service|port]

46 --> IPv4 or IPv6

protocol --> TCP or UDP

hostname --> Internet host name

hostaddr --> IPv4位置

service --> /etc/service中的 service name (可以不只一个)

port --> 端口号 (可以不只一个)

例子: TCP:25 - TCP and port 25

@1.2.3.4 - Internet IPv4 host address 1.2.3.4

tcp@ohaha.ks.edu.tw:ftp - TCP protocol hosthaha.ks.edu.tw service name:ftp

lsof -n 不将IP转换为hostname，缺省是不加上-n参数

例子: lsof -i tcp@ohaha.ks.edu.tw:ftp -n

lsof -p 12 看进程号为12的进程打开了哪些文件

lsof +|-r [t] 控制lsof不断重复执行，缺省是15s刷新

-r，lsof会永远不断的执行，直到收到中断信号

+r，lsof会一直执行，直到没有档案被显示

例子：不断查看目前ftp连接的情况：lsof -i tcp@ohaha.ks.edu.tw:ftp -r

lsof -s 列出打开文件的大小，如果没有大小，则留下空白

lsof -u username 以UID，列出打开的文件

一般root用户才能执行lsof命令，普通用户可以看见/usr/sbin/lsof命令，但是普通用户执行会显示“permission denied”

我总结一下lsof指令的用法：

lsof abc.txt 显示开启文件abc.txt的进程

lsof -i :22 知道22端口现在运行什么程序

lsof -c abc 显示abc进程现在打开的文件

lsof -g gid 显示归属gid的进程情况

lsof +d /usr/local/ 显示目录下被进程开启的文件

lsof +D /usr/local/ 同上，但是会搜索目录下的目录，时间较长

lsof -d 4 显示使用fd为4的进程

lsof -i 用以显示符合条件的进程情况

语法: lsof -i[46] [protocol][@hostname|hostaddr][:service|port]

46 --> IPv4 or IPv6

protocol --> TCP or UDP

hostname --> Internet host name

hostaddr --> IPv4位置

service --> /etc/service中的 service name (可以不只一个)

port --> 端口号 (可以不只一个)

例子: TCP:25 - TCP and port 25

@1.2.3.4 - Internet IPv4 host address 1.2.3.4

tcp@ohaha.ks.edu.tw:ftp - TCP protocol hosthaha.ks.edu.tw service name:ftp

lsof -n 不将IP转换为hostname，缺省是不加上-n参数

例子: lsof -i tcp@ohaha.ks.edu.tw:ftp -n

lsof -p 12 看进程号为12的进程打开了哪些文件

lsof +|-r [t] 控制lsof不断重复执行，缺省是15s刷新

-r，lsof会永远不断的执行，直到收到中断信号

+r，lsof会一直执行，直到没有档案被显示

例子：不断查看目前ftp连接的情况：lsof -i tcp@ohaha.ks.edu.tw:ftp -r

lsof -s 列出打开文件的大小，如果没有大小，则留下空白

lsof -u username 以UID，列出打开的文件						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-05-19 11:31:35 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 19 May 2010 03:31:35 +0000</pubDate>
	</item>
		<item>
	    <title>2010-05-12 17:16:19 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=163</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> ifconfig eth1 172.23.131.108 -broadcast 172.23.131.127 netmask 255.255.255.128						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-05-12 17:16:19 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 12 May 2010 09:16:19 +0000</pubDate>
	</item>
		<item>
	    <title>2010-05-12 10:29:04 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=162</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> shutdown -hP -t5 now						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-05-12 10:29:04 from Web</span>
		</p>]]></description>
	    <pubDate>Wed, 12 May 2010 02:29:04 +0000</pubDate>
	</item>
		<item>
	    <title>2010-05-11 14:42:21 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=161</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> vim /etc/init.d/iptables/eth0/ETH0_TCP.IPT;iptables -A  ETH0_TCP -p tcp -s 211.151.50.193 --sport 80 -j ACCEPT;/etc/init.d/iptables/eth0/ETH0_TCP.IPT						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-05-11 14:42:21 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 11 May 2010 06:42:21 +0000</pubDate>
	</item>
		<item>
	    <title>2010-05-06 14:38:01 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=160</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> vim /etc/resolv.conf
nameserver 172.xx.xx.xx
vim /etc/nsswitch.conf
hosts:          files dns
networks:       files dns						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-05-06 14:38:01 from Web</span>
		</p>]]></description>
	    <pubDate>Thu, 6 May 2010 06:38:01 +0000</pubDate>
	</item>
		<item>
	    <title>2010-05-01 09:28:07 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=159</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> http://ditu.google.com/maps?f=d&source=s_d&saddr=%E6%B7%B1%E5%9C%B3%E5%B8%82%E5%8D%97%E5%B1%B1%E5%8C%BA%E9%AB%98%E9%A6%96%E4%BF%B1%E4%B9%90%E9%83%A8&daddr=%E5%B9%BF%E4%B8%9C%E7%9C%81%E4%B8%9C%E8%8E%9E%E5%B8%82%E5%B8%82%E5%8C%BA%E8%BF%90%E6%B2%B3%E8%A5%BF%E4%B8%89%E8%B7%AF148%E5%8F%B7+(%E4%B8%9C%E6%BA%90%E5%95%86%E5%8A%A1%E9%85%92%E5%BA%97)&geocode=FdW7VwEd2GjKBiGByZ_FH7PRUA%3BFW54XwEdbYbHBiGkcqd_vuidOimZV32dogoDNDHEfRsPNQKlLg&hl=zh-CN&mra=ls&sll=22.526858,113.930272&sspn=0.00768,0.016469&brcurrent=3,0x34030a94dd8813e5:0x768320300ebc7a43,0,0x315285f132af5c3f:0x2ed41c6f09259f29%3B5,0,0&ie=UTF8&ll=22.745789,114.141083&spn=0.981515,2.108002&z=10						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-05-01 09:28:07 from Web</span>
		</p>]]></description>
	    <pubDate>Sat, 1 May 2010 01:28:07 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-30 10:38:48 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=158</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> /var/spool/cron/tabs/root						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-30 10:38:48 from Web</span>
		</p>]]></description>
	    <pubDate>Fri, 30 Apr 2010 02:38:48 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-26 17:38:06 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=157</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-26 17:38:06 from Web</span>
		</p>]]></description>
	    <pubDate>Mon, 26 Apr 2010 09:38:06 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-26 10:35:35 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=156</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> #! /bin/sh
conf='/etc/sysctl.conf'
verify_first=`wc -l $conf|awk '{print $1}'`
echo -e "# add some configure for proxy of web.isd.com.----chnliu
# Disable response to broadcasts.
# You don't want yourself becoming a Smurf amplifier.
net.ipv4.icmp_echo_ignore_broadcasts = 1
# enable route verification on all interfaces
net.ipv4.conf.all.rp_filter = 1
# enable ipV6 forwarding
# net.ipv6.conf.all.forwarding = 1
kernel.sysrq = 1" > $conf
grep ^net.ipv4.tcp_mem $conf > /dev/null
if [ $? ]
then
echo -e "net.ipv4.tcp_mem = 161061 295074 839701 225472" >> $conf
fi
##打开fin_wait 快速关闭参数 
grep ^net.ipv4.tcp_fin_timeout $conf > /dev/null
if [ $? ]
then
echo -e "net.ipv4.tcp_fin_timeout = 1" >> $conf
fi
##快速回收fin_wait参数
grep ^net.ipv4.tcp_tw_recycle $conf > /dev/null
if [ $? ]
then
echo -e "net.ipv4.tcp_tw_recycle = 1" >> $conf
fi
grep ^net.core.rmem_max $conf > /dev/null
if [ $? ]
then
echo -e "net.core.rmem_max = 16777216" >> $conf
fi
grep ^net.core.rmem_default $conf > /dev/null
if [ $? ]
then
echo -e "net.core.rmem_default = 16777216" >> $conf
fi
grep ^net.core.netdev_max_backlog $conf > /dev/null
if [ $? ]
then
echo -e "net.core.netdev_max_backlog = 262144" >> $conf
fi
grep ^net.core.somaxconn $conf > /dev/null
if [ $? ]
then
echo -e "net.core.somaxconn = 262144" >> $conf
fi
#打开SYN_COOKIE
grep ^net.ipv4.tcp_syncookies $conf > /dev/null
if [ $? ]
then
echo -e "net.ipv4.tcp_syncookies =1" >> $conf
fi
grep ^net.ipv4.tcp_max_orphans $conf > /dev/null
if [ $? ]
then
echo -e "net.ipv4.tcp_max_orphans =262144" >> $conf
fi
##SYN 队列大小  2M
grep ^net.ipv4.tcp_max_syn_backlog $conf > /dev/null
if [ $? ]
then
echo -e "net.ipv4.tcp_max_syn_backlog = 262144" >> $conf
fi
##SYN_ACK重试次数  2
grep ^net.ipv4.tcp_synack_retries $conf > /dev/null
if [ $? ]
then
echo -e "net.ipv4.tcp_synack_retries = 2" >> $conf
fi
grep ^net.ipv4.tcp_syn_retries $conf > /dev/null
if [ $? ]
then
echo -e "net.ipv4.tcp_syn_retries = 2" >> $conf
fi
verify_then=`wc -l $conf|awk '{print $1}'`
if [ $verify_then -gt $verify_first ]
then
/sbin/sysctl -p > /dev/null
echo "optimized already,have a good luck"
fi						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-26 10:35:35 from Web</span>
		</p>]]></description>
	    <pubDate>Mon, 26 Apr 2010 02:35:35 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-22 14:35:59 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=155</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> １.core文件的生成开关和大小限制
１）ulimit -c   查看可生成的core文件的大小，默认设置为０
２）ulimit -c filesize 设置生成core文件的大小（ＫＢ），ulimit -c unlimited设置core文件大小不受限制
 
２.core文件的名称和保存目录
１）echo "1" > /proc/sys/kernel/core_uses_pid 可以设置生成的名称加上进程pid作为后缀。默认此文件内容为０，所以生成的core文件的名字都是core，新的覆盖旧的。
２）echo "/corefile/core-%e-%p-%t" > core_pattern 可以将core文件统一生成到corefile目录，core-%e-%p-%t是文件名，%e等是参数表，其含义如下：
%p - insert pid into filename 添加pid
%u - insert current uid into filename 添加当前uid
%g - insert current gid into filename 添加当前gid
%s - insert signal that caused the coredump into the filename添加导致产生core的信号
%t - insert UNIX time that the coredump occurred into filename添加core文件生成时的unix时间
%h - insert hostname where the coredump happened into filename添加主机名
%e - insert coredumping executable name into filename添加命令名
３.用gdb查看core文件
1)gdb ./test corefile
2)gdb ./test.out
  core-file corefile
3)gdb -core=corefile
  file ./test.out
4)gdb -c corefile
  file ./test.out
 
4.注意
１）编译的时候加上-g参数。
２）要保证存放Coredump的目录存在且进程对该目
录有写权限。存放Coredump的目录即进程的当前目录，一般就是当初发出命令启动该进程时所在的目录。但如果是通过脚本启动，则脚本可能会修改当前目录，这时进程真正的当前目录就会与当初执行脚本所在目录不同。这时可以查看”/proc/进程pid/cwd“符号链接的目标来确定进程真正的当前目录地址。通过系统服务启动的进程也可通过这一方法查看。
３）若程序调用了seteuid()/setegid()改变了进程的有效用户或组，则在默认情况下系统不会为这些进程生成Coredump。很多服务程序都会调用seteuid()，如MySQL，不论你用什么用户运行mysqld_safe启动ＭySQL，mysqld进行的有效用户始终是msyql用户。如果你当初是以用户A运行了某个程序，但在ps里看到的
这个程序的用户却是B的话，那么这些进程就是调用了seteuid了。为了能够让这些进程生成coredump，需要将/proc/sys/fs/suid_dumpable文件的内容改为1（一般默认是0）。
４）这个一般都知道，就是要设置足够大的Core文件大小限制了。程序崩溃时生成的Core文件大小即为程序运行时占用的内存大小。但程序崩溃时的行为不可按平常时的行为来估计，比如缓冲区溢出等错误可能导致堆栈被破坏，因此经常会出现某个变量的值被修改成乱七八糟的，然后程序用这个大小去申请内存就可能导致程序比平常时多占用很多内存。因此无论程序正常运行时占用的内存多么少，要保证生成Core文件还是将大小限制设为unlimited为好。						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-22 14:35:59 from Web</span>
		</p>]]></description>
	    <pubDate>Thu, 22 Apr 2010 06:35:59 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-22 10:31:46 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=154</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> du -h --max-depth=1 /data						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-22 10:31:46 from Web</span>
		</p>]]></description>
	    <pubDate>Thu, 22 Apr 2010 02:31:46 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-20 11:24:57 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=153</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> tr 'a-z' 'A-Z' <<< abcdefg						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-20 11:24:57 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 20 Apr 2010 03:24:57 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-20 10:46:28 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=152</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> tr 'a-z' 'A-Z' "abcdefg"						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-20 10:46:28 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 20 Apr 2010 02:46:28 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-16 19:10:37 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=151</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> HTTP Error Codes (and what they mean)
Web servers will use the following Error Codes when something goes awry. Knowing what they mean enables you to fix the problem, or create custom error pages.
The status codes are returned to the client making the request (typically an Internet Browser) and also recorded in the server's log file. Theses error codes are encoded into decimal ranges:
Error Code Range	Type of Error Code
100 to 199	Informational status codes, rarely used - and generally only written to server logs.
200 to 299	Successful, only 200 frequently used - and generally only written to server logs.
300 to 399	Warning - but the request may still be satisfiable.
400 to 499	Client Error, the request was invalid in some way.
500 to 599	Server Error, the server could not fulfil the (valid) request.
100 Range

HTTP Error 100
Continue. Not really an "error", this HTTP Status Code means everything is working fine.
HTTP Error 101
Switching Protocols. Again, not really an "error", this HTTP Status Code means everything is working fine.
200 Range

HTTP Error 200
Success. This HTTP Status Code means everything is working fine. However, if you receive this message on screen, obviously something is not right... Please contact the server's administrator if this problem persists. Typically, this status code (as well as most other 200 Range codes) will only be written to your server logs.
HTTP Error 201
Created. A new resource has been created successfully on the server.
HTTP Error 202
Accepted. Request accepted but not completed yet, it will continue asynchronously.
HTTP Error 203
Non-Authoritative Information. Request probably completed successfully but can't tell from original server.
HTTP Error 204
No Content. The requested completed successfully but the resource requested is empty (has zero length).
HTTP Error 205
Reset Content. The requested completed successfully but the client should clear down any cached information as it may now be invalid.
HTTP Error 206
Partial Content. The request was canceled before it could be fulfilled. Typically the user gave up waiting for data and went to another page. Some download accelerator programs produce this error as they submit multiple requests to download a file at the same time.
300 Range

HTTP Error 300
Multiple Choices. The request is ambiguous and needs clarification as to which resource was requested.
HTTP Error 301
Moved Permanently. The resource has permanently moved elsewhere, the response indicates where it has gone to.
HTTP Error 302
Moved Temporarily. The resource has temporarily moved elsewhere, the response indicates where it is at present.
HTTP Error 303
See Other/Redirect. A preferred alternative source should be used at present.
HTTP Error 304
Not Modified. The server has identified from the request information that the client's copy of the information is up-to-date and the requested information does not need to be sent again.
HTTP Error 305
Use Proxy. The request must be sent through the indicated proxy server.
HTTP Error 307
Temporary Redirect The resource has temporarily moved elsewhere, the response indicates where it is at present. Client should still use this URL.
400 Range

HTTP Error 400
Bad Request. Due to malformed syntax, the request could not be understood by the server. The client should not repeat the request without modifications. Please contact the server's administrator if this problem persists.
HTTP Error 401.1
Unauthorized: Logon Failed. This error indicates that the credentials passed to the server do not match the credentials required to log on to the server. Please contact the Web server's administrator to verify that you have permission to access the requested resource.
HTTP Error 401.2
Unauthorized: Logon Failed due to server configuration. This error indicates that the credentials passed to the server do not match the credentials required to log on to the server. This is usually caused by not sending the proper WWW-Authenticate header field. Please contact the Web server's administrator to verify that you have permission to access to requested resource.
HTTP Error 401.3
Unauthorized: Unauthorized due to ACL on resource. This error indicates that the credentials passed by the client do not have access to the particular resource on the server. This resource could be either the page or file listed in the address line of the client, or it could be another file on the server that is needed to process the file listed on the address line of the client. Please make a note of the entire address you were trying to access and then contact the Web server's administrator to verify that you have permission to access the requested resource.
HTTP Error 401.4
Unauthorized: Authorization failed by filter. This error indicates that the Web server has a filter program installed to verify users connecting to the server. The authentication used to connect to the server was denied access by this filter program. Please make a note of the entire address you were trying to access and then contact the Web server's administrator to verify that you have permission to access the requested resource.
HTTP Error 401.5
Unauthorized: Authorization failed by ISAPI/CGIapp. This error indicates that the address on the Web server you attempted to use has an ISAPI or CGI program installed that verifies user credentials before proceeding. The authentication used to connect to the server was denied access by this program. Please make a note of the entire address you were trying to access and then contact the Web server's administrator to verify that you have permission to access the requested resource.
HTTP Error 403.1
Forbidden: Execute Access Forbidden. This error can be caused if you try to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed. Please contact the Web server's administrator if the problem persists.
HTTP Error 403.2
Forbidden: Read Access Forbidden. This error can be caused if there is no default page available and directory browsing has not been enabled for the directory, or if you are trying to display an HTML page that resides in a directory marked for Execute or Script permissions only. Please contact the Web server's administrator if the problem persists.
HTTP Error 403.3
Forbidden: Write Access Forbidden. This error can be caused if you attempt to upload to, or modify a file in, a directory that does not allow Write access. Please contact the Web server's administrator if the problem persists.
HTTP Error 403.4
Forbidden: SSL required. This error indicates that the page you are trying to access is secured with Secure Sockets Layer (SSL). In order to view it, you need to enable SSL by typing "HTTPs://" at the beginning of the address you are attempting to reach. Please contact the Web server's administrator if the problem persists.
HTTP Error 403.5
Forbidden: SSL 128 required. This error message indicates that the resource you are trying to access is secured with a 128-bit version of Secure Sockets Layer (SSL). In order to view this resource, you need a browser that supports this level of SSL. Please confirm that your browser supports 128-bit SSL security. If it does, then contact the Web server's administrator and report the problem.
HTTP Error 403.6
Forbidden: IP address rejected. This error is caused when the server has a list of IP addresses that are not allowed to access the site, and the IP address you are using is in this list. Please contact the Web server's administrator if the problem persists.
HTTP Error 403.7
Forbidden: Client certificate required. This error occurs when the resource you are attempting to access requires your browser to have a client Secure Sockets Layer (SSL) certificate that the server recognizes. This is used for authenticating you as a valid user of the resource. Please contact the Web server's administrator to obtain a valid client certificate.
HTTP Error 403.8
Forbidden: Site access denied. This error can be caused if the Web server is not servicing requests, or if you do not have permission to connect to the site. Please contact the Web server's administrator.
HTTP Error 403.9
Access Forbidden: Too many users are connected. This error can be caused if the Web server is busy and cannot process your request due to heavy traffic. Please try to connect again later. Please contact the Web server's administrator if the problem persists.
HTTP Error 403.10
Access Forbidden: Invalid Configuration. There is a configuration problem on the Web server at this time. Please contact the Web server's administrator if the problem persists.
HTTP Error 403.11
Access Forbidden: Password Change. This error can be caused if the user has entered the wrong password during authentication. Please refresh the page and try again. Please contact the Web server's administrator if the problem persists.
HTTP Error 403.12
Access Forbidden: Mapper Denied Access. Your client certificate map has been denied access to this Web site. Please contact the site administrator to establish client certificate permissions. You can also change your client certificate and retry, if appropriate.
HTTP Error 403.13
Client certificate revoked: The page you are trying to view requires the use of a valid client certificate. Your client certificate was revoked, or the revocation status could not be determined. The certificate is used for authenticating you as a valid user of the resource.
HTTP Error 403.14
Directory listing denied: This Virtual Directory does not allow contents to be listed.
HTTP Error 403.15
Client Access Licenses exceeded: There are too many people accessing the Web site at this time.
HTTP Error 403.16
Client certificate untrusted or invalid: The page you are trying to view requires the use of a valid client certificate. Your client certificate is untrusted or invalid. The client certificate is used for authenticating you as a valid user of the resource.
HTTP Error 403.17
Client certificate has expired or is not yet valid: The page you are trying to view requires the use of a valid client certificate. Your client certificate has expired or is not yet valid. The client certificate is used for identifying you as a valid user of the resource.
HTTP Error 404
Not Found: The Web server cannot find the file or script you asked for. Please check the URL to ensure that the path is correct. Please contact the server's administrator if this problem persists.
HTTP Error 404.1
Web site not found. (You can probably change the wording to read "Web site" instead of "Web server". The Web site you are looking for is unavailable due to its identification configuration settings.)
HTTP Error 405
Method Not Allowed: The method specified in the Request Line is not allowed for the resource identified by the request. Please ensure that you have the proper MIME type set up for the resource you are requesting. Please contact the server's administrator if this problem persists.
HTTP Error 406
Not Acceptable: The resource identified by the request can only generate response entities that have content characteristics that are "not acceptable" according to the Accept headers sent in the request. Please contact the server's administrator if this problem persists.
HTTP Error 407
Proxy Authentication Required: You must authenticate with a proxy server before this request can be serviced. Please log on to your proxy server, and then try again. Please contact the Web server's administrator if this problem persists.
HTTP Error 408
Request Time-Out. The client did not send a request within the required time period.
HTTP Error 409
Conflict. There is an internal conflict of access to the resource. Please contact the server's administrator if this problem persists.
HTTP Error 410
Gone. The requested resource used to be on the server but is no longer available. Any robot seeing this response should delete the reference from its information store.
HTTP Error 411
Length Required. The request requires the Content-Length HTTP request field to be specified.
HTTP Error 412
Precondition Failed: The precondition given in one or more of the Request-header fields evaluated to FALSE when it was tested on the server. The client placed preconditions on the current resource meta-information (header field data) to prevent the requested method from being applied to a resource other than the one intended. Please contact the Web server's administrator if the problem persists.
HTTP Error 413
Request Entity Too Large. The URL is too long (possibly too many query strings?).
HTTP Error 414
Request-URI Too Long: The server is refusing to service the request because the Request-URI is too long. This rare condition is likely to occur only in the following situations:
A client has improperly converted a POST request to a GET request with long query information.
A client has encountered a redirection problem (for example, a redirected URL prefix that points to a suffix of itself).
The server is under attack by a client attempting to exploit security holes present in some servers using fixed-length buffers for reading or manipulating the Request-URI.
Please contact the Web server's administrator if this problem persists.
HTTP Error 415
Unsupported Media Type. The server does not support the resource type requested. Frequently found when attempting to serve up content which may require a plug-in. See also: Mime Types
HTTP Error 416
Requested Range Not Satisfiable. The portion of the resource requested is not available or out of range.
HTTP Error 417
Expectation Failed. The Expect specifier in the HTTP request header can not be met.
500 Range

HTTP Error 500
Internal Server Error: The Web server is incapable of performing the request. Please try your request again later. Please contact the Web server's administrator if this problem persists.
HTTP Error 500.12
Application restarting: There is a problem with the page you are trying to reach and it cannot be displayed.
HTTP Error 500.13
Server too busy: There is a problem with the page you are trying to reach and it cannot be displayed.
HTTP Error 500.15
Requests for Global.asa not allowed: There is a problem with the page you are trying to reach and it cannot be displayed.
HTTP Error 500-100.asp
ASP error: There is a problem with the page you are trying to reach and it cannot be displayed.
HTTP Error 501
Not Implemented: The Web server does not support the functionality required to fulfill the request. Please check your URL for errors, and contact the Web server's administrator if the problem persists.
HTTP Error 502
Bad Gateway: The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request. Please contact the Web server's administrator if the problem persists.
HTTP Error 503
Out of Resources. Service temporarily unavailable - typically because it is currently overloaded.
HTTP Error 504
Gateway Time-Out: Unable to connect to origin web server. The web site you are attempting to access is currently unreachable. This may be due to a network outage, or the web site might be experiencing technical difficulties.
HTTP Error 505
HTTP Version not supported. The request uses a version of HTTP that is not supported.
The Final Word:
The Internet HTTP1.1 protocol specifies the entire set of errors that are recorded by most servers. Please refer to RFC2616 for the authoritative explanation.						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-16 19:10:37 from Web</span>
		</p>]]></description>
	    <pubDate>Fri, 16 Apr 2010 11:10:37 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-13 18:33:01 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=150</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> 变量赋值：DATA=`date -d yesterday +'%y%m%d'`

[oracle@drptest ~]$ DATA=`date -d yesterday +'%y%m%d'`

[oracle@drptest ~]$ echo $DATA

090604

[oracle@drptest ~]$ DATA=`date -d tomorrow +'%y%m%d'`

[oracle@drptest ~]$ echo $DATA

090606


直接显示：date -d yesterday +%y%m%d

[oracle@drptest ~]$ date -d yesterday +%y%m%d

090604

[oracle@drptest ~]$ date -d tomorrow +%y%m%d

090606



顺便补充下data的常用命令：

date命令


date命令的功能是显示和设置系统日期和时间。


该命令的一般格式为： date [选项] 显示时间格式（以+开头，后面接格式）


date 设置时间格式


命令中各选项的含义分别为：


-d datestr, --date datestr 显示由datestr描述的日期


-s datestr, --set datestr 设置datestr 描述的日期


-u, --universal 显示或设置通用时间


时间域


% H 小时（00..23）


% I 小时（01..12）


% k 小时（0..23）


% l 小时（1..12）


% M 分（00..59）


% p 显示出AM或PM


% r 时间（hh：mm：ss AM或PM），12小时


% s 从1970年1月1日00：00：00到目前经历的秒数


% S 秒（00..59）


% T 时间（24小时制）（hh:mm:ss）


% X 显示时间的格式（％H:％M:％S）


% Z 时区日期域


% a 星期几的简称（ Sun..Sat）


% A 星期几的全称（ Sunday..Saturday）


% b 月的简称（Jan..Dec）


% B 月的全称（January..December）


% c 日期和时间（ Mon Nov 8 14：12：46 CST 1999）


% d 一个月的第几天（01..31）


% D 日期（mm／dd／yy）


% h 和%b选项相同


% j 一年的第几天（001..366）


% m 月（01..12）


% w 一个星期的第几天（0代表星期天）


% W 一年的第几个星期（00..53，星期一为第一天）


% x 显示日期的格式（mm/dd/yy）


% y 年的最后两个数字（ 1999则是99）


% Y 年（例如：1970，1996等）


注意：只有超级用户才有权限使用date命令设置时间，一般用户只能使用date命令显示时间。						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-13 18:33:01 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Apr 2010 10:33:01 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-13 17:49:03 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=149</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> date +%d/%b/%Y:%H						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-13 17:49:03 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Apr 2010 09:49:03 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-13 17:43:32 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=148</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> cat access.log|awk '{print $7,"|",$9}'|sort|uniq -c|sort -r						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-13 17:43:32 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Apr 2010 09:43:32 +0000</pubDate>
	</item>
		<item>
	    <title>2010-04-13 14:34:47 #admin</title>
	    <link>http://liuchn.com/help/?act=view&amp;id=147</link>
	    <description><![CDATA[<strong>admin</strong> <span id="prefix" class="says">说</span> cur_path=$(dirname $(which $0))						<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta">2010-04-13 14:34:47 from Web</span>
		</p>]]></description>
	    <pubDate>Tue, 13 Apr 2010 06:34:47 +0000</pubDate>
	</item>
	</channel>
</rss>

