Find the answer to your Linux question:
Results 1 to 5 of 5
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Nov 2006
    Posts
    101

    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!

    phsieh2005

  2. #2
    Just Joined!
    Join Date
    Jan 2008
    Posts
    2

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

    A normal "text mode" program has three files opened on launch:
    - stdin (on FD=0) is standard input
    - stdout (on FD=1) is standard output
    - stderr (on FD=2) is standard error output

    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

  3. #3
    Linux Newbie
    Join Date
    Nov 2006
    Posts
    101

    Thanks!

    Hi, lpoulsen:

    Thanks for the reply!

    I am using bash. Can I use: "make >> output.log 2>&1"? Or "make 2>&1 > output.log"? since make does not have input file.

    phsieh2005

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru gogalthorp's Avatar
    Join Date
    Oct 2006
    Location
    West (by God) Virginia
    Posts
    3,104

  6. #5
    Just Joined!
    Join Date
    Mar 2010
    Location
    Pittsburgh
    Posts
    3

    output to file (bash)

    Quote Originally Posted by phsieh2005 View Post
    I am using bash. Can I use: "make >> output.log 2>&1"? Or "make 2>&1 > output.log"?
    phsieh2005
    2.5 years later, but "better late than never" and I was looking for clarification on this (i.e. so others still might be):

    make 2> output.log # creates/overwrites output.log
    make 2>> output.log # appends to output.log

    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •