Redirect all output to a file [duplicate]

This article was translated from: Redirect all output to file [duplicate]

This question already has an answer here: 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. I know that in Linux, to redirect output from the screen to a file, I can use >OR tee. However, I'm not sure why part of the output is still output to the screen and not written to the file. However, I'm not sure why part of the output will still be output to the screen without writing to the file.

Is there a way to redirect all output to file? Is there a way to redirect all output to file ?


#1st Floor

Reference: https://stackoom.com/question/S0IR/ redirect all output to a file-duplicate


#2nd Floor

To get the output on the console AND in a file file.txtfor example. For example, to get the output on the console and in the file file.txt.

make 2>&1 | tee file.txt

Note: &(in 2>&1) specifies that 1is not a file name but a file descriptor. Note: (in ) specifies not a file name but a file descriptor .&2>&11


#3rd floor

Use >>additional:

command >> file


#4th floor

You can use execcommand to redirect all stdout / stderr output of any commands later. You can use command to redirect all stdout / stderr output of all commands in the future exec.

sample script: sample script:

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

#5th Floor

Use this - "require command here" > log_file_name 2>&1 use it -"require command here" > log_file_name 2>&1

Detail description of redirection operator in Unix / Linux. A detailed description of the redirection operator in Unix / Linux .

The> operator redirects the output usually to a file but it can be to a device. The> operator usually redirects the output to a file , but can also be redirected to a device. You can also use >> to append. 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 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 is an empty device, it will receive any input you want and discard it. It can be used to suppress any output. It can be used to suppress any output .


#6th floor

In Linux Mint, this command string routed executing script and errors to a single txt file. In Linux Mint, this command string routes the execution script and errors to a single txt file. 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. The script name was setup.sh and the output destination was setup.txt.

Published 0 original articles · praised 75 · 560,000 views +

Guess you like

Origin blog.csdn.net/w36680130/article/details/105483052