How to delete command history?

0119

To delete command history in a Linux terminal, you can use the following methods:

1. Clear the Current Session History

You can clear the command history for the current session by using the history command with the -c option:

history -c

This will clear the history for the current terminal session.

2. Delete Specific Entries

If you want to delete specific entries from your history, you can use the history command followed by the -d option and the line number of the entry you want to delete. First, list your history:

history

Then, delete a specific entry by its number:

history -d <line_number>

3. Clear the History File

To delete all command history stored in the history file (usually ~/.bash_history for Bash), you can use:

cat /dev/null > ~/.bash_history

Or you can use:

rm ~/.bash_history

After deleting the file, you may want to log out and log back in or run the following command to ensure the changes take effect:

history -c

4. Disable History Temporarily

If you want to prevent commands from being saved to history during a session, you can set the HISTSIZE variable to zero:

export HISTSIZE=0

Note

Be cautious when deleting command history, as it cannot be recovered once deleted.

0 Comments

no data
Be the first to share your comment!