[Bash] Bash history tips

Changing bash history length

To increase the history length of your command history simply redefine the HISTFILESIZE variable into your .bash_profile. For example:

HISTFILESIZE=2000

will quadruple the default value.

Checking bash history

Everybody know the standard history command, but do you know you this command can take options ?

For example for displaying only the last 5 commands:

history 5

For writing the current display to a file:

history -w /tmp/foobar.txt

There is a ton of other options for modify or filter the ouput, built-in into the history command.

Disable bash history

Setting the HISTFILESIZE variable to zero will disable bash command history completely. Having the history file disabled does not effect command recall for the current session.

Executing commands from bash history

Just give the command number. For example for the 51th command:

!51

For the last command use the shortcut: !!.

Dealing with multiple bash session

By default, bash writes its history at the end of each session, overwriting the existing file with an updated version. This means that if you are logged in with multiple sessions, only the last one to exit will have its history saved.

To bypass this limitation you can add the following into your .bashrc:

shopt -s histappend

Unlimited bash history

Beware: unlimited bash history could slow down your session.
If you want an unlimited bash history you can modify your .bash_profile like this:

# Unlimited bash history setting
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
export HISTFILE=~/.bash_unlimited_history

What is the difference between HISTSIZE and HISTFILESIZE ?

HISTSIZE is the number of lines or commands that are stored in memory in a history list while your bash session is ongoing.

HISTFILESIZE is the number of lines or commands that are allowed in the history file at startup time of a session, and also are stored in the history file at the end of your bash session.

Varnish

varnish is a reverse-proxy build exclusively for web acceleration. It speed up websites by caching their contents in memory and serve the requested objects (HTML pages, images, css, js, etc…) directly instead of the HTTP server.

It not only reduce user-perceived page load time, but also increase platform load capacity. Varnish is licensed under the two-clause BSD license, but commercial support is also available from Varnish-software.

Architecture / Performance

The big plus of Varnish compared to using a classic proxy, like Squid, in reverse mode, is it ability to store data in virtual memory and lets the kernel decide what to do with it (place the object in RAM or swap or anything else). This behavior make Varnish very memory efficient.

Varnish is also massively multi-threaded, queuing incoming connection only when it reaches its limit or when multiple users ask for the same non-cacheable resource. Also in order to reduce system calls, varnish logs requests in shared memory. In a nutshell: varnish is clearly build for performance.

Configuration

Configuration is done via a specific ‘pseudo-language’ called VCL. VCL is trans-coded into C code and compiled as a shared object when reloading the configuration. If you know what you do, you can add C code into a VCL setting file to increase varnish functionalities.

Speaking of functionalities, varnish supports round-robin load balancing and most ESI standard tags, which simplify a lot the inclusion of dynamic content into ‘static’ cachable pages.