linux - BASH - 如何将输出 1 和 2 重定向到文件和屏幕?

标签 linux bash

如何将输出 1 和 2 重定向到文件和屏幕?

command 2 1 > /tmp/log and 2 1 screen

所有输出到文件和屏幕

谢谢

最佳答案

tee 命令将输出定向到文件和 tty。

echo 'hi there'  2>&1 | tee outputfile

向输出文件和 tty 写入相同的“hi there”。 这将重定向 1 和 2。

根据您的描述尝试脚本:

Linux / Unix Command: script

 Command Library
NAME

script - make typescript of terminal session  
SYNOPSIS

script [-a ] [-f ] [-q ] [-t ] [file ]  
DESCRIPTION

Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1).
If the argument file is given, script saves all dialogue in file If no file name is given, the typescript is saved in the file typescript

关于linux - BASH - 如何将输出 1 和 2 重定向到文件和屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15352480/

相关文章:

c++ - C++:使用waitpid时等待子进程终止

未在范围内声明的 C++ 转换仅发生在服务器上

linux - 使用 'sh' 运行脚本时无法使用内置 bash 命令

linux - awk + ​​从用双引号定义的行打印字段

linux - 从文件中过滤具有给定前缀的特定行

.net - 如何在 Kubernetes 中部署.net core?

Linux ext2 文件系统为什么会有删除时间?

Bash shebang 选项 -l

Windows Ubuntu Bash SSH 进入 Github

c++ - 子线程退出时如何通知父线程