Linux History command with examples

1

To view the list of commands executed by the user.

# history

To view the total history size in the server

# echo $HISTSIZE
1000

To modify the total history size in the server. for eg I’m going to set the history size to 1500

# export HISTSIZE=1500
# echo $HISTSIZE
1500

To set the history command size to 1500 in the HISTFILESIZE.

# export HISTFILESIZE=1500
# echo $HISTFILESIZE
1500

To ignore the commands that not needed to store in the history. Below example shows how to exclude the cat command in the history.

Output took before excluding the cat command

# history | tail -10
   80  date
   81  ls
   82  ls
   83  history
   84  history | grep tail -10
   85  history | tail -10
   86  pwd
   87  cd /root/
   88  ls
   89  history | tail -10
# export HISTIGNORE="cat*"
# cat test.txt

If you see now the output of history command, you can notice that cat command not stored in the history.

# history | tail -10
   82  ls
   83  history
   84  history | grep tail -10
   85  history | tail -10
   86  pwd
   87  cd /root/
   88  ls
   89  history | tail -10
   90  export HISTIGNORE="cat*"
   91  history | tail -10

To turn off not to store any command information in the history.

# set +o history

To turn on back to store command information in the history

# set -o history

To display the commands in history with time stamp

# export HISTTIMEFORMAT="%d/%m/%y %T "

# history | tail -10
  104  09/11/16 18:58:29 ls
  105  09/11/16 18:58:34 history
  106  09/11/16 19:00:28 export HISTTIMEFORMAT=%d/%m%y %T"
  107  09/11/16 19:00:32 export HISTTIMEFORMAT="%d/%m%y %T"
  108  09/11/16 19:00:35 history
  109  09/11/16 19:00:47 history | tail -10
  110  09/11/16 20:09:51 export HISTTIMEFORMAT="%d/%m/%y %T"
  111  09/11/16 20:09:53 history | tail -10
  112  09/11/16 20:11:19 export HISTTIMEFORMAT="%d/%m/%y %T "
  113  09/11/16 20:11:21 history | tail -10

Recommended For You

About the Author: admin

Leave a Reply

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

Subscribe To Our Newsletter
Subscribe to our email newsletter today to receive updates on the latest news, tutorials and special offers!
No Thanks
Thanks for signing up. You must confirm your email address before we can send you. Please check your email and follow the instructions.
We respect your privacy. Your information is safe and will never be shared.
Don't miss out. Subscribe today.
×
×
WordPress Popup Plugin