The Power of Linux “History Command” in Bash Shell

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Narad Shrestha

He has over 10 years of rich IT experience which includes various Linux Distros, FOSS and Networking. Narad always believes sharing IT knowledge with others and adopts new technology with ease.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

25 Responses

  1. jack says:

    How can I filter a many of commands in history? for example i don’t want to show me “ls” command in history file.

    HISTIGNORE='ls' command don't work for me
    • the digitalmouse says:

      Perhaps the easiest is to just filter what you are looking *for* instead of what you are not looking for. Just a standard ‘history | grep (thing you want to find)‘ is enough? Otherwise you should be able to construct a regex in the grep to search what you want *and* ignore the ls lines found.

    • the digitalmouse says:

      rember to ‘export’ that command before using it

  2. the digitalmouse says:

    Great stuff! I would suggest updating the title text for points 11, 12, and 13 to read: “Recall Last…”, not “Recall Lastly…” just to make the tips a bit more readable and could possibly improve search engine results. It is also proper grammar. :) Keep up the good work!

  3. SGTItlog says:

    To clear (totally) all the command history of a certain user (e.g root)

    1. Log-in to that user
    2. cat “” > .bash_history (same as cat /dev/null > .bash_history)
    3. history -c

    Logout and re-login.

  4. Dragos Alexe says:

    Dear Narad,
    If you allow me one suggestion. The ignoredups remove consecutive duplicates; erasedups- eliminate duplicates across the whole history.
    So, if I type multiple times-but not consecutive- the same commands in bash: -l
    2.dir -a -l- the way to remove duplicates from history is : export HISTCONTROL=erasedups.
    Great work!!

  5. Milton Reyes says:

    HISTSIZE=0 is nice if you don’t want to leave traces of history increasing security, however your shell is your working tool and sometimes you need to view the commands you typed previously which you can’t with this limitation.
    Consider this:
    ln -s -f /dev/null ~/.bash_history
    This approach will keep the history through your session and erase it when you close shell or logout

  6. Jack says:

    Thanks for this nice summary on the “history” command. I’ve been using the method with grep as
    in paragraph 10 for years. Now I’ve upgraded my linux system and get the following:
    $ history | grep pwd
    Binary file (standard input) matches
    Any idea what might be misconfigured, making grep consider the output of history to be binary, even
    when it clearly isn’t?

  7. ilya says:

    Good article! Just one question: can anyone explain why all commands in the first example have the same time stamp, 2013-06-09 10:40:12 ?
    Even if you cut and pasted them, commands “ping” would take more than one second, would not they?
    Occasionally I see the same anomaly in my history logs; I wonder if these time stamps are reliable at all?

  8. charm aliros says:

    This article saved tons of my worries. I am not a linux cli expert and I am asked to configure an l2tp server. Did not know how to add iptables rules and so checking the previous commands in a different server, I was able to copy and execute the proper commands!


  9. Satyendra Jaiswal says:

    I really very thankful for your post , it’s very useful for me , I am a beginner in Linux , we can delete all history using “$ history -c” command, but I want to delete my history from last 1 month, or any specified duration , how can we delete by command ,

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.