Maybe I'm overlooking something but is there a way to get your current bash history for the current session you are using like
if i run
ssh host $ pwd $ ls $ cd /tmp
I just want to see those 3 commands and nothing else
A slightly roundabout way:
history -a ~/current_history
This will save the current session's unsaved bash history to
~/current_history, which you can then view.
I had the problem that I wanted to write the current
history to a file but still wanted the entries to be recorded in the main bash
I solved this by just attaching the file with
history -a current-history cat current-history >> .bash_history
comp to compare the entire history (incl. current Bash session) with the already persisted history in
.bash_history and only print those lines that are unique to the current session -- which should show only those commands that were executed since starting the current Bash shell
comm -23 <( history | cut -c 8- ) ~/.bash_history
Edit: as @Wildcard pointed out this command does not work for all distributions of
comm. I tested this on Mac OS.
A variation of the same idea using
diff <( history | cut -c 8- ) ~/.bash_history | sed -n 's/^< //pg'