hardening debian server | Install pgsl on debian 7 | passing php urlencode variable to javascript?
 


 

How To Delete or Not Keep a Command in Bash History



Delete a Command from Bash History

Here I give some test commands to fill history:

pontikis@ubuntu:~$ clear

pontikis@ubuntu:~$ echo 1
1
pontikis@ubuntu:~$ echo 2
2
pontikis@ubuntu:~$ echo 3
3
pontikis@ubuntu:~$ my-secret-command
my-secret-command: command not found

I can view the history using history command:

pontikis@ubuntu:~$ history
    1  clear
    2  echo 1
    3  echo 2
    4  echo 3
    5  my-secret-command
    6  history

So, to remove my-secret-command (line 5), I use -d option of history command:

pontikis@ubuntu:~$ history -d 5
pontikis@ubuntu:~$ history
    1  clear
    2  echo 1
    3  echo 2
    4  echo 3
    5  history
    6  history -d 5
    7  history

DO NOT KEEP a Command in Bash History

Start a command with SPACE if you DO NOT want to be included in Bash history:

pontikis@ubuntu:~$  my-secret-starts-with-space
my-secret-starts-with-space: command not found
pontikis@ubuntu:~$ history
1  clear
2  echo 1
3  echo 2
4  echo 3
5  history
6  history -d 5
7  history

Make sure that your .bashrc file contains something like this

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

In other words, ensure that HISTCONTROL environmental variable is set to ignorespace or ignoreboth

Related Posts

You may also be interested in

Εγγραφή!
Sign-up for our free email newsletter. Get updates when new tutorials and tips are published. You can unsubscribe anytime with a click.

Your comments are welcomed!

This site actively encourages commenting on any post. Comments are not pre-moderated, but this community does not tolerate direct or indirect attacks, name-calling or insults. Please, read terms of use and Comment Policy at privacy policy.

More tips