I'm trying to view all commands I have entered and their outputs. I understand that I can use 'history' to view all of my recent commands. However, is there a way I can check for previous outputs of those commands? I have tried looking it up and there does not seem to be a way.
-
What is the date of the oldest output you are seeing? Searching for documentation that could help you to see the history of the commands you used in command shell, seems that there is not one way to do it yet. But using Linux, this documentation can help you. https://opensource.com/article/18/6/history-command#:~:text=Another%20way%20to%20get%20to,by%20pressing%20Return%20or%20Enter – Andrés Mar 24 '22 at 22:50
1 Answers
It only stores history of the commands you ran (which you can retrieve by typing history
). Unless you already have set the scroll-back to a very high number, there is no way to see the outputs that are older than the set value of scroll-back. Also setting this value to a very high number will make your scrolling sluggish since the lines are stored in the memory. Cloud Shell uses Tmux, which has a scroll back buffer of 2000 lines by default.
To store your future commands and their outputs, there are few options:
Using screen
Start a screen session by entering screen
. Once you are inside ‘screen’, press Ctrl-a, then :, then enter log
. All the I/O will be captured in screenlog
files in the directory where you started the screen
command.
Using script
You can start by typing script
. A script session will start that will capture all the I/O to a file named typescript
. You can exit the script
session by Ctrl-d and view the logs in the typescript
file.
Using tee
tee is a handy tool. You can do something like this:
$ tmux | tee log.txt
This will open a new bash shell inside the one you are already running. When you exit
out of this, you can see the outputs in the file called log.txt
Other ways
As Dustin Kirkland suggested in this post, you can also use byobu. Although, I have never used terminal screencasting tools such as Shelr also sounds like an option.
Other ways
Cloud Shell commands to run and a link that explains more. This will exit the terminal and thus delete all the scroll back buffer, resetting it to empty, but in the future it will save 5000 lines rather than 2000.
$ tmux show-options -g | grep history
history-limit 2000
$ echo "set -g history-limit 5000" >> ~/.tmux.conf
$ exit
$ tmux show-options -g | grep history
history-limit 5000
If you type…
$ man tmux
… you can find the documentation for this setting (search by typing '/history-limit' + (enter)).
‘history-limit lines’ set the maximum number of lines held in window history. This setting applies only to new windows - existing window histories are not resized and retain the limit at the point they were created.

- 487
- 1
- 12
-
I appreciate your answer. Long done with assignment but this will come in handy next time. – Vinny Mar 30 '22 at 21:21