Okay, so today I messed around with the `history` command in Zsh, specifically getting timestamps to show up. Turns out, it’s pretty simple.
First, I had to set this thing called `HISTTIMEFORMAT`. It’s basically an environment variable that tells the `history` command how to display the time. I used the `export` command for this, like so:
- First, I tried this command:
`export HISTTIMEFORMAT=’%F %T’`
This sets the format to show the date (`%F`) and time (`%T`). Pretty straightforward, right?
- Then, I typed `history` to see the magic:
Boom! Now my command history was showing dates and times next to each entry. Super useful for remembering when I did what.
I also played around with different date and time formats. For example:
- I also tried this format:
`export HISTTIMEFORMAT=’%Y/%m/%d %T’`
This changes the date format to year-month-day. You can customize it however you like. There are all sorts of format codes you can use.
Oh, and another thing I learned: by default, `history` only shows the last 16 entries. But if you type `history 1`, it’ll show you everything. Kind of like a time machine for your terminal.
So yeah, that was my little adventure with `HISTTIMEFORMAT` and Zsh today. It wasn’t a huge deal, but it’s a nice little trick to have up your sleeve. Now I can see exactly when I ran those commands, which is more helpful than you might think.