View Terminal Command History in Ubuntu – How to Guide

bash-historyhistory

Is there a way to save all my typed terminal commands and view it like history in a log book?

Best Answer

This is automatically done. Bash stores your commands in ~/.bash_history. If you want to have a look at the history, either print the output of this file using one of

cat ~/.bash_history
less ~/.bash_history
...any other pager or output command...

Or you can use bash's builtin command:

history

To clear the history, delete the file and clear the temp history:

rm ~/.bash_history && history -c

The history size defaults to 500 commands. You can, however, increase this by adding a line to your ~/.bashrc file to set the HISTSIZE variable:

HISTSIZE=<number of entries, -1 for unlimited>

This will not take effect immediately, but only to newly started sessions. To apply this, re-source the .bashrc file:

. ~/.bashrc

or run HISTSIZE=... in your current session.