0

The line numbers from less -N .bash_history and wc -l .bash_history have 44 more lines than the line numbers shown by the bash built-in command history. Comparing the last 20 entries in the history list displayed by history against the last 20 entries in the history file displayed by less shows that those commands are the same, which rules out duplicate commands as the reason, so what is causing the different line numbers between the history command and wc or less?

I initially assumed that the history command simply counted the commands in the history file but the different results with less -N or wc -l indicate this is not the case

  • 1
    What are your HISTSIZE and HISTFILESIZE? – muru Jul 24 at 15:20
  • @muru pardon my late response. Both HISTSIZE and HISTFILESIZE are 50000 – MyWrathAcademia Jul 30 at 19:09
0

This is due to the bash_history may be recording the Epoch timestamp of every command.

HISTTIMEFORMAT environment variable is set in the bashrc file as HISTTIMEFORMAT="[%F %T] "), bash stores timestamps for each history item and when a user inspects history with the BASH built-in history, the timestamps are shown in an easily-readable format (ex: 2019-07-24 15:40:19); however, when these history sessions are saved out to a file (e.g., ~/.bash_history), the timestamps are shown in Unix time (seconds since the Epoch).

You may use history with option -r or -w to input the .bash_history file.

https://ss64.com/bash/history.html

I hope this answers your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.