May 092009

Sponsored Link

This is very useful tip if there are multiple people maintaining or using debian desktop,server or even if you are the maintainer, but can't remember exactly when you did or changed something.

If you want to add this settings to globally use /etc/bash.bashrc

First you need to Edit your $HOME/.bashrc file

#vi $HOME/.bashrc

Add the following line

export HISTTIMEFORMAT="%h/%d -- %H:%M:%S "

Save and exit the file.

From next login instead of:

574  tail -f /var/log/maillog
575  mailq | tail -15
576  tail -f /var/log/maillog
577  less /var/log/maillog

you get:

1002  May/09 -- 11:46:16 grep log /var/log/maillog
1003  Apr/09 -- 14:17:40 passwd test
1004  Apr/09 -- 14:50:28 history 15

Some more bash history tips

The most efficent way to search your history is to hit Ctrl R and type the start of the command. It will autocomplete as soon as there’s a match to a history entry, then you just hit enter

If you don't want to save duplicate commands use the following option in your bashrc file ($HOME/.bashrc)


If you want to set the size of the history file use the following option in your bashrc file ($HOME/.bashrc)


Sponsored Link

 Posted by at 7:11 pm

  6 Responses to “How to Add Date And Time To Your Bash History file”

  1. In short:

    export HISTTIMEFORMAT=’%F %T ‘
    export HISTCONTROL=ignoredups
    export HISTCONTROL=ignoreboth
    export HISTSIZE=5000

  2. # My .bashrc HISTORY 😉

    export HISTTIMEFORMAT=’%F %T ‘ # time entry for .bash_history
    export HISTCONTROL=ignoredups # eliminate continuous occurrences duplicates
    export HISTSIZE=100000 # big big histfile
    shopt -s histappend # append to history, don’t overwrite it

    # Save and reload the history after each command finishes
    export PROMPT_COMMAND=”history -a; history -r; $PROMPT_COMMAND”

  3. I had to replace the double quotes with single quotes to get this working

  4. I like those enhancements, guys! 🙂
    Only, it gives me this “wise reminder” after every ENTER hit in the BASH prompt:
    bash: history: cannot use more than one of -anrw

    …although, I must admit it, I’m not in “Lenny”, I’m in OpenSuSE 11.1. But I guess BASH is distro-independent, eh? GPL software and all that…

  5. thanks for your trick 🙂

  6. If you seek an easy way how to view, navigate, search and filter Bash history, you may want to a give a try to

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>