Shell中将程序控制台输出复制到文件
2015-11-05 13:26
387 查看
在Linux中,如果想将一个程序在控制台中的输出字符输出到文件中,不保留控制台内的文字,可以用下面命令:
some_command > output.txt
命令结果会输出到output.txt中,换成>>可以追加到文件末尾
但如果想输出到文件同时,保留控制台的内容,需要使用tee命令,示例如下:
some_command | tee output.txt
有时会发现上述命令后屏幕有输出,但文件内容为空,此时可能是由于some_command输出的字符从std error文件描述符输出,需要先将std error的输出导向到std output:
some_command 2>&1 | tee output.txt
其中,2代表std error,1代表std output,>&是linux中fd到fd的重定向操作符。
some_command > output.txt
命令结果会输出到output.txt中,换成>>可以追加到文件末尾
但如果想输出到文件同时,保留控制台的内容,需要使用tee命令,示例如下:
some_command | tee output.txt
有时会发现上述命令后屏幕有输出,但文件内容为空,此时可能是由于some_command输出的字符从std error文件描述符输出,需要先将std error的输出导向到std output:
some_command 2>&1 | tee output.txt
其中,2代表std error,1代表std output,>&是linux中fd到fd的重定向操作符。
相关文章推荐
- shell脚本编程之字符串测试及循环
- centos安装tomcat (用shell脚本安装为服务)
- Shell特殊变量:Shell $0, $#, $*, $@, $?, $$和命令行参数
- 教你解决Xshell用SSH连接ubuntu总掉线该
- profile、bashrc、bash_profile区别
- Shell行操作:逐行读取,指定行输出,指定行删除等
- Linux 关机 shutdown -h now 提示 bash:command not found
- linux:Bash常用快捷键
- linux:/用户/.bashrc 保存别名永久生效
- 几个常用的linux快捷键和shell知识
- RHCE 系列(四): 使用 Shell 脚本自动化 Linux 系统维护任务
- shell 连续执行命令
- SHELL常用命令与脚本
- xshell
- .NET通过PowerShell操作ExChange为用户开通邮箱教程
- DOS pause-like command in Bash
- Shell case esac语句
- shell中的条件判断、参数以及变量替换
- -bash: crontab: command not found
- Shell入门之概念