Skip to main content
Became Hot Network Question
Tweeted twitter.com/StackUnix/status/1208764162454773763
Source Link

Does bash load into memory the `HISTFILE` upon starting?

I have been going through some videos on bash and history-related bash variables. There's a stackoverflow question that linked this video that mentions editing .bash_history.

I changed my $HISTFILE to a local file in shell A and changed cd to ls in the first line while still in shell A then I ran history and saw no change of cd.

    1  Sun 22/Dec/19 07:59:02 cd
    2  Sun 22/Dec/19 07:59:12 view ~/.bash_profile
    3  Sun 22/Dec/19 08:00:22 history 5
    4  Sun 22/Dec/19 08:00:58 vim ~/.bash_profile
    5  Sun 22/Dec/19 08:01:43 history 5
    6  Sun 22/Dec/19 08:01:59 history 4
    7  Sun 22/Dec/19 08:30:36 echo $HISTFILE
    8  Sun 22/Dec/19 08:30:48 vim $HISTFILE
    9  Sun 22/Dec/19 08:31:02 history

I then opened shell B ran history. Here's the output from the command. The new shells saws my change on the first line as ls.

    1  Sun 22/Dec/19 07:59:02 ls
    2  Sun 22/Dec/19 07:59:12 view ~/.bash_profile
    3  Sun 22/Dec/19 08:00:22 history 5
    4  Sun 22/Dec/19 08:00:58 vim ~/.bash_profile
    5  Sun 22/Dec/19 08:01:43 history 5
    6  Sun 22/Dec/19 08:01:59 history 4
    7  Sun 22/Dec/19 08:31:19 history

So does the bash process load up the history file into memory every time it is opened? Hence, if one has a very large $HISTFILE, wouldn't this be a big memory issue?