codeblog code is freedom — patching my itch

9/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 3.0 License.
Creative Commons License

19 Comments »

  1. kill -9 $$

    Comment by Bj√∂rn Steinbrink — 9/1/2008 @ 9:29 am

  2. what about

    rm ~/.bash_history

    ?

    Comment by Mattia — 9/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 — 9/1/2008 @ 9:43 am

  4. history -c

    Comment by ranf — 9/1/2008 @ 9:45 am

  5. emacs

    ’nuff said

    Comment by ciasaboark — 9/1/2008 @ 10:53 am

  6. history -r

    Comment by Simon — 9/1/2008 @ 11:46 am

  7. export HISTSIZE=0

    Comment by Sam — 9/1/2008 @ 12:43 pm

  8. killall -9 bash

    Comment by garaged — 9/1/2008 @ 12:43 pm

  9. export HISTIGNORE=ls
    ls

    ..does not count? :)

    Comment by nd — 9/1/2008 @ 1:24 pm

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

    Comment by necro — 9/1/2008 @ 1:31 pm

  11. exit

    Comment by Jean-Christophe Dubacq — 9/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. — 9/1/2008 @ 6:54 pm

  13. !3

    Comment by meatyzppl — 9/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 — 9/1/2008 @ 11:30 pm

  15. halt -n -f -p

    Comment by Salz — 9/2/2008 @ 1:24 am

  16. any of the history shortcuts, like !!

    the command it shortcuts too would show up tho

    Comment by TheGrieve — 9/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 — 9/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 — 9/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 — 9/3/2008 @ 7:52 am

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered by WordPress