Let's say I want to see the output what a command does, such as apt-get. However, if I would run a command redirecting the output such as

apt-get install some-application -y > apt_out.txt


apt-get install some-application -y | tee apt_out.txt

then I would lose the capability to interact with the program's input. Yet my workaround is to use a screen -L session, but would there be something cleaner?

  • 3
    Unless you specify what you find unclean about using screen -L, and what you consider a cleaner option, there is no way to know if an answer will satisfy your condition. E.g. you could select & copy-and-paste the output in your terminal, but whether that is cleaner or not is subjective. – Anthon Sep 24 '17 at 5:44

Let's look at this in terms of feature sets and behaviours rather than some unspecified notion of cleanliness.

A less general-purpose mechanism than screen -L, but that nonetheless does for your purposes what screen does that tee does not (i.e. allow easy interactive use and not make programs drop into their non-interactive or buffered output modes when they find standard output to not be a terminal), is the script command.

script -c "apt-get install some-application" apt_out.txt

A different mechanism to script is ptybandage, which is suitable for use in command pipelines, and does not require that its own, outer, standard I/O actually be a terminal. (Indeed, its primary use case is to make non-interactive standard I/O seem like interactive standard I/O to a child program.) It is a way to persuade the program to run in its interactive/line buffered mode whilst still using the pipe-through-tee approach.

ptybandage apt-get install some-application 2>&1 | tee apt_out.txt

Further reading

| improve this answer | |

screen -L sounds like a good solution to me. Another option is script (this logs control characters and mis-typings as well, which some find confusing).

Many programs test to see if their input and output are connected to a terminal or not, and will fail or change their behaviour depending on this. See ls vs. ls | cat for a tiny example.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.