打印STDOUT / STDERR,并将其写入到猛砸文件? [英] Print STDOUT/STDERR and write them to a file in Bash?

查看:113
本文介绍了打印STDOUT / STDERR,并将其写入到猛砸文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让Bash的重定向STDOUT / STDERR到一个文件,但仍把它们打印出来到终端呢?

Is there a way to have Bash redirect STDOUT/STDERR to a file yet still print them out to the terminal as well?

推荐答案

这都将输出和错误重定向到同一个文件:

This will redirect both STDOUT and STDERR to the same file:

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

这篇关于打印STDOUT / STDERR,并将其写入到猛砸文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆