Search For Command History By Date

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:

Delete An Entry In Your bash_history

Dealing With Duplicates In Your Bash History

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 CTRL + ALT + T and your default terminal should open.

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:

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:

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:

searching command history by date
See? It works! It does show the command used to show these results, of course.

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.

Closure:

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.

Subscribe to Newsletter!
Get notified when new articles are published!
We promise to never share your email!
icon

Author: KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

6 thoughts on “Search For Command History By Date”

    1. It’s likely some grep output coloring, which would be controlled by your .bashrc file.

      Yeah, it’s in there – in this code, I’m pretty sure:

      # enable color support of ls and also add handy aliases
      if [ -x /usr/bin/dircolors ]; then
      test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
      alias ls='ls --color=auto'
      #alias dir='dir --color=auto'
      #alias vdir='vdir --color=auto'

      alias grep='grep --color=auto'
      alias fgrep='fgrep --color=auto'
      alias egrep='egrep --color=auto'
      fi

        1. I’m surprised your distro doesn’t automatically do that. I checked across a couple of them and they both turned the ‘grep’ results red. The alias bits with the grep, egrep, and fgrep are the ones telling grep to use colors. You could add them to your .bash_aliases and that’d probably work.

          You’d have to likely create that file and I’ve not yet done an article on it, but you can use a search engine to get that sorted.

          1. I entered the script you told me about in a bash shell. I checked .bashrc and it is there. I’m not sure why I am not seeing it. I have Linux Mint Cinnamon and my system is less than a year old. Please recommend an entry to see if it has been applied. Maybe (newbie) me is expecting it to show up in the wrong place. Thanks for your patience. I love your articles. My main focus is trying to know my way around bash and the terminal.
            Susan

            1. I checked Mint Cinnamon and it’s colored red there – on my system.

              Maybe try a different terminal? Install Terminator and see if that does the trick.

              sudo apt install terminator

              If that doesn’t work, I’d suggest joining https://linux.org (I’m a moderator there) and you can get this problem in front of more eyes, getting more help.

              Sorry for the delay in responding. I finally got nailed with COVID. It’s not too bad, as I’m vaccinated and boosted. It just feels like the regular flu – fever, chills, body ache, and feeling exhausted. That sorta stuff. I quarantined myself upstairs, and I have toys like a laptop to keep me from being bored. So, it’s not too bad.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.