• Adjust What the History Command Shows

    By default on OS X, the history command (accessed via the terminal) shows the last 500 commands including multiple entries that are the exact same. Just to find an old useful command, you may have to sort through 100’s of ls and cd commands. Wouldn’t it be nice to show only unique commands, and remove the duplicates, or store a larger history? Well you can and it is very simple to set the variables to control what the history command shows on the MAC terminal.

    Launch a terminal, by default you should be put into your home directory. To make sure you are in your HOME, just type:

    cd ~/

    Now there are a few places you can put this information on OS X, but I like using the .bash_profile file.  By default this does not exist in your HOME directory so you will need to create  it.  First, check if it exists by typing:

    ls -al

    Create the .bash_profile file, if it does not already exist, otherwise this will edit the existing file:

    nano .bash_profile

    If you created this, it will be blank, if not just add the following to the file:

    export HISTSIZE=1000
    export HISTCONTROL=erasedups
    export HISTIGNORE="history:ls:ls -al:cd ..:irb:pwd"
    export HISTTIMEFORMAT="%F %T "

    In this setup we are doing the following. First HISTSIZE is being set to store 1000 commands, if you set this to 0 no history is stored. HISTCONTROL is being set to erase any duplicate entries, so commands will only appear once. HISTIGNORE is telling bash not to record those commands, meaning they will not appear in the history. HISTTIMEFORMAT shows the date and time the command was last executed.

    The history command is incredibly useful and can make you much more efficient if you leanr how to use it well. This article provides a few details of what you can make the history command do for you. If you really do not know much about the OS X command line, read this.


    Leave a reply