To clear the shell history in Ubuntu Linux, you can use the history
command with the -c
option. This will clear the history of the current shell session.
For example, to clear the history of the current bash shell session, you can use the following command:
history -c
This will clear the history of the current shell session, but it will not delete the history file itself. The history file is usually stored in the ~/.bash_history
file, and it contains a record of all the commands you have entered in previous shell sessions.
To delete the history file itself, you can use the rm
command. For example:
rm ~/.bash_history
This will delete the .bash_history
file, which will prevent the shell from loading the history from the file in future sessions.
Note that these commands will only clear the history for the current user. If you want to clear the history for all users on the system, you will need to repeat these steps for each user.
You can also use the history
command with the -w
option to write the current history to the history file. For example:
history -w
This will save the current history to the .bash_history
file, replacing any existing history in the file.
You can also use the history
command with the -a
option to append the current history to the history file. For example:
history -a
This will add the current history to the end of the .bash_history
file, without replacing any existing history.
Finally, you can use the history
command with the -d
option to delete a specific command from the history. For example:
history -d 123
This will delete the command with the number 123 from the history. You can use the history
command without any options to display a list of the commands in the history, along with their numbers, which you can use to delete specific commands.