I know to check history we use falling command:
export HISTTIMEFORMAT='%F %T '
But it displays history of present day only. How could someone check history of past days?
No, to check the bash history, you use the built-in
history
command.
Setting HISTTIMEFORMAT just sets the format string used for the timestamps displayed in the history file.
After setting this variable to
'%F %T '
- whenever you use the
history
command, you'll get every single command in the file listed, but it will have the "number" of the command in the history file and the timestamp consisting of the date (%F) and the time (%T), followed by the command.
e.g.
Code:
1995 2020-10-12 16:55:05 ls -t | head -n 10
So you'll see every single command in the history file with their time-stamps.
Now, at the time of posting this, the date is the 12th october 2020.
If you look at the man-page for the date command, you'll see that the date format used by %F is YYYY-MM-DD. So today would be 2020-10-12.
Yesterday would have been 2020-10-11.
So - assuming you have the timestamp set - if you want to see the commands from yesterday, you could simply use:
Bash:
history | \grep 2020-10-11
Or, if you didn't know todays date, you could find yesterdays date and use it to filter out commands from yesterday like this:
Bash:
history | \grep "$(date --date='yesterday' +%F)"
Or if you want to find the commands from three weeks ago (assuming there are entries from that long ago):
Code:
history | \grep "$(date --date='-3 weeks' +%F"
Simple!
I use the terminal a lot, so typically - I don't have commands much older than two or three days. If you want to keep a more comprehensive log - you either need to increase the value of HISTSIZE and/or HISTFILESIZE.
OR - if you set them to a negative number - it will log every single command. But it will be up to you to keep an eye on the log-files size.
And if you set it to 0, it won't keep any history at all.