linux - 打印 STDOUT/STDERR 并将它们写入 Bash 中的文件?

标签 linux bash stdout stderr io-redirection

有没有办法让 Bash 将 STDOUT/STDERR 重定向到一个文件,同时仍然将它们打印到终端?

最佳答案

这会将 STDOUT 和 STDERR 重定向到同一个文件:

some_command 2>&1 | tee file.log

例子

$ touch foo; ls foo asfdsafsadf 2>&1 | tee file.log
ls: asfdsafsadf: No such file or directory
foo
$ cat file.log
ls: asfdsafsadf: No such file or directory
foo

关于linux - 打印 STDOUT/STDERR 并将它们写入 Bash 中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4739418/

相关文章:

linux - 在系统内安全存储加密 key 的 TPM 替代方案

linux - 无法删除 Vim 中的右滚动条

java - 什么是 Tomcat 运行?

linux - 在循环中捕获 bash 函数的返回值和输出

svn - 用于迭代定义的文件名集并执行命令的 Bash 脚本

c - 在可移植 C 中将标准输出移出控制台

c++ - 在qt中创建线程时出错

macos - shell脚本等待java jar文件完成

Haskell 编译 IO-Action 顺序和刷新

linux - 捕获其他程序stderr和stdout的程序