将所有输出重定向到 Bash 中的文件 [英] Redirect all output to file in Bash

查看:29
本文介绍了将所有输出重定向到 Bash 中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在 Linux 中,要将输出从屏幕重定向到文件,我可以使用 >tee.但是,我不确定为什么部分输出仍然输出到屏幕而不是写入文件.

I know that in Linux, to redirect output from the screen to a file, I can either use the > or tee. However, I'm not sure why part of the output is still output to the screen and not written to the file.

有没有办法将所有输出重定向到文件?

Is there a way to redirect all output to file?

推荐答案

那部分写到stderr,使用2>重定向.例如:

That part is written to stderr, use 2> to redirect it. For example:

foo > stdout.txt 2> stderr.txt

或者如果你想要在同一个文件中:

or if you want in same file:

foo > allout.txt 2>&1

注意:这适用于 (ba)sh,请检查您的 shell 的语法是否正确

Note: this works in (ba)sh, check your shell for proper syntax

这篇关于将所有输出重定向到 Bash 中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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