I know you can use tee to log output from a command in a terminal, e.g.:

df -h | tee ~/log.txt

However, how can I do this with a more complex command like this:

xterm -hold -e program arg1 arg2 arg3

I tried this to no avail:

xterm -hold -e matlab -noxterm -nojvm -r "solver('/path/to/a/folder',1)" | tee ~/log.txt

My goal is to log all output of the xterm and not of the original terminal. The

  • so you're trying to get output of matlab ? Apr 14, 2015 at 15:04
  • I am running MATLAB from the command line in a xterm (not using the GUI). Because my MATLAB code has a bug and is crashing quite severely I want to log everything that is shown in xterm to start debugging. Apr 14, 2015 at 15:06

3 Answers 3


You can turn on xterm logging and send all xterm output to a file:

xterm -l -lf logfile.txt -e program

  • sure - but not everyone has logging configured in xterm, and since OP didn't mention it, must assume it's not in OP's xterm. Nov 4, 2016 at 12:52

Redirecting output can change the behavior of programs that run in a terminal. If you want to capture all output of the program use something that does not interfere with the program, e.g., script:

xterm -hold -e script -c "program arguments" output.log

(Linux) or

xterm -hold -e script output.log program arguments

(OSX, other BSD)

Alternatively, you could setup xterm to write its screen to a "printer", e.g., using the printerCommand resource, or using the menu entry Print-All Immediately.

Further reading:


If you want the output of the program that you tell xterm to run, xterm -hold -e " program arg1 arg2 arg3 | tee ~/log.txt"

So for instance , in my Ubuntu I'd run from gnome-terminal something like xterm -hold -e " firefox | tee ~/log.txt"

There's also an option to log errors with

xterm -hold -e program 2> errors.txt which redirects any errors that usually go to console, to file

But this is a bit redundant, i think. Running a program from one terminal into another.

You must log in to answer this question.

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