#显示当前目录文件 test.sh test1.sh test1.sh实际不存在 [chengmo@centos5 shell]$ ls test.sh test1.sh ls: test1.sh: 没有这个文件和目录 test.sh #正确输出与错误输出都显示在屏幕了,现在需要把正确输出写入suc.txt # 1>可以省略,不写,默认所至标准输出 [chengmo@centos5 shell]$ ls test.sh test1.sh 1>suc.txt ls: test1.sh: 没有这个文件和目录 [chengmo@centos5 shell]$ cat suc.txt test.sh #把错误输出,不输出到屏幕,输出到err.txt [chengmo@centos5 shell]$ ls test.sh test1.sh 1>suc.txt 2>err.txt [chengmo@centos5 shell]$ cat suc.txt err.txt test.sh ls: test1.sh: 没有这个文件和目录 #继续追加把输出写入suc.txt err.txt “>>”追加操作符 [chengmo@centos5 shell]$ ls test.sh test1.sh 1>>suc.txt 2>>err.txt #将错误输出信息关闭掉 [chengmo@centos5 shell]$ ls test.sh test1.sh 2>&- test.sh [chengmo@centos5 shell]$ ls test.sh test1.sh 2>/dev/null test.sh #&[n] 代表是已经存在的文件描述符,&1 代表输出 &2代表错误输出 &-代表关闭与它绑定的描述符 #/dev/null 这个设备,是linux 中黑洞设备,什么信息只要输出给这个设备,都会给吃掉 #关闭所有输出 [chengmo@centos5 shell]$ ls test.sh test1.sh 1>&- 2>&- #关闭 1 ,2 文件描述符 [chengmo@centos5 shell]$ ls test.sh test1.sh 2>/dev/null 1>/dev/null #将1,2 输出转发给/dev/null设备 [chengmo@centos5 shell]$ ls test.sh test1.sh >/dev/null 2>&1 #将错误输出2 绑定给 正确输出 1,然后将 正确输出 发送给 /dev/null设备 这种常用 <p>[chengmo@centos5 shell]$ ls test.sh test1.sh &>/dev/null #& 代表标准输出 ,错误输出 将所有标准输出与错误输出 输入到/dev/null文件
[chengmo@centos5 shell]# cat > catfile testing cat file test #这里按下 [ctrl]+d 离开 #从标准输入【键盘】获得数据,然后输出给catfile文件 [chengmo@centos5 shell]$ cat>catfile <test.sh #cat 从test.sh 获得输入数据,然后输出给文件catfile [chengmo@centos5 shell]$ cat>catfile <<eof test a file test! eof #<< 这个连续两个小符号, 他代表的是『结束的输入字符』的意思。这样当空行输入eof字符,输入自动结束,不用ctrl+D
[chengmo@centos5 shell]$ exec 6>&1 #将标准输出与fd 6绑定 [chengmo@centos5 shell]$ ls /proc/self/fd/ 0 1 2 3 6 #出现文件描述符6 [chengmo@centos5 shell]$ exec 1>suc.txt #将接下来所有命令标准输出,绑定到suc.txt文件(输出到该文件) [chengmo@centos5 shell]$ ls -al #执行命令,发现什么都不返回了,因为标准输出已经输出到suc.txt文件了 [chengmo@centos5 shell]$ exec 1>&6 #恢复标准输出 [chengmo@centos5 shell]$ exec 6>&- #关闭fd 6描述符 [chengmo@centos5 ~]$ ls /proc/self/fd/ 0 1 2 3
exec 3<>test.sh; #打开test.sh可读写操作,与文件描述符3绑定 while read line<&3 do echo $line; done #循环读取文件描述符3(读取的是test.sh内容) exec 3>&- exec 3<&- #关闭文件的,输入,输出绑定
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有