Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 758
Greenhorn Avatar asked Dec 19 '11 13:12

Greenhorn


People also ask

How can I see all command line history?

Here's how: Open Start. Search for Command Prompt, and click the top result to open the console. Type the following command to view the command history and press Enter: doskey /history.

Can I see history of commands in cmd?

To see the list of recently executed commands in CMD, press the F7 key. This will open a pop-up inside CMD showing the list of recently executed commands. You can select any command and press enter and that specific command will be executed again.

How do I find command history in terminal?

Open a terminal application on your Linux or Unix and type history to list all commands. To search for a command in the history, press ctrl+r multiple times. For instance, you can hit the ctrl+r and type string to search.


2 Answers

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.

like image 173
Kent Avatar answered Sep 21 '22 15:09

Kent


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.

like image 23
Chewie Avatar answered Sep 20 '22 15:09

Chewie