4

I use Arch Linux and bash. I've identified the following and can't understand how it works.

The first issue is:

history -cw doesn't clear ~/.bash_history file but history -c ; history -w does.

The second one is:

When I open the shell and execute something like these:

$ first $ second $ history -c $ third 

and close the shell, ~/.bash_history is supplemented with a line third. I expect ~/.bash_history to contain the single line third.

My shopt histappend is off, doesn't this mean that the history file needs to be overwritten? It's not critical for me, but I want to understand how it works.

2 Answers 2

4

First issue

The bash man page lists the two flags -c and -w separately:

 history -c ... history -anrw [filename] 

The command history --help is more specific:

$ history --help history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...] 

You cannot use the flags -c and -w together.

Second issue

The command history -c clears the history in your current shell but it doesn't clear the history file. If you close this shell the history will be appended to the history file. If you want to clear the history file, you could delete it with the command rm $HISTFILE.

3

Force zsh to close the history file by setting the size to zero, then setting it to the size you want;

HISTSIZE=0 HISTSIZE=4095 

Otherwise, in in-memory, cached copy of history is used, and won't be deleted until the "use count" goes to 0 when the shell exits.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.