Clear bash history command line in Linux



How to check your Bash History


To start working with the Linux history commands, you will need command history.
When you launch it, you will be shown the entire history of commands in the terminal.
# history

If you want to see the last 5 commands then use the following command
# history 5


How to clear Linux command history


If you don’t want to save history in Bash, since the commands may contain data such as passwords. This article will help keep Bash history in check.
Below is an example using the command . With this command you can clear or delete all entries in your bash history.
# history -c

How to remove bash history completely


-c - Clear history file
-w - add commands of the current session to the history file
# history -cw

How to delete a single command from history in bash


If you need to remove a single command from Bash history, then the command will help you -d

# history -d

Below you will find an example in which command d - Delete the line with the specified number from the history
# history -dw 352

How to clear command history of current session


-r - Read the current history file and add its contents to the command history list.
# history -r

How don't save command in Bash history


How to run the command without putting it in the history of Bash:
"space" command
Put a space before any command and it will not be saved in Bash history.

How don't save all commands of the current session in the history of Bash


If you will disable the HISTFILE results in the fact that until you exit the current session, any commands you will execute will not be saved in a file with the bash_history history:
# unset HISTFILE

How to find the right command in bash history


If you want to find a specific command in bash history then use the command grep:
# history grep (command name)


Also, you can read our other articles: