Monday, October 14, 2013

Linux history command(change HISTSIZE variable)

History is a very handy command to see what was typed and executed in a shell for a period of time.
For example, you are troubleshooting Linux server and you want to see the last 20 commands executed.
$ history 20
Or you want to find all commands with sudo word in them.
$ history | grep sudo
You can combine with less, tail and so on, it all depends of your needs.
After search you’ve found a command with number 234 and you want to execute it again.
$ !234
For more details about history command -> man history.
So how this works, how long is history and how to change its size?
Shell command history is stored in a .bash_history file in your /home folder ( cat .bash_history to see all the entries there ).
Number of commands is defined by histsize variable.
Type
$ echo $HISTSIZE
or
$ env | grep HISTSIZE
to see the number of commands that can be stored in this file.
My default number on Oracle Linux is 1000.
But what if you want to store 3000 commands for example, how can you change this variable?
Well quite simply, just use gedit or vi editor.
Change .bash_profile, add HISTSIZE=3000, export this variable to override one in /etc/profile, save file and load the changes with
$ source .bash_profile
Your .bash_profile should look like this
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
………
HISTSIZE=3000
export PATH HISTSIZE
So now you can store up to 3000 command in your history.
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
source ~/.bashrc

Related Posts:

  • Compile httpd 2.4.6-P3 Introduction to Apr The Apache Portable Runtime (APR) is a supporting library for the Apache web server. It provides a set of application programming interfaces (APIs) that map to the underlying Operating System (OS). Wher… Read More
  • SQL Injection through HTTP Headers During vulnerability assessment or penetration testing, identifying the input vectors of the target application is a primordial step. Sometimes, when dealing with Web application testing, verification routines related to SQL… Read More
  • Compile httpd 2.4.6-P2 Introduction to Apr Util The Apache Portable Runtime Utility Library provides a predictable and consistent interface to underlying client library interfaces. This application programming interface assures predictable if no… Read More
  • Compile httpd 2.4.6-P4./configure --help `configure' configures this package to adapt to many kinds of systems. Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. &nbs… Read More
  • Tools mysql This page contains links to various tools we found helpful to use in practice.Some tools are written by us, others by third parties, yet another ones may be shipped with your operating system you just need to find they are t… Read More