Home » Linux » Retrieving command line history

Retrieving command line history

Posted by: admin November 30, 2017 Leave a comment


I use ubuntu 11.04, and the question must be common to any bash shell. Pressing the up arrow key on your terminal will retrieve the previous command you had executed at your terminal.

My question is where(in which file) will all these command history be stored? Can I read that file?


the history filename was stored in variable : $HISTFILE

echo  $HISTFILE 

will give you the right file.

Usually in bash it would be ~/.bash_history, however it could be changed by configuration.

also notice that sometimes the very last commands is not stored in that file. running

history -a

will persistent.

history -r 

will clean those command not yet written to the file.


For bash, it is by default in ~/.bash_history (check the HISTFILE environment variable if it isn’t). You can directly cat the file or use the history command.