linux 输出重定向
2015-09-11 15:40
549 查看
格式:
command-line1 [1-n] > file或文件操作符或设备
上面命令意思是:将一条命令执行结果(标准输出,或者错误输出,本来都要打印到屏幕上面的) 重定向其它输出设备(文件,打开文件操作符,或打印机等等)1,2分别是标准输出,错误输出。
command-line1 [1-n] > file或文件操作符或设备
上面命令意思是:将一条命令执行结果(标准输出,或者错误输出,本来都要打印到屏幕上面的) 重定向其它输出设备(文件,打开文件操作符,或打印机等等)1,2分别是标准输出,错误输出。
#显示当前目录文件 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 #& 代表是已经存在的文件描述符,&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文件 </p>
相关文章推荐
- linux时间同步,ntpd、ntpdate
- linux ntp ntpdate 同步时间
- Linux学习6_Linux下载文件命令wget用法介绍
- Linux 环境下如何使 Chrome 浏览器字体更漂亮
- linux (CentOS)安装python-tesseract 用于验证码识别
- linux DNS配置
- CentOS 6.3从自带的Pyhon版本
- SElinux 学习笔记一
- Linux搭建DNS服务器
- centos 一键安装jdk
- 0911_Linux命令整理
- 虚拟机centos6.5 --VirtualBox设置全屏
- 深入理解linux内核poll机制
- centos安装与配置dhcp服务
- linux终端nohup置空
- sed one line
- Linux中替换文本中的字符串
- awk one line(老文章了,新老Administrator都用得到其中部分)
- python图像处理环境配置(linux+windows)
- 把windows目录挂载mount到linux下,非root用户没有写权限解决方法