Happy New Year to All! Wondering if there is a way to display time/date of last use of a command in my history file? ( i.e. .bash_history ). history --help gives:
…“If the HISTTIMEFORMAT variable is set and not null, its value is used
as a format string for strftime(3) to print the time stamp associated
with each displayed history entry. No time stamps are printed otherwise.”
Not sure (tried to pipe history | grep date, etc.; no luck!) if the second line referencing “…format string…to print the time stamp…” is telling me what I want is available or no?
Regular use of history command of course gives 1. (number of command) <tab> <Command>. I’m looking to add time/date <Command> was last used. Any ideas?
Thanks, as always. Again: A Healthy, Safe & Prosperous New Year to all!!
— rob
Thanks @malcolm for quick guidance, as always! I’ll be a couple of days chewing on this. . .concepts & terms from ‘Linux Programmer’s Manual’
Whew. . .like speaking Klingon to me. But will stick with it. Give you a shout by end of week. Thanks!
Thanks for this thread. I’ve long wondered what was the secret to utilizing the numbers in .bash_history, but never came up with useful search terms when I looked.
‘which history’ produces not found, as does ‘cnf history’, yet ‘history --help’ works. How does the history command get run?
Since history is builtin to the shell, you can use
help history
HISTTIMEFORMAT has a default value It is probably set when bash is package/compiled from the distro. (assuming bash is your login shell which the default for openSUSE)
grep -i histtimeformat /etc/bash.bashrc
Afaik which is builtin from other shell but not bash and since which is external command from the shell, It has no knowledge of builtin commands.
a good example is cd, try looking for cd (using bash as your login shell) using which
which cd
It will not output anything, unless of course you have an executable in you PATH that has the same name.
I’d go with type since it is also builtin from the (bash) shell
type cd
type history
Builtins are commands that came from the shell
External commands/executables are located within you PATH which is the value of
There’s a Bash alternative to “fc” – Readline line editing, which is enabled by default – with an Emacs style command interface – change it to a Vi style command interface by adding “set -o vi” to “~/.bashrc” …