linux各种数据流重定向
来源:互联网 发布:遇上网络诈骗怎么办 编辑:程序博客网 时间:2024/05/16 15:46
分类: linux管理2013-08-13 20:40 312人阅读 评论(0) 收藏 举报
- > :以覆盖的方法将『正确的数据』输出到指定的文件或装置上
- 1> :以覆盖的方法将『正确的数据』输出到指定的文件或装置上
- 1>>:以累加的方法将『正确的数据』输出到指定的文件或装置上
- 2> :以覆盖的方法将『错误的数据』输出到指定的文件或装置上
- 2>>:以累加的方法将『错误的数据』输出到指定的文件或装置上
- <:将原本需要由键盘输入的数据,改由文件内容来取代
- <<:代表的是『结束的输入字符』
例如:『我要用 cat 直接将输入的信息输出到 catfile 中, 且当由键盘输入 eof 时,该次输入就结束』,那我可以这样做:
- [root@www ~]# cat > catfile << "eof"
- > This is a test.
- > OK now stop
- > eof <==输入这关键词,立刻就结束而不需要输入 [ctrl]+d
- [root@www ~]# cat catfile
- This is a test.
- OK now stop
还有一个“<<-”,主要是为了在输出是忽略掉语句前面的一个或者多个tab符,看下面的例子:
#!/bin/bash
cat << EOF
123
456
EOF
输出为:
cat << EOF
123
456
EOF
输出为:
123
456
如果改成:
#!/bin/bash
cat <<- EOF
123
456
EOF
cat <<- EOF
123
456
EOF
输出为:
123
456
- 2>& 1:将正确和错误的数据全部写入到指定文件或装置上
例如:
- yan@yan-vm:~$ ll /root/ /home/ > result 2>& 1
- yan@yan-vm:~$ cat result
- /home/:
- total 16
- drwxr-xr-x 4 root root 4096 Jun 4 13:03 ./
- drwxr-xr-x 23 root root 4096 Apr 12 20:43 ../
- drwx------ 2 normaluser normalgroup 4096 Jun 4 13:14 normaluser/
- drwxr-xr-x 24 yan yan 4096 Jun 5 06:36 yan/
- ls: cannot open directory /root/: Permission denied
下面我们来衍生几种用法,大家猜猜看运行结果是什么:
- ll /root/ /home/ > result 1>&2
- ll /root/ /home/ 2> result 1>&2
- ll /root/ /home/ 2>&1 > result
- yan@yan-vm:~$ ll /root/ /home/ > result 1>&2
- /home/:
- total 16
- drwxr-xr-x 4 root root 4096 Jun 4 13:03 ./
- drwxr-xr-x 23 root root 4096 Apr 12 20:43 ../
- drwx------ 2 normaluser normalgroup 4096 Jun 4 13:14 normaluser/
- drwxr-xr-x 24 yan yan 4096 Jun 5 06:36 yan/
- ls: cannot open directory /root/: Permission denied
- yan@yan-vm:~$ cat result
- yan@yan-vm:~$
将错误的数据(包含正确的数据)显示到屏幕上。
- yan@yan-vm:~$ ll /root/ /home/ 2> result 1>&2
- yan@yan-vm:~$ cat result
- /home/:
- total 16
- drwxr-xr-x 4 root root 4096 Jun 4 13:03 ./
- drwxr-xr-x 23 root root 4096 Apr 12 20:43 ../
- drwx------ 2 normaluser normalgroup 4096 Jun 4 13:14 normaluser/
- drwxr-xr-x 24 yan yan 4096 Jun 5 06:36 yan/
- ls: cannot open directory /root/: Permission denied
将正确的数据写到屏幕上,但是此时正确的数据为空,所以没有任何信息显示在屏幕上。
- yan@yan-vm:~$ ll /root/ /home/ 2>&1 > result
- ls: cannot open directory /root/: Permission denied
- yan@yan-vm:~$ cat result
- /home/:
- total 16
- drwxr-xr-x 4 root root 4096 Jun 4 13:03 ./
- drwxr-xr-x 23 root root 4096 Apr 12 20:43 ../
- drwx------ 2 normaluser normalgroup 4096 Jun 4 13:14 normaluser/
- drwxr-xr-x 24 yan yan 4096 Jun 5 06:36 yan/
- yan@yan-vm:~$
0 0
- linux各种数据流重定向
- linux各种数据流重定向
- LINUX 数据流重定向
- linux数据流重定向
- Linux数据流重定向
- [Linux] 数据流重定向
- linux数据流重定向
- linux 数据流重定向
- Linux数据流重定向
- linux数据流重定向
- Linux数据流重定向
- Linux数据流重定向
- Linux数据流重定向
- Linux数据流重定向
- Linux 数据流重定向
- Linux数据流重定向
- Linux 之 数据流重定向
- Linux中的数据流重定向
- 三.Java基础_面向对象(一)
- 解题报告之——hdu1233还是畅通工程(最小生成树)
- ss命令
- 淘宝技术发展(分布式时代:服务化)
- @selector
- linux各种数据流重定向
- soft cascade(opencv dev-3.00 version)
- ios 内存管理
- ping命令
- 科普:SDN(软件定义网络)
- windows xp 待机
- zhangenmingLKR
- lua table操作实例详解 lua_gettable
- 解决方法:Ubuntu12.04安装Qt5.0后,首次运行,编译失败,提示 can`t find -Igl