admin说在A执行命令去取B的数据
1.在A的用户目录下的.ssh2目录下生成密钥:用命令 ssh-keygen2,生成一个私钥一个公钥,公钥是以.pub结尾的
2.将公钥拷贝到B的用户目录下的.ssh2下。
3.在A的用户目录的.ssh2目录下,建立文件 identification文件,内容是 idkey 私钥
4.在B的用户目录的.ssh2目录下,建立文件 authorization文件,内容是key 公钥
admin说一、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
admin说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
admin说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
admin说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的效率应该更高!
admin说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
数据统计:24 小时内发布0篇 ... 一周内发布0篇 ... 总发布数182
