codeblog code is freedom — patching my itch

September 1, 2008

bash trivia

Filed under: Blogging,Debian,Ubuntu — kees @ 8:42 am

I have been playing too many puzzle games lately. This trivia question just popped into my head:

What command will never appear in a .bash_history file?

Unfortunately, I seem to have disproven the answer I originally had. I wonder if there are others? My original answer was going to be “unset HISTFILE”, but I can make it show up in my .bash_history file:

unset HISTFILE
export HISTFILE=/home/kees/.bash_history

© 2008, Kees Cook. This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 License.
CC BY-SA 4.0

19 Comments

  1. kill -9 $$

    Comment by Björn Steinbrink — September 1, 2008 @ 9:29 am

  2. what about

    rm ~/.bash_history

    ?

    Comment by Mattia — September 1, 2008 @ 9:33 am

  3. The “rm” would actually show up once you closed the shell. But the “kill -9” would certainly do the trick. Heh. :)

    Comment by kees — September 1, 2008 @ 9:43 am

  4. history -c

    Comment by ranf — September 1, 2008 @ 9:45 am

  5. emacs

    ’nuff said

    Comment by ciasaboark — September 1, 2008 @ 10:53 am

  6. history -r

    Comment by Simon — September 1, 2008 @ 11:46 am

  7. export HISTSIZE=0

    Comment by Sam — September 1, 2008 @ 12:43 pm

  8. killall -9 bash

    Comment by garaged — September 1, 2008 @ 12:43 pm

  9. export HISTIGNORE=ls
    ls

    ..does not count? :)

    Comment by nd — September 1, 2008 @ 1:24 pm

  10. sudo chattr +i ~/.bash_history :)

    Comment by necro — September 1, 2008 @ 1:31 pm

  11. exit

    Comment by Jean-Christophe Dubacq — September 1, 2008 @ 4:17 pm

  12. (man bash)
    HISTCONTROL
    A colon-separated list of values controlling how commands are
    saved on the history list. If the list of values includes
    ignorespace, lines which begin with a space character are not
    saved in the history list. A value of ignoredups causes lines
    matching the previous history entry to not be saved. A value of
    ignoreboth is shorthand for ignorespace and ignoredups.

    I have
    export HISTCONTROL=ignoreboth
    in my .bashrc so no command starting with a space will be saved (VERY convenient) and no duplicates ;-)

    Hope that helps.

    Comment by Ju. — September 1, 2008 @ 6:54 pm

  13. !3

    Comment by meatyzppl — September 1, 2008 @ 10:50 pm

  14. About your last example…

    > unset HISTFILE
    > export HISTFILE=/home/kees/.bash_history

    I would think that the “export [..]” line wouldn’t be recorded: you have unset HISTFILE, so that command is going to be logged nowhere. Am I wrong?

    Comment by David Paleino — September 1, 2008 @ 11:30 pm

  15. halt -n -f -p

    Comment by Salz — September 2, 2008 @ 1:24 am

  16. any of the history shortcuts, like !!

    the command it shortcuts too would show up tho

    Comment by TheGrieve — September 2, 2008 @ 4:34 am

  17. export HISTIGNORE=’*’
    export HISTSIZE=0
    ln -sf /dev/null ~/.bash_history

    There is no bloody way the history will be saved after any of those 3 commands. There are a few history tricks in this blog post I wrote:
    http://digitalprognosis.com/blog/2008/06/13/increasing-command-line-productivity-in-the-bash-shell-pt-ii/

    Comment by Jeff Schroeder — September 2, 2008 @ 4:45 am

  18. history -d $(history | tail -1 | awk ‘{ print $1 }’)

    Fun fact: I had to retype it from memory because… well, when I tested it it disappeared from my history :-)))

    Comment by Jacobo — September 2, 2008 @ 9:53 am

  19. unset HISTFILE && exit

    (Though, like almost any command, you could use aliases or similar to make those commands not do the obvious thing.)

    !!

    (bash doesn’t save the literal command line when you use history.)

    Comment by Anonymous — September 3, 2008 @ 7:52 am

Powered by WordPress