Monday, June 24, 2013

history - shell built in command

In Bash shell, the following three variables help in configuring the history command

  1. HISTFILE - Where the history  of the exited shell is stored
  2. HISTFILESIZE - How many entries are stored there
  3. HISTSIZE - How many entries are kept in the memory while using the shell.
How  to check if history is enabled or disabled for a user?

Run the following command
              set -o | grep history

The output of the above command shall be either history off or history  on

Eg:  $ set -o | grep history
       history         on

How to enable history for a user?

If  set -o | grep history provides the output as history off, then history can be enabled for the user as follows

1) Add the follow line in the file ~/.bashrc

        set -o history

2) Then check the values of the parameters - HISTFILE, HISTSIZE, HISTFILESIZE

          echo $HISTFILE
          echo $HISTSIZE
          echo $HISTFILESIZE

If the value of echo $HISTFILE is blank or /dev/null, add the following line in ~/.bashrc file

          HISTFILE=$HOME/.bash_history

If HISTSIZE or HISTFILESIZE is set to 0, set it to a value of choice in ~/.bashrc file

        HISTFILESIZE=1000
        HISTSIZE=1000

No comments:

Post a Comment