How to Manage BASH History - Delete, Clear, and Control Your Linux Command History

Опубликовано: 21 Март 2026
на канале: Slap Ya Administrator
48
4

Learn how to manage BASH history - Delete, Clear, and Control Your Linux Command History.

Here are the command featured in my video.


Find the line number
--------------------
Find the line number
history


METHOD 1:
Delete Specific Line by Number
------------------------------
Then delete a specific line (replace N with the line number)
history -d N


METHOD 2:
Delete Range of Lines
----------------------


METHOD 3:
Clear Entire History
---------------------
Clear all history in current session
history -c

Also clear the history file permanently
history -w


METHOD 5:
Edit History File Directly
--------------------------
Edit the history file (usually ~/.bash_history)
nano ~/.bash_history
or
vim ~/.bash_history

After editing, reload history
history -r



***************
*** BONUS ***
***************

Prevent Specific Commands from Being Saved
------------------------------------------
Add space before command to exclude from history
ls -la # This won't be saved to history



Control History Size
--------------------
Add these lines to ~/.bashrc to limit history size:
nano ~/.bashrc

Limit history file size
HISTFILESIZE=1000
HISTSIZE=1000

Ignore duplicates and specific commands
HISTCONTROL=ignorespace:ignoredups:erasedups

Ignore specific commands
HISTIGNORE="ls:cd:history"


#fypシ #linux #history