How to Manage Bash History on Linux Systems

BASH (Bourne Again SHell) it is the default shell on virtually all Linux based operating systems. All commands, which we write in the terminal, are interpreted by the shell and become part of its history. In this tutorial we will see, where shell history is stored and how to manage it using the built-in "history" command and some environment variables.

In this tutorial you will find out:

Where and how the history of BASH is recorded
How to clear Bash shell history

Where BASH history is stored?

If we are opening a terminal emulator or working in TTY and we want to invoke a command, we have launched in the past, we usually press the up arrow key, To go back or Down arrow key, to move forward in shell history . Have you ever wondered, where and how the history of Bash is recorded? Command list, which we call in the Bash shell, is stored in the so-called. "History file", which is by default ~/.bash_profile.

To visualize the current contents of the shell history, we can use the history command, without passing any argument or options. Each line in the output it generates is preceded by a number:

Clearing Bash History

The history command is not only used to display the current history of the shell, but also to perform other operations. To clear all current history of the Bash shell, for example, just invoke it with the -c option.

We also have the option to remove a specific command from the history, by using the -d option and passing the line offset as an argument. imagine, that we want to delete the row 1 from the current history in memory. We would invoke the history command as follows:

How useful this post was?

Click on the star, to evaluate it!

Average grade / 5. number of votes:

So far, no votes! Be the first to rate this post.