I am compiling a program using make and want the output of make to be written to a file. I have tried using > operator like
make > build_log.txt
and using tee command like
make | tee build_log.txt
but the problem is that some of the ouput goes into the file but rest keeps appearing on the screen.
I can simply copy/paste the text from terminal into a file after running make but that is not a solution.
So my question is how do I save i.e redirect all the output to file so that it goes into file only without appearing on screen.
The text that is displayed in the terminal comes from the
stderr
stream (2). If you do justmake > build_log.txt
, only thestdout
(1) stream is redirected to thebuild_log.txt
file.stdout
is the standard output stream and has file descriptor number 1. This is the default stream being redirected in shells.stderr
is the standard error stream and has file descriptor number 2To redirect the
stderr
stream to thatbuild_log.txt
file too, use:make
is executed andstdout
stream is redirected (>
) tobuild_log.txt
stderr
stream is redirected (2>
) to thestdout
stream (&1
), which was redirected tobuild_log.txt
The order is important, you cannot switch switch the redirection operators like
make 2>&1 > build_log.txt
.Alternative command:
The redirection to
/dev/null
is needed to hide output,tee
writes its input tobuild_log.txt
and outputs it too.