The other night I was reading AU Q&A and used a bash command:
inxi -????
Problem is today I don't remember characters comprising ????. I want to put the command and parameters into my documentation spreadsheet. Based on an this answer (How to recall history in teminal) I used this command:
$ cat .bash_history | grep inxi
inxi -b
sudo apt install inxi
inxi -b
However the command I want isn't there even though the history goes far back. I've used the inxi
commands many times in the terminal since that old history but none of is showing up.
I've also tried Ctrl+R+inxi without any luck. Because I open multiple terminal windows all the time is history tied to a specific window?
Is there a different way to grep
bash history file(s)?
Note that I do not prefix terminal commands with a Space Bar such that they are supressed from history.
Best Answer
I can't know what happened without access to your machine but here is a short explanation of how the history system works which might help you figure out what happened.
Each open terminal has its own history buffer. These buffers are appended to your
$HISTFILE
when the terminal is closed (maybe also whenever the buffer is filled, but I don't know how often that happens). Now, the way to search for a command in your history is to simply run:But if the command was run in a different shell, you won't see it in the history of your current one. To fix that, you close all open shells, open a new terminal window and search your history again.
If that still doesn't help, you've probably passed the threshold of commands stored in the
$HISTFILE
. The behavior of the$HISTFILE
is controlled by various environment variables (seeman bash
for the full list), but the relevant ones here are:The higher values you set these to, the more commands you'll keep in your
$HISTFILE
. For example, I use:If you want to import the history from one shell into another, you can use the
history
command:So, run
history -a
to write the history from one terminal and thenhistory -w
to read it from the another. Now, runninghistory
will show you the history of both shells.Finally, you can make all your terminals share the same history by adding these lines to your
~/.bashrc
:I also suggest you add this: