Skip to main content
Back to Journal
Tips

Quick Tip: How To Delete Commands from your Bash/Terminal History

Managing Your Bash History

Your bash terminal keeps a record of every command you type. While this is useful for recalling previous commands, sometimes you need to clean up your history — whether for security reasons or just to keep things tidy.

Viewing Your History

To see your command history, simply type:

history

This displays a numbered list of all your recent commands.

Deleting a Specific Entry

To delete a specific command from your history, use the -d flag followed by the line number:

history -d 123

This removes entry number 123 from your history.

Clearing All History

To clear your entire bash history:

history -c

Preventing Commands from Being Recorded

Start your command with a space to prevent it from being recorded in history (if HISTCONTROL is set to ignorespace or ignoreboth):

 sensitive-command --password=secret

The History File

Bash stores your history in ~/.bash_history. When you close a terminal session, the in-memory history is written to this file. To write immediately:

history -w
BashTerminalTips