如何在Linux Bash中将Stderr重定向到Stdout?

I have an application. This application can be run from the command line. This application is a bit old and requires some optional libraries but I can not find them because of this libraries are deprecated. So when running this application they throw errors to the command line. I will save the standard output of this app but I do not want to save error or warnings. How can I redirect error logs to other file or null?

我有一个申请。 可以从命令行运行此应用程序。 该应用程序有些陈旧,需要一些可选的库,但由于不建议使用此库,因此我找不到它们。 因此,在运行该应用程序时,它们会向命令行抛出错误。 我将保存此应用程序的标准输出,但我不想保存错误或警告。 如何将错误日志重定向到其他文件或为null?

Bash重定向类型 (Bash Redirection Types)

As we know Linux work logic sits up to file operations. So everything in Linux is file. So to access files handles are used. While running applications there is handles automatically created. These handles get numbers to identify.

众所周知, Linux工作逻辑取决于文件操作。 因此,Linux中的所有内容都是文件。 因此要使用文件句柄。 在运行应用程序时,会自动创建句柄。 这些句柄获取数字以进行标识。

  • Standard input named stdin and numbered 

    标准输入名为stdin并编号

  • Standard output named stdout and numbered 1

    标准输出名为stdout ,编号为1

  • Standard error named stderr and numbered 2

    标准错误名为stderr ,编号为2

将标准错误重定向到文件 (Redirect Standard Error To A File)

The standard error is an output type where an application or program-related logs are redirected. We can redirect this error stream into a file like below. We will redirect ls command error into a log file named errors.log

标准错误是一种输出类型,在该输出类型中,应用程序或程序相关的日志将被重定向。 我们可以将此错误流重定向到如下文件中。 我们将ls命令错误重定向到名为errors.log的日志文件中

$ls / 2> errors.log
  • We redirect ls stderr with 2> to the errors.log file

    我们使用2>将ls stderr重定向到errors.log文件

将标准输出重定向到文件(Redirect Standard Output into A File)

$ls / &> log.log
  • Merge standard output and standard error and send log.log

    合并标准输出和标准错误并发送log.log

将标准错误重定向到标准输出 (Redirect Standard Error To Standard Out)

$ls / 2>&1
  • Merge standard output and standard error

    合并标准输出和标准错误

如何在Linux Bash中将Stderr重定向到Stdout? 信息图 (How To Redirect Stderr To Stdout In Linux Bash? Infographic)

  How To Redirect Stderr To Stdout In Linux Bash? Infographic
How To Redirect Stderr To Stdout In Linux Bash? Infographic
如何在Linux Bash中将Stderr重定向到Stdout? 信息图
LEARN MORE  How To Use Linux Nohup Command To Execute Commands After Exit Shell or Terminal?
了解更多信息在退出Shell或终端后如何使用Linux Nohup命令执行命令?

翻译自: https://www.poftut.com/redirect-stderr-stdout-linux-bash/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值