linuxbashubuntu-11.04

Retrieving command line history


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?


Solution

  • 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.