Remove/ Disable Bash shell commands History on Linux
- Shashi Kallae

- Dec 19, 2023
- 1 min read
Updated: Dec 20, 2023

Disable the History
Step -1: Disable history for a linux shell (bash).
set +o historyStep -2: Clean command history.
history -cStep -3: Permanently disable bash history.
echo 'set +o history' >> ~/.bashrcThe above will affect the users when they login to the shell. It will not store any commands to a history file .bash_history.
Step -4: To apply these settings immediately for the current shell session, Invoke/execute the .bashrc file:
. ~/.bashrcStep -5: Disable a command history system-wide:
echo 'set +o history' >> /etc/profileThese will be effective for all the new users created after this.
Find out the History
To find the history use the below commands,
history
history | less
history | more
history | grep 'find'Find out the number of commands saved in the history
echo "$HISTSIZE"
MBP.local.net@SK $ echo "$HISTSIZE"
500
-----------
printf "%d\n" $HISTSIZE
MBP.local.net@SK $ printf "%d\n" $HISTSIZE
500
The bash terminal history is stored in the ‘.bash_history’ file.
Path: /home/user_name/.bash_historyHISTFILE is the variable that gets initialized when the history file is invoked.
~/.bash_history
printf “%s\n” “$HISTFILE"
echo $HISTFILE
MBP.local.net@SK $ echo $HISTFILE
/Users/shashikallae/.bash_sessions/2DBDCE25-4A92-4DD6-9CA8-97175124E09E.historynewClear the bash History
history -c
history -d 10


Comments