Jump to content

Change Length of Bash Command History or Disable Bash History Completely


Recommended Posts

Posted

<div class="KonaBody"><p><img src="http://osxdaily.com/wp-content/uploads/2012/04/bash_history.gif" alt="Bash History" title="bash_history" width="611" height="294" class="aligncenter size-full wp-image-29335" /></p>

<p>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.</p>

<h2 style="font-size:1.2em;">Changing Bash History Length</h2>

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

<p><code>HISTFILESIZE=2500</code></p>

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

<h2 style="font-size:1.2em;">Disable Bash History</h2>

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

<p><code>HISTFILESIZE=0</code></p>

<p>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.</p>

<h2 style="font-size:1.2em;">Checking Bash History</h2>

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

<p><code>history</code></p>

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

<p><code>history -w pastbash.txt</code></p>

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

<p><code>cat /Users/USERNAME/.bash_history</code></p>

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

<p><strong>Practical Applications for Mac Users</strong>

Two of the most common applications for a Mac user is to <a href="http://osxdaily.com/2012/01/31/see-all-previously-used-defaults-commands/">keep track of defaults entries</a> that have been entered into the Terminal and to quickly find past commands. <a href="http://osxdaily.com/2011/02/06/print-and-query-command-history-to-find-past-commands/">Query command history</a> and you won’t have to guess what that obscure command was that you entered four months ago that started with a ‘s’.</p>

</div>

<p><a href="http://feedads.g.doubleclick.net/~a/TAAovMtWRJ4BXfhcEhPel_mcS_0/0/da"><img src="http://feedads.g.doubleclick.net/~a/TAAovMtWRJ4BXfhcEhPel_mcS_0/0/di" border="0" ismap="true"></img></a><br/>

<a href="http://feedads.g.doubleclick.net/~a/TAAovMtWRJ4BXfhcEhPel_mcS_0/1/da"><img src="http://feedads.g.doubleclick.net/~a/TAAovMtWRJ4BXfhcEhPel_mcS_0/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">

<a href="http://feeds.feedburner.com/~ff/osxdaily?a=dAIocjXYoG8:dVhMezOjREA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=dAIocjXYoG8:dVhMezOjREA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=dAIocjXYoG8:dVhMezOjREA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=dAIocjXYoG8:dVhMezOjREA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=dAIocjXYoG8:dVhMezOjREA:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=dAIocjXYoG8:dVhMezOjREA:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=dAIocjXYoG8:dVhMezOjREA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=qj6IDK7rITs" border="0"></img></a>

</div><img src="http://feeds.feedburner.com/~r/osxdaily/~4/dAIocjXYoG8" height="1" width="1"/>

 

View the full article

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic


×
×
  • Create New...