Change Length of Bash Command History or Disable Bash History Completely

Apr 12, 2012 - 5 Comments

Bash History

A users .bash_history file keeps a running tab of command line history, logging every command that has been entered into the bash prompt. These command history files make it very easy to find and recall past commands that may have been forgotten, and they’re also extremely useful for system administration. We will cover how to change the stored length of these files, how to disable it, and also how to quickly check a users bash history.

Changing Bash History Length

To increase the history length of a users command history, add the following line to .bash_profile:

HISTFILESIZE=2500

The example above will increase the history size to 2500 commands, that can be changed to any other number as deemed appropriate.

Disable Bash History

Setting the HISTFILESIZE number to 0 within .bash_profile will disable bash command history completely:

HISTFILESIZE=0

Having the history file disabled does not effect command recall, but it does prevent a super user from easily seeing the commands entered into another users shell.

Checking Bash History

There’s a few quick ways to see command history, to see your own type:

history

You can also export that command history to a file with the -w flag:

history -w pastbash.txt

To see another users command history, use cat with their .bash_history file instead:

cat /Users/USERNAME/.bash_history

Remember that if USERNAME has set their history file size to zero, nothing will be shown.

Practical Applications for Mac Users
Two of the most common applications for a Mac user is to keep track of defaults entries that have been entered into the Terminal and to quickly find past commands. Query command history and you won’t have to guess what that obscure command was that you entered four months ago that started with a ‘s’.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: William Pearson in Command Line

5 Comments

» Comments RSS Feed

  1. vdiv says:

    Using the bash history is invaluable when trying to remember what one did some time ago. Excellent tips! Thank you!

  2. Stefan says:

    The way I usually disable the bash-history is by symlinking .bash_history to /dev/null.
    Command: ln -s /dev/null /Users/USERNAME/.bash_history

  3. [...] length of history stored still depends on on what HISTFILESIZE is set to, so don’t forget to adjust that to accommodate your needs. Also note that if you clear [...]

  4. lol says:

    `To see another users command history, use cat with their .bash_history file instead:

    cat /Users/USERNAME/.bash_history’

    I hope not.

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates