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)
翻译自: https://www.poftut.com/redirect-stderr-stdout-linux-bash/