If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below. ** If you are logged in, most ads will not be displayed. **

How to save screen output to a text file?

Dear Linux experts:

On the terminal, usually one can use ">" to pipe output to a text file. However, sometimes, ">" does not work and output message still only go to the screen. For example, if I try to compile a piece of program by typing "make", for example, "make > output.txt". This will not capture all the output message from the computer. Is there a way to capture EVERYTHING to a text file? Thanks!

Re: How to save screen output to a text file?

The method for redirecting stderr differs depending on which shell you are using, but always tends to involve the character "&":
- in csh: program <infile >&outfile
- in bash: program <infile 2>&1 >outfile

lpoulsen was just putting all possibilities in one generic statement; i.e. if inputting from a file, place "< file" before the "2>" or "2>>" and/or if outputting to file, put " file" after the "2>" or "2>>".

Also, just FYI:
"make > output.log" and "make 1> output.log" would be the same
"make >> output.log" and "make 1>> output.log" would be the same
"make 2>&1> output.log" or "make 2>&1>> output.log" puts STDERR *and* STDOUT stuff in the output.log (and "2>>&1>>" doesn't work; i.e. whether to append or not depends on the final redirect symbol)

I stick to STDOUT *or* STDERR (as opposed to *and*) because, as one example, "tar -f tarfile file 2>&1> file.log" doesn't redirect the STDERR to the file (if there is any), but rather to the screen (but "tar -f tarfile file 2> file.log" works as expected).