I am using the tee command to output the compilation errors of a program into a file along with the terminal.

gcc hello.c | tee file.txt 

This is the command I have used. The compilation errors are displayed on the terminal but they are not outputted in the file. How should I output the std errors into file?

  • OK, good. Any question ? Jan 7, 2015 at 9:53
  • tee only redirects stdout, compilation errors are presumably being output to stderr. See this post for more info on redirecting stderr with tee
    – Josh Jolly
    Jan 7, 2015 at 9:59

1 Answer 1


With csh, tcsh, zsh or recent versions of bash, try

gcc hello.c |& tee file.txt


  • |& instruct the shell to redirect standard error to standard output.

In other Bourne-like shells:

gcc hello.c 2>&1 | tee file.txt

In rc-like shells:

gcc hello.c >[2=1] | tee file.txt

In the fish shell:

gcc hello.c ^&1 | tee file.txt
  • This is a bash 4 feature. For older versions of bash, use 2>&1 | instead. Jan 7, 2015 at 10:07
  • @AnsgarEsztermann, that's a (t)csh feature, also available in zsh and recently added to bash. Jan 7, 2015 at 10:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .