Run statistics on typed shell commands
Programming Snapshot – Shell Stats

© Lead Image © Scott Rothstein, 123RF.com
In the history log, the Bash shell records all commands typed by the user. Mike Schilli extracts this data with Go for a statistical analysis of his typing behavior.
How did the long command to connect to the database server work again? Shell power users know this memory problem and have taught themselves tricks over the years to repeat or resend modified versions of previously sent command lines. For example, the sequence !!
repeats the last command (useful to prepend a sudo
you might have forgotten); with Ctrl+R you can find and reuse commands that were sent further back in time by using search patterns. Bash remembers the entire typing history and shows it with the history
command, which lists the tail end of what it has in memory (Figure 1).

If you have ever taken a look at the .bash_history
file in your home directory, you will know its little secret. This is where Bash simply appends every command sent, regardless of if it was successful or aborted with an error. If you ask for the last commands you entered, Bash simply looks there (Figure 2).
[...]
Buy this article as PDF
(incl. VAT)