If I wanted to get the output of the last command stored in a file, for example ~/.last_command.txt(overwriting the output of the previous command), how could I do this in bash so that the output goes to both stdout and this file? I assume that this will be connected with connecting to tee ~/.last_command.txt, but I don’t know what to do, and I definitely don’t want to add this to every command that I run manually.
Also, how can I extend this to save the output of the last n commands?
source
share