SERVER MANAGEMENT Tips & Tricks

How to logout from shell without saving bash history

bash history
bash history

Logout from shell without saving bash history

Here I am explaining different methods to logout from shell without saving bash history.

Method 1

 
unset HISTFILE

Run the above command before loging out from the server to exit from terminal without saving bash history.

Method 2

 
kill -9 $$

The above command will kill the current terminal without saving the history.

Method 3

 
HISTSIZE=0

The above command will change the HISTSIZE to zero. Hence it can’t store the current history.

Method 4

 
HISTFILE=/dev/null

This command also clears the current session history.

Method 5

 
history -c

It will delete the all bash history. i.e., the earlier history will be removed.

Method 6

If you would like to avoid only some commands in the history file, you can set the HISTIGNORE variable.

 
HISTIGNORE='cat*:cd*'

Any instance of cat and cd will not be recorded on your bash history if you use the above command.

Method 7

Also, if you would like to avoid some particular commands, you can set HISTCONTROL variable.

 
HISTCONTROL='ignorespace'

By setting the above command will help to omit any command lines starting with space.

 
HISTCONTROL='ignoreboth'

It will skip repeated lines.

That’s it!

If you like this post and wish to receive more articles from us, please like our FB page: Grepitout

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.

For more details on our services, please drop us an E-mail at info@grepitout.com

Topics