I know that Ctrl+R let's you search command history, but it's a little primitive. Is there a way to export all my command history (not just the current terminal session, but the full history) to a text file? I could then use a text editor to search it comfortably. Or if the history file already exists, where is it?
HISTFILE The name of the file in which command history is saved. The default value is ~/.bash_history. If unset, the command history is not saved when a shell exits.
So, the variable
HISTFILE will contain the filename where the history will be saved.
$ echo "$HISTFILE" /home/user/.bash_history
You can now search for the pattern:
$ grep "vim" "$HISTFILE" vim foo.text vim bar.text vim file.txt
As @Dennis has pointed out, if you want you can run
history -a to append the command history of the running session to the
$HISTFILE file. Basically the commands will be automatically appended once you close a session,
history -a will do the same thing right at that instant.
help history to get more idea on the
history builtin itself.
history > output.txt less output.txt
Then search by typing
The bash history is saved in your home directory
Basically Ctrl + R searches from this file.