Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

BASH History Control

Submitted by on May 12, 2015 – 12:01 pm

The standard output of the “history” command will show you the last one thousand commands executed by the user. This is useful, of course, but there are a few issues. Sometimes it’s important to know when a particular command was executed and the default history format does not provide this information. Can’t really call it “history” without dates. Another issue is duplicate and redundant commands in the history: you don’t really need to now the user ran the “ls” command ten times in a row, do you?

The format of BASH command history is controlled by the .bashrc file. Below are the recommended settings for the BASH history. Keep in mind that these settings are not retroactive: they will only apply to the commands you run after making this change. Thus, don’t expect to see accurate timestamps for commands you ran at some point in the past.

export HISTTIMEFORMAT='| %F %T | '
export HISTSIZE=10000
#export HISTCONTROL=erasedups
export HISTCONTROL=ignoredups
export HISTIGNORE="uname:uname *:whoami:ls:ls *:pwd:df:df *:grep *:cat *:tail *:history"
shopt -s histappend

For the HISTCONTROL option you have two choices: to erase duplicates or to just not display them. The HISTIGNORE setting controls the list of commands that will not be displayed when you run the “history” command. Knowing these commands were executed at some point in the past gives you no practical information and clutters the output of the “history” command.

Print Friendly, PDF & Email

Leave a Reply