Modify BASH File History size in Ubuntu

The Bourne Again Shell (i.e BASH) is one of the most popular shells available. With the help of history feature, we can view, modify and use commands we have already entered in the past. And, this command history would build on over a period of time. The default number of command that it stores is 2000 in Ubuntu. In this article, we cover how to modify BASH File History size in Ubuntu.

How to access previously entered commands in BASH?

Open a terminal and use Up and Down Arrow keys. And, press Enter when you have found the right command. Or, edit it and then use it.

Now, there are two things we should know before making any changes, first is the default BASH History file size and BASH History file (i.e. the file where BASH History is saved). So, open a terminal and issue the following –

echo $HISTFILE
echo $HISTFILESIZE

If changes haven’t been made earlier then, it should return with –

/home/$USER/.bash_history
2000

The $HISTFILE is the file where all the commands we type in terminal are saved unless we clear the history. And, once we close the session without clearing History then the entered commands gets stored in $HISTFILE.

The $HISTFILESIZE is the maximum number of commands the $HISTFILE can store.

Modify BASH File History size in Ubuntu

We hope you have got the idea of how things work in background. Next comes, how to modify BASH File History size?

For that, edit .bashrc file. Use a text-editor, we have used nano

nano ~/.bashrc

And, edit the following line –

HISTFILESIZE=2000

Here, 2000 is the default value. Change it to something you prefer. Save and Exit.

To immediately make changes to the current SHELL –

source ~/.bashrc

Now, verify the changes by again using the command –

echo $HISTFILESIZE

It should return with the value you entered.

In conclusion, we have covered how to modify BASH File History size in Ubuntu.

Similar Posts