6 Replies Latest reply: Mar 10, 2012 10:09 AM by Tissot11
Tissot11 Level 1 Level 1 (0 points)



I just quickly want to ask one question about using a .bashrc file for my bash shell on OS Lion. I've configured some shell variables and made .bashrc as my default instead of .bash-profile. However, when I configure export HISTCONTROL=ignoreboth in .bashrc file to ignore the duplicate and spaced commands, this particular variable doesn't work and i keep seeing all the duplicates commands when I type history on terminal. All of the variables related to history and aliases seem to work fine. Does anyone has any idea? I paste below the .bashrc file for quick checking.


-------------------------------------------------------------------------------- ----------------------


#echo ""

#echo -n "Welcome to Unix on Mac OS X Lion, "; whoami

#echo ""

#echo -n "Today is "; date "+%m-%d-%Y %H:%M:%S"

#echo ""


echo -n "Uptime: "; uptime

echo ""





export PS1="Kumar:# \W > "







#export LESS='-M'



export HISTSIZE=500

export HISTFILESIZE=10000

export HISTCONTROL=ignoreboth      #ignoredups:ignorespace

export HISTTIMEFORMAT='%b %d %I:%M %p '  #using strftime format

#export HISTCONTROL=ignoredupes:erasedups

#export HISTCONTROL=ignorespace

#set histdup='all'

export HISTIGNORE="history:pwd:exit:df -lah:ls -la:h"



alias mv='mv -i'

alias cp='cp -i'

alias home='cd ~'

alias up='cd ..'

alias h='history'


  • Charles Minow Level 6 Level 6 (9,180 points)



    Try enclosing 'ignoreboth' in single quotes:




    That's working for me on Snow Leopard.



  • Frank Caggiano Level 7 Level 7 (25,715 points)

    Works for me. Do both the duplicates and spaced commands show in your history?


    You realize the dups only apply to the previous line. That is if I type:

    # ls

    # ls


    then only one ls in the history. But if I type:

    #l ls

    # pwd

    # ls


    both ls's will be in the history.


    If you do an export from the command line does is HISTCONTROL set in your environment?


    No quotes should be needed, not using them on Lion but this should be fairly OS independent.

  • Tissot11 Level 1 Level 1 (0 points)

    Unfortunately this doesn't seem to work for me on Lion.

  • Tissot11 Level 1 Level 1 (0 points)

    I tried setting and resetting from command prompt HISTCONTROL variable, and at the end I had the same environment variables in my .bashrc file as before but strangely before it was only ignoring the spaced command but now it does ignore the immediate duplicate and spaced commands too, which I don't understand. Anyway is there anyway to not to record any duplicate commands from the history. I mean the all duplicate commands have only one entry in the history? This would be quite useful for me.

  • Frank Caggiano Level 7 Level 7 (25,715 points)

    No way to remove duplicates earlier in the history file that I am aware of.


    You could write something to go through the history file and remove duplicates, wouldn't be to hard or they may be a script out there that does that. Using sort  and uniq would do it except the commands would not be in the file in the order they were entered on the command line if that is a problem.


    something like

    sort .bash_history | uniq -d

    should be a starting point.



  • Tissot11 Level 1 Level 1 (0 points)

    Thanks Frank for the tip.