Today’s article is going to show you how to search for the command history by date. This isn’t hard, but might seem a little advanced for some of the newer users. We’ll be doing this through the terminal, of course. That seems like a good idea to me!
Unless you’ve made some fairly drastic changes, Linux terminals keep a log of previously entered commands. This is on a per-user basis and considered relatively secure, or at least as secure as your user account is. It’s helpful to be able to look at your command history, especially if you’ve forgotten what you did and you really need to undo it!
Previous history articles include:
So, I haven’t really covered the .bash_history (proper name, I suppose) all that much. There really isn’t all that much to cover, but today we’ll learn how to search your command history by date. It’s most useful when you remember when you made changes but you can’t remember the precise commands used when you made those changes.
Find Command History By Date:
Like oh so many articles, this one too requires an open terminal. You can open one easily enough. Just press
With your terminal open, we first have to tell Bash to store and show dates along with the history. That’s an easy command that you need only run once:
export HISTTIMEFORMAT='%F %T'
When you next type ‘
history‘, it’ll look like a hot mess until you figure out what the command has done.
Now, to find command history by date. To do that, you just enter:
history | grep '2022-08-25'
The format for me is YYYY-MM-DD, though I suppose it could be different for others who have an alternative date format set up. I don’t really know, but it’s easy to figure out by just running the history command and deducing the format from those results. If you’ve done it properly, it might look a little something like this:
So, if you want to see what commands were run on a certain date, you can do that. You can also find what you entered when you remember the day but not the commands you entered. It can be pretty handy so search the command history by date. Keep it as a handy tool, as you never know when you’re going to need it.
And there you have it. You have another article in a very long list of articles. This one is handy if you need to know your command history by date. I know I’ve been known to use this myself, largely because I sometimes need to narrow down my history quite a bit, as I do a great deal in the terminal and my history is a hot mess.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.