Bash History
Any new commands that have been issued in the active terminal can be appended to the .bash_history
file with the following command:
history -a
The only tricky concept to understand is that each terminal has its own bash history list (loaded from the .bash_history
file when you open the terminal)
If you want to pull any new history that's been written by other terminals during the lifetime of this active terminal, you can append the contents of the .bash_history
file to the active bash history list
history -c;history -r
This will clear the current history list so we don't get a repeated list, and append the history file to the (now empty) list.
Solution
You can use the bash variable PROMPT_COMMAND
to issue a command with each new prompt (every time you press enter in the terminal)
export PROMPT_COMMAND='history -a'
This will record each command to the history file as it is issued.
Result
Now any new terminal you open will have the history of other terminals without having to exit
those other terminals. This is my preferred workflow.
More Precision
Let's say (for some reason) you have two terminals that you're using simultaneously and you want the history to reflect between both for each new command.
export PROMPT_COMMAND='history -a;history -c;history -r'
The main drawback here is that you may need to press enter to re-run the PROMPT_COMMAND in order to get the latest history from the opposite terminal.
You can see why this more precise option is probably overkill, but it works for that use case.
I faced this exact issue.
Before I locked my screen, I wanted to remove all Evolution package files, and made the mistake of doing so by executing sudo apt remove --purge evolution-*
.
After I locked the screen, I faced the exact scenario that you described.
Turns out, my mistake removed the ubuntu-desktop
package as well (I don't know why).
Installed it again using - sudo apt install ubuntu-desktop
and then sudo reboot
- voila! Got my desktop back.
Edit: Purging Evolution didn't remove ubuntu-desktop
per se, it just deleted some files that support the package.
Best Answer
If you are using BASH, your history should be stored in in the location that is pointed to by the environment variable HISTFILE. You can view this with "echo $HISTFILE". By default, this should be ~/.bash_history. This is also what will be used if $HISTFILE is not set. If HISTFILE is not set to that location, you can set it with the following:
The following will reload the history file into your history buffer:
If this does not resolve your issue, the "HISTORY" section of the bash manpage may give more clues as to why your history is not working as expected.
You may also want to check and make sure your shell has not changed from bash: