15 C
Jaipur
Saturday, November 28, 2020

How to clear command history in Linux – Linux Hint

Must read

Late Black Friday Lego deal cuts the price of the Statue of Liberty and more landmarks

Going on vacations hasn't very easy in 2020, but the late Black Friday Lego deals – or perhaps early Cyber Monday Lego deals depending...

Hot Cyber Monday Nintendo Switch deals, bundles and games

Early Cyber Monday Nintendo Switch deals have begun trickling in, as we reach the end of Black Friday weekend. We've already seen some fantastic...

The best pre-Cyber Monday iPad deal is still this surprise iPad Air 4 price cut

Loads of the Cyber Monday iPad deals cover Apple tablets that are several years old, but the risk of buying one of these is...

Daniel Dubois vs Joe Joyce live stream: how to watch the fight from anywhere tonight

After two previous false starts, this much-anticipated face off between two of Britain's best heavyweights finally gets to take place tonight. Don't miss a...

The bash history stores the records of all terminal commands which are executed by a user on the command-line Linux system. Using the history feature, you can easily locate the previously executed commands on your Linux system through the arrow keys navigation.

Why should we remove the Linux Command line History?

Most of the time, we don’t want to reveal the terminal history of other users on your Linux system. For example, if you are giving classes to your students on a Lab computer and you might have taught some harmful commands and are not recommended to use on our system. But most of the students don’t have an idea about the side effects of these critical commands. A curious student may search about the command-line history and test them to check the working of each command. It may crash your system many times. However, you can repair or re-install your system in a quick way. But, it is not a good practice. So, in this case, we want to prefer to clear the command line history after working on it. Especially when you have shared access with your friends or colleagues. We have just elaborated it with just a simple example; there could be other problems through which you want to clear the Linux command line history. In this article, we will give you a demo of how you can clear the command line history in the Linux system.

We have executed all the commands on Ubuntu 20.04 terminal application in this article. Therefore, it is necessary to open the terminal window on your system. Click on the ‘Activities’ located at the left corner on your system’s desktop, and then using the application search bar, you will search the ‘terminal’ keyword. After completing the search, click on the terminal icon and launch it.

Removing the Linux Command line history

If you want to view the history of your terminal command then, type the following command on the terminal:

Normally, the command line history stores in a file named ‘bash_history’. This file you may locate in a particular user’s home directory /home/username/.bash_history. Execute the below-given command to locate the bash_history file:

$ ls -l /home/kbuzdar/.bash_history

Note: A root user can observe the command history of all user’s on your system. But, the standard user can only view their own command line history.

Remove a Line from the bash history

If you want to remove just a single line from the bash history file, then you can use the -d option with history command and enter the targeted line number, which you want to remove.

For example, we want to clear a command that contains your password where you have entered a password in a plain text; you can easily find the line number in the history file and clear it by executing the following command:

Remove or Clear all commands from the bash history

You can also clear or delete all entries from the bash history file. So, use the option -c with the history command. You can run the following command on the terminal to clear or delete the all bash history:

Alternatively, by running the following command, you can remove or delete all history of last executed commands in the bash history file permanently.

$ cat /dev/null > ~/.bash_history

Conclusion

In this article, we have presented a better understanding of the history command and why we need to clear it. From the above all mentioned command, I hope now can clear the history of your system easily. But, always remember that what you perform on the terminal all commands recorded in a bash history file, so it is recommended that you never use passwords in a plain-text format on the Linux command line. If you have any queries and thoughts related to this article then, please share your ideas with us.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

Late Black Friday Lego deal cuts the price of the Statue of Liberty and more landmarks

Going on vacations hasn't very easy in 2020, but the late Black Friday Lego deals – or perhaps early Cyber Monday Lego deals depending...

Hot Cyber Monday Nintendo Switch deals, bundles and games

Early Cyber Monday Nintendo Switch deals have begun trickling in, as we reach the end of Black Friday weekend. We've already seen some fantastic...

The best pre-Cyber Monday iPad deal is still this surprise iPad Air 4 price cut

Loads of the Cyber Monday iPad deals cover Apple tablets that are several years old, but the risk of buying one of these is...

Daniel Dubois vs Joe Joyce live stream: how to watch the fight from anywhere tonight

After two previous false starts, this much-anticipated face off between two of Britain's best heavyweights finally gets to take place tonight. Don't miss a...

The Apple Watch 6 drops to lowest price ever in post-Black Friday deal

While Black Friday proper is technically over, you can still find incredible deals that are available today. Amazon has already started its Cyber Monday...