将所有输出重定向到文件[重复]

本文翻译自:Redirect all output to file [duplicate]

This question already has an answer here: 这个问题已经在这里有了答案:

I know that in Linux, to redirect output from the screen to a file, I can either use the > or tee . 我知道在Linux中,要将输出从屏幕重定向到文件,我可以使用>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? 有没有办法将所有输出重定向到文件?


#1楼

参考:https://stackoom.com/question/S0IR/将所有输出重定向到文件-重复


#2楼

To get the output on the console AND in a file file.txt for example. 例如,要在控制台上并在文件file.txt获取输出。

make 2>&1 | tee file.txt

Note: & (in 2>&1 ) specifies that 1 is not a file name but a file descriptor. 注意: & (在2>&1 )指定1不是文件名而是文件描述符。


#3楼

使用>>附加:

command >> file


#4楼

You can use exec command to redirect all stdout/stderr output of any commands later. 以后可以使用exec命令重定向所有命令的所有stdout / stderr输出。

sample script: 示例脚本:

exec 2> your_file2 > your_file1
your other commands.....

#5楼

Use this - "require command here" > log_file_name 2>&1 使用它- "require command here" > log_file_name 2>&1

Detail description of redirection operator in Unix/Linux. Unix / Linux中重定向运算符的详细描述。

The > operator redirects the output usually to a file but it can be to a device. >运算符通常将输出重定向到文件,但也可以重定向到设备。 You can also use >> to append. 您也可以使用>>进行追加。

If you don't specify a number then the standard output stream is assumed but you can also redirect errors 如果您未指定数字,则假定使用标准输出流,但是您也可以重定向错误

> file redirects stdout to file
1> file redirects stdout to file
2> file redirects stderr to file
&> file redirects stdout and stderr to file

/dev/null is the null device it takes any input you want and throws it away. / dev / null是空设备,它将接收您想要的任何输入并将其丢弃。 It can be used to suppress any output. 它可以用来抑制任何输出。


#6楼

In Linux Mint, this command string routed executing script and errors to a single txt file. 在Linux Mint中,此命令字符串将执行脚本和错误路由到单个txt文件。 bash -x ./setup.sh > setup.txt 2>&1 . bash -x ./setup.sh > setup.txt 2>&1 Script name was setup.sh and output destination was setup.txt. 脚本名称为setup.sh,输出目标为setup.txt。

发布了0 篇原创文章 · 获赞 75 · 访问量 56万+

猜你喜欢

转载自blog.csdn.net/w36680130/article/details/105483052