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. Martin says:

    Perhaps you could consider BASH history suggest box https://github.com/dvorka/hstr that greatly simplifies navigation through the history and its management.

  2. shabu says:

    Hi,
    while using this commnad “export HISTSIZE=0” it wil delete all users history or related to me(the commands which has executed by me) in the global user account.

  3. Subu says:

    Hi,

    We need the ssh session commands to be redirected to a file everytime they login.

    We have added the below lines under bashrc.

    HISTFILE=/var/tmp/history/$USER.$(date +%d-%m-%Y:%H:%M)
    readonly HISTFILE
    HISTSIZE=5000
    HISTTIMEFORMAT=”%d/%m/%y %T ”

    Its logging all the commands but, when we run history it shows only session history where we want that to show the complete history..

    Please help. thanks in advance.
    Subu.

  4. rehan says:

    var/log/secure provides us below information :

    Mar 20 08:07:07 testing sshd[29749]: Accepted password for oracle from 10.51.1.12 port 49239 ssh2
    Mar 20 08:07:07 testing sshd[29749]: pam_unix(sshd:session): session opened for user oracle by (uid=0)
    Mar 20 08:12:16 testing sshd[29759]: Received disconnect from 10.51.1.12: 11: Disconnect requested by Windows SSH Client.
    Mar 20 08:12:16 testing sshd[29749]: pam_unix(sshd:session): session closed for user oracle

    But what commands that oracle user executed we can not get from the above information?

    /home/oracle/.bash_history provides us information like this about what commands are executed:
    exit
    cat /home/oracle/ashfaq/Auto_Clone/Auto_Clone.sh
    cat /u01/down.sh
    cd /u01/oracle/inst/apps/TESTING_testing/admin/scripts/
    ./adstpall.sh apps/apps
    ./adstrtal.sh apps/apps
    cat /home/oracle/ashfaq/Auto_Clone/Auto_Clone.sh
    ls -ltr
    cat main_exec.sh

    but does not tell us that user from which IP or hostname and at what time executed these commands.

    how we can store all this information in one file with time, IP, user name (root, oracle, ricky ) and commands executed by these users ?

  5. Lee says:

    We can modify History of command ..?

  6. jack says:

    Hi

    I want history like below. is it possible ?

    year time command username

    05/12/13 11:07:36 ls -lah

    • Tom says:

      Hi Jack, of course it’s possible.

      Edit your ~/.bashrc and set the line
      HISTTIMEFORMAT
      to:
      HISTTIMEFORMAT=”%F %T “.

      Exit all your terminals and now it should write a timestamp in the history file.
      (Maybe you have to log out!)

  7. Rahul says:

    Good one, I got a lot from this

  8. VIVEK says:

    Sir
    I am linux trainer. these cmds are very useful

    THANKYOU

    WITH REGARDS

    VIVEK

  9. Ron says:

    Thanks for #2.

  10. 5. unset export HISTCONTROL

    This command unsets two variables, export and HISTCONTROL. It does not just remove HISTCONTROL from the environment; it unsets it entirely.

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.