Skip to main content

Use compcomm 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 
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:

diff <( history | cut -c 8- ) ~/.bash_history | sed -n 's/^< //pg' 

Use 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:

diff <( history | cut -c 8- ) ~/.bash_history | sed -n 's/^< //pg' 

Use comm 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:

diff <( history | cut -c 8- ) ~/.bash_history | sed -n 's/^< //pg' 
adding an alternative command using the same basic idea
Source Link

Use 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:

diff <( history | cut -c 8- ) ~/.bash_history | sed -n 's/^< //pg' 

Use 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.

Use 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:

diff <( history | cut -c 8- ) ~/.bash_history | sed -n 's/^< //pg' 
adding restriction that solution works not on all distributions
Source Link

Use 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.

Use 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 

Use 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.

Source Link
Loading