12

What are some tricks for avoiding bash history being logged in a fascist logging environment that does not involve modifying .bashrc or deleting content from within the history file?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • 4
    use another shell e.g. `sh` – strugee Jul 27 '13 at 02:33
  • 3
    So that means no `rm ~/.bash_history; ln -s /dev/null ~/.bash_history`? – goldilocks Jul 27 '13 at 05:27
  • Depending on how often you want to do that, see [Temporarily suspend bash_history on a given shell?](http://unix.stackexchange.com/q/10922) or [How do I close a terminal without saving the history?](http://unix.stackexchange.com/q/25049) – Gilles 'SO- stop being evil' Jul 27 '13 at 22:36
  • Also, unset `PROMPT_COMMAND`. This is the default `$PROMPT_COMMAND` on a server I have access to: `history -a >(tee -a ~/.bash_history | logger -t "$USER[$$] $SSH_CONNECTION")` – Kusalananda Sep 08 '17 at 14:28

3 Answers3

10

One possible solution is to stop logging bash history is:

set +o history

and to reset, that is to start logging again:

set -o history
easl
  • 1,968
  • 7
  • 21
  • 29
7

I guess you have .bash_profile, and this startup file calling .bashrc? Do you have write permission on .bash_profile?

Otherwise, if you just don't want to log some commands, run

$ unset HISTFILE

then all commands afterwards won't be logged within that session.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Shâu Shắc
  • 929
  • 1
  • 10
  • 11
3

On stackoverflow they had some decent answers:

  • Add a space to your command.
  • Add [ \t]* to HISTIGNORE
  • Add ignorespace to your HISTCONTROL environment variable

Although not all of them may apply for your situation, those seems like the only options.

chrisjlee
  • 8,283
  • 16
  • 49
  • 54
  • 1
    It's important to note that HISTIGNORE/HISTCONTROL stop commands from being added to the history list. This probably keeps them from being logged, too, but it also makes them impossible to access with normal history keys (like up and down arrow, ctrl-R, etc.) So if you're used to editing and repeating previously typed commands, these settings are really annoying. – rici Jul 27 '13 at 04:08
  • 1
    Adding a space specifically requires the *first character* to be a space, right? – phs Jul 28 '13 at 00:49
  • @phs yes - see http://unix.stackexchange.com/questions/115917/why-is-bash-not-storing-commands-that-start-with-spaces – Simon D Jul 26 '16 at 16:23