top of page
Writer's pictureShashi Kallae

Remove/ Disable Bash shell commands History on Linux

Updated: Dec 20, 2023


Remove/ Disable Bash shell commands History on Linux.
Remove/ Disable Bash shell commands History on Linux.

Disable the History

Step -1: Disable history for a linux shell (bash).

set +o history

Step -2: Clean command history.

history -c

Step -3: Permanently disable bash history.

echo 'set +o history' >> ~/.bashrc

The 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:

 . ~/.bashrc

Step -5: Disable a command history system-wide:

echo 'set +o history' >> /etc/profile

These 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_history

HISTFILE 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.historynew

 

Clear the bash History

history -c

history -d 10

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page