Gist

Use bash’s comment char (#) at the command-line prompt to leave yourself a trail of breadcrumbs back to how, why and when, e.g.

$ cd ~/project-foo/
$ # Adding .gitignore file per https://help.github.com/articles/ignoring-files/
$ touch .gitignore

To retrieve your comment breadcrumbs pipe the output from the history command to grep to filter lines containing bash’s comment char (#)1.

Input

$ history | grep \#

Output:

10 # Adding .gitignore file per https://help.github.com/articles/ignoring-files/

histtimeformat

Breadcrumbs are even more useful if you configure the HISTTIMEFORMAT environmental variable by adding the following line to your .bashrc2:

1
2
3
# ~/.bashrc
# show the date and time
export HISTTIMEFORMAT="%Y-%m-%d %T "

To add the HISTTIMEFORMAT variable to your .bashrc and re-source the file do:

$ echo "export HISTTIMEFORMAT="%Y-%m-%d %T " >> ~/.bashrc; source ~/.bashrc

Now, the history | grep \# output will also provide date/time when the line was added to the .bash_history file like:

10  16-08-20 16:40:07    # Adding .gitignore file per https://help.github.com/articles/ignoring-files/
  1. the hash (#) must be escaped with a backslash (\)

  2. or .bash_profile depending on your setup