HostOnNet Blog


How to Clear current session history (bash)

history_ssh

To clear the history, type the following command:


history -c

Type the following command to remove a certain line (e.g. 890) from the Bash history file :


history -dw 890

-c Clear the history list 
-d Delete specified line from the history

Don’t save commands in bash history

Unsetting HISTFILE will cause any commands that you have executed in the current shell session not to be written in your bash_history file upon logout :


unset HISTFILE


About Annie

I've been working in Technical Section for over 10 years in a wide range of tech jobs from Tech Support to Software Testing. I started writing blog for my future reference and useful for all.

  • How can we show time of the command executed when we type “history” ?

  • Annie

    Edit your /etc/bashrc file and add following line:

    export HISTTIMEFORMAT=”%h/%d – %H:%M:%S ”

    From next login onwards we can see each commands with date and time.

  • Thanks, done that. On my PC running Ubuntu, old commands that was run months ago shows todays date.

    me@fwhlin:~$ history | tail -n 2

    2005 Oct/24 – 15:24:42 cd

    2006 Oct/24 – 15:24:48 history | tail -n 2

    me@fwhlin:~$ history | head -n 2

    1008 Oct/24 – 15:23:42 git diff

    1009 Oct/24 – 15:23:42 git commit -m

    me@fwhlin:~$

    Do you know how to fix please ?