Reload of .bash_history - Suse

This is a discussion on Reload of .bash_history - Suse ; When you have 6 terninals open, the .bash_history only works with the commands in .bash_history when the terminal was opend. Is there a way to have this read each time you do a command or even a [ENTER]? houghi -- ...

+ Reply to Thread
Results 1 to 17 of 17

Thread: Reload of .bash_history

  1. Reload of .bash_history

    When you have 6 terninals open, the .bash_history only works with the
    commands in .bash_history when the terminal was opend.

    Is there a way to have this read each time you do a command or even a
    [ENTER]?

    houghi
    --
    The blue light suddenly flashed on my horrified face. What a disaster!
    Oh, the humanity! I never thought it would happen to me. How terrifying
    it is to see for yourself "*The Blue Screen of Death*".

  2. Re: Reload of .bash_history

    On Fri, 11 Jan 2008, houghi wrote:-

    >When you have 6 terninals open, the .bash_history only works with the
    >commands in .bash_history when the terminal was opend.
    >
    >Is there a way to have this read each time you do a command or even a
    >[ENTER]?


    I wouldn't think so since, AFAIK, the command history for a terminal
    isn't written out until the terminal is closed.


    Regards,
    David Bolt

    --
    www.davjam.org/lifetype/ www.distributed.net: OGR@100Mnodes, RC5-72@15Mkeys
    SUSE 10.1 32bit | openSUSE 10.2 32bit | openSUSE 10.3 32bit | openSUSE 11.0a0
    SUSE 10.1 64bit | openSUSE 10.2 64bit | openSUSE 10.3 64bit
    RISC OS 3.6 | TOS 4.02 | openSUSE 10.3 PPC |RISC OS 3.11

  3. Re: Reload of .bash_history

    David Bolt wrote:
    > On Fri, 11 Jan 2008, houghi wrote:-
    >
    >>When you have 6 terninals open, the .bash_history only works with the
    >>commands in .bash_history when the terminal was opend.
    >>
    >>Is there a way to have this read each time you do a command or even a
    >>[ENTER]?

    >
    > I wouldn't think so since, AFAIK, the command history for a terminal
    > isn't written out until the terminal is closed.


    Bummer. :-/

    houghi
    --
    The blue light suddenly flashed on my horrified face. What a disaster!
    Oh, the humanity! I never thought it would happen to me. How terrifying
    it is to see for yourself "*The Blue Screen of Death*".

  4. Re: Reload of .bash_history

    David Bolt wrote:

    > On Fri, 11 Jan 2008, houghi wrote:-
    >
    >>When you have 6 terninals open, the .bash_history only works with the
    >>commands in .bash_history when the terminal was opend.
    >>
    >>Is there a way to have this read each time you do a command or even a
    >>[ENTER]?

    >
    > I wouldn't think so since, AFAIK, the command history for a terminal
    > isn't written out until the terminal is closed.
    >
    >
    > Regards,
    > David Bolt
    >


    I think you're right David. Sometimes I accidently enter my root password as
    a command when thinking that sudo is asking for my password. To prevent the
    password from appearing in .bash_history, I do CTRL+D which kills bash
    without writing out .bash_history.

    --
    Chris

  5. Re: Reload of .bash_history

    Chris wrote:
    > David Bolt wrote:
    >
    >> On Fri, 11 Jan 2008, houghi wrote:-
    >>
    >>> When you have 6 terninals open, the .bash_history only works with the
    >>> commands in .bash_history when the terminal was opend.
    >>>
    >>> Is there a way to have this read each time you do a command or even a
    >>> [ENTER]?

    >> I wouldn't think so since, AFAIK, the command history for a terminal
    >> isn't written out until the terminal is closed.
    >>
    >>
    >> Regards,
    >> David Bolt
    >>

    >
    > I think you're right David. Sometimes I accidently enter my root password as
    > a command when thinking that sudo is asking for my password. To prevent the
    > password from appearing in .bash_history, I do CTRL+D which kills bash
    > without writing out .bash_history.


    Ctrl+D writes the history normally here :P If your eye is quick, you
    can even catch the "logout" command appearing for a few milliseconds
    after the Ctrl+D.

  6. Re: Reload of .bash_history

    Nikos Chantziaras wrote:
    >> I think you're right David. Sometimes I accidently enter my root password as
    >> a command when thinking that sudo is asking for my password. To prevent the
    >> password from appearing in .bash_history, I do CTRL+D which kills bash
    >> without writing out .bash_history.

    >
    > Ctrl+D writes the history normally here :P If your eye is quick, you
    > can even catch the "logout" command appearing for a few milliseconds
    > after the Ctrl+D.


    Wait, this gives me some hope. What is the command that is used to write
    out to the .bash_history file? I could then try to edit .bashrc so that
    each time it shows the $ and #, it writes out the history.

    houghi
    --
    The blue light suddenly flashed on my horrified face. What a disaster!
    Oh, the humanity! I never thought it would happen to me. How terrifying
    it is to see for yourself "*The Blue Screen of Death*".

  7. Re: Reload of .bash_history

    Nikos Chantziaras wrote:

    > Chris wrote:
    >> David Bolt wrote:
    >>
    >>> On Fri, 11 Jan 2008, houghi wrote:-
    >>>
    >>>> When you have 6 terninals open, the .bash_history only works with the
    >>>> commands in .bash_history when the terminal was opend.
    >>>>
    >>>> Is there a way to have this read each time you do a command or even a
    >>>> [ENTER]?
    >>> I wouldn't think so since, AFAIK, the command history for a terminal
    >>> isn't written out until the terminal is closed.
    >>>
    >>>
    >>> Regards,
    >>> David Bolt
    >>>

    >>
    >> I think you're right David. Sometimes I accidently enter my root password
    >> as a command when thinking that sudo is asking for my password. To
    >> prevent the password from appearing in .bash_history, I do CTRL+D which
    >> kills bash without writing out .bash_history.

    >
    > Ctrl+D writes the history normally here :P If your eye is quick, you
    > can even catch the "logout" command appearing for a few milliseconds
    > after the Ctrl+D.


    Damn! I swear that used to be the way. Hmmm. I will have to go back to the
    manpage and see if I confused it with another way.

    Thanks for trying it and pointing it out!

    --
    Chris

  8. Re: Reload of .bash_history

    Chris wrote:

    > Nikos Chantziaras wrote:
    >
    >> Chris wrote:
    >>> David Bolt wrote:
    >>>
    >>>> On Fri, 11 Jan 2008, houghi wrote:-
    >>>>
    >>>>> When you have 6 terninals open, the .bash_history only works with the
    >>>>> commands in .bash_history when the terminal was opend.
    >>>>>
    >>>>> Is there a way to have this read each time you do a command or even a
    >>>>> [ENTER]?
    >>>> I wouldn't think so since, AFAIK, the command history for a terminal
    >>>> isn't written out until the terminal is closed.
    >>>>
    >>>>
    >>>> Regards,
    >>>> David Bolt
    >>>>
    >>>
    >>> I think you're right David. Sometimes I accidently enter my root
    >>> password as a command when thinking that sudo is asking for my password.
    >>> To prevent the password from appearing in .bash_history, I do CTRL+D
    >>> which kills bash without writing out .bash_history.

    >>
    >> Ctrl+D writes the history normally here :P If your eye is quick, you
    >> can even catch the "logout" command appearing for a few milliseconds
    >> after the Ctrl+D.

    >
    > Damn! I swear that used to be the way. Hmmm. I will have to go back to the
    > manpage and see if I confused it with another way.
    >
    > Thanks for trying it and pointing it out!
    >


    Ok I was waaayyy off base with this one. I found two ways to exit without
    saving:

    Option 1. execute: unset HISTFILE
    Option 2. execute: kill -9 $$

    With Option 1, once I exit bash, the history will not be saved. Option 2
    complete kills bash

    --
    Chris

  9. Re: Reload of .bash_history

    houghi wrote:

    > When you have 6 terninals open, the .bash_history only works with the
    > commands in .bash_history when the terminal was opend.
    >
    > Is there a way to have this read each time you do a command or even a
    > [ENTER]?
    >
    > houghi


    According to a response found in here:
    http://linux.derkeiler.com/Mailing-L...4-09/0164.html

    you may want to look into the "histappend" option? I guess that would append
    the history of each terminal to .bash_history. I imagine that could get
    messy though.

    What about HISTFILE env. variable? If you routinely use those 6 terminals,
    perhaps you can start each one with its own HISTFILE setting. This way each
    terminal would read/write to say .bash_history_t1, .bash_history_t2, etc
    etc.?

    --
    Chris

  10. Re: Reload of .bash_history

    houghi wrote:
    > Nikos Chantziaras wrote:
    >>> I think you're right David. Sometimes I accidently enter my root password as
    >>> a command when thinking that sudo is asking for my password. To prevent the
    >>> password from appearing in .bash_history, I do CTRL+D which kills bash
    >>> without writing out .bash_history.

    >> Ctrl+D writes the history normally here :P If your eye is quick, you
    >> can even catch the "logout" command appearing for a few milliseconds
    >> after the Ctrl+D.

    >
    > Wait, this gives me some hope. What is the command that is used to write
    > out to the .bash_history file? I could then try to edit .bashrc so that
    > each time it shows the $ and #, it writes out the history.


    There's a bash built-in command called 'history'. 'man history' should
    help. It says that with 'history -a' you can write the history
    immediately by appending to the file, and with 'history -w' you don't
    append but overwrite:

    -a Append the ``new'' history lines (history lines entered
    since the beginning of the current bash session) to the
    history file.

    -w Write the current history to the history file, overwriting
    the history file's contents.

    If you want to write right after each prompt, you can probably execute
    'history -a' in the env var that controls the prompt. The var is $PS1
    and is defined in /etc/bash.bashrc, around line 150.

  11. Re: Reload of .bash_history

    Nikos Chantziaras wrote:
    > [...]
    > If you want to write right after each prompt, you can probably execute
    > 'history -a' in the env var that controls the prompt. The var is $PS1
    > and is defined in /etc/bash.bashrc, around line 150.


    Also, if you need to do any tricks or fancy stuff each time you logout,
    you can just put the commands in ~/.bash_logout

  12. Re: Reload of .bash_history

    Chris wrote:
    > houghi wrote:
    >
    >> When you have 6 terninals open, the .bash_history only works with the
    >> commands in .bash_history when the terminal was opend.
    >>
    >> Is there a way to have this read each time you do a command or even a
    >> [ENTER]?
    >>
    >> houghi

    >
    > According to a response found in here:
    > http://linux.derkeiler.com/Mailing-L...4-09/0164.html
    >
    > you may want to look into the "histappend" option? I guess that would append
    > the history of each terminal to .bash_history. I imagine that could get
    > messy though.
    >
    > What about HISTFILE env. variable? If you routinely use those 6 terminals,
    > perhaps you can start each one with its own HISTFILE setting. This way each
    > terminal would read/write to say .bash_history_t1, .bash_history_t2, etc
    > etc.?


    No. Something like that already works. What I have is 6 terminals that
    are open all the time. They will not close. They are not intended to
    close.

    Now I do a command in one terminal and then the next day I want to do it
    in another, as I might not remember what terminal I did it in the first
    time. Also I do not remember the whole line like:
    sudo grep "mounted /dev/" /var/log/messages|grep -v grep|awk '{print
    $7}'|tail -n 1

    The link DOES give good info. e.g. that the file will be overwritten and
    not apended, so that might explain why you do not always see your
    password later.

    http://unix.derkeiler.com/Newsgroups.../msg00206.html
    gives some more info.

    houghi
    --
    The blue light suddenly flashed on my horrified face. What a disaster!
    Oh, the humanity! I never thought it would happen to me. How terrifying
    it is to see for yourself "*The Blue Screen of Death*".

  13. Re: Reload of .bash_history

    On Fri, 11 Jan 2008, in the Usenet newsgroup alt.os.linux.suse, in article
    , Chris wrote:

    >David Bolt wrote:


    >> houghi wrote:-
    >>
    >>>When you have 6 terninals open, the .bash_history only works with the
    >>>commands in .bash_history when the terminal was opend.


    Yes - there is only one .bash_history in a user's home directory.

    >>>Is there a way to have this read each time you do a command or even a
    >>>[ENTER]?


    Are you trying to see the history of the "current" terminals? If you
    run the command 'history' you will access the history of the terminal
    session where you are running the command - back to $HISTSIZE or
    when ever the terminal session was started (and the history filled
    from the .bash_history file).

    >> I wouldn't think so since, AFAIK, the command history for a terminal
    >> isn't written out until the terminal is closed.


    It's not written out - but "this" history is available in "this" terminal.

    >I think you're right David. Sometimes I accidently enter my root
    >password as a command when thinking that sudo is asking for my password.
    >To prevent the password from appearing in .bash_history, I do CTRL+D
    >which kills bash without writing out .bash_history.


    "help history" and look at the '-r' option.

    [compton ~]$ history | grep history
    271 history | grep big-8
    451 history | grep big-8
    614 history | grep big-8
    859 history | grep mash
    911 history | grep big-8
    1199 help history
    1200 history | grep -c history
    [compton ~]$ history -r
    [compton ~]$ history | grep history
    1813 history | grep netack
    2058 history | grep turno
    2110 history | grep Joshua
    2203 history | grep history
    [compton ~]$

    It's a lot faster, and actually works ;-)

    Old guy


  14. Re: Reload of .bash_history

    Moe Trin wrote:
    > Are you trying to see the history of the "current" terminals? If you
    > run the command 'history' you will access the history of the terminal
    > session where you are running the command - back to $HISTSIZE or
    > when ever the terminal session was started (and the history filled
    > from the .bash_history file).


    No, I am trying to see the history of ALL terminals in ALL terminals.

    > "help history" and look at the '-r' option.



    It is history -a that I want.

    houghi
    --
    You tried, and you failed, so the lesson is, never try. - Homer J. Simpson.

  15. Re: Reload of .bash_history

    Nikos Chantziaras wrote:
    >> Wait, this gives me some hope. What is the command that is used to write
    >> out to the .bash_history file? I could then try to edit .bashrc so that
    >> each time it shows the $ and #, it writes out the history.

    >
    > There's a bash built-in command called 'history'. 'man history' should
    > help. It says that with 'history -a' you can write the history
    > immediately by appending to the file, and with 'history -w' you don't
    > append but overwrite:
    >
    > -a Append the ``new'' history lines (history lines entered
    > since the beginning of the current bash session) to the
    > history file.


    Yes, this is what I want. Thanks. As usual man pages are usefull if you
    do not need them. ;-)

    > -w Write the current history to the history file, overwriting
    > the history file's contents.


    This is not usefull in that it will overwrite the other terminals
    things. On one of the pages I saw that it should be possible to ignore
    certain tings. I will see that I can ignre ^history.

    What I have done is on one terminal run `tail -f ~/.bash_history` and
    then run in another terminal `l;history -a` and `XX;history -a` and what
    not.

    > If you want to write right after each prompt, you can probably execute
    > 'history -a' in the env var that controls the prompt. The var is $PS1
    > and is defined in /etc/bash.bashrc, around line 150.


    Thanks for the pointer. I am sure it will be very helpfull for many
    people. I amalready aware of that. Have you seen that the roorshell is now
    red in 10.3 by default? You are very welcome. ;-) I can't find the
    bugzilla number right now, but it is in there somewhere.

    I have added the following:
    #Colors
    BLACK="\[\033[0;30m\]"
    GREY="\[\033[1;30m\]"
    BLUE="\[\033[0;34m\]"
    LBLUE="\[\033[1;34m\]"
    GREEN="\[\033[0;32m\]"
    LGREEN="\[\033[1;32m\]"
    CYAN="\[\033[0;36m\]"
    LCYAN="\[\033[1;36m\]"
    RED="\[\033[0;31m\]"
    LRED="\[\033[1;31m\]"
    PURPLE="\[\033[0;35m\]"
    LPURPLE="\[\033[1;35m\]"
    BROWN="\[\033[0;33m\]"
    YELLOW="\[\033[1;33m\]"
    LGREY="\[\033[0;37m\]"
    WHITE="\[\033[1;37m\]"
    NO_COLOUR="\[\033[0m\]"
    TITLEBAR='\[\033]0;\u@\h : \w\007\]'

    #Standard houghi prompt
    C1=`tput setaf 1`
    C2=`tput setaf 2`
    C3=`tput setaf 3`
    C4=`tput setaf 4`
    C5=`tput setaf 5`
    C6=`tput setaf 6`
    C7=`tput setaf 7`
    PS1="$NO_COLOUR[\w]
    $BLUE\u@\h : $NO_COLOUR"

    And each machine has a different colour. That way when I ssh into an
    external macchine, I can see that I am not on m 'normal' terminal.

    It is possible to change colour by deaflt. e.g. root is red, user is
    green, if you ssh into it it is blue, telnet into it it is organge, ...

    See http://tldp.org/HOWTO/Bash-Prompt-HOWTO/ for more infor.

    houghi
    --
    You tried, and you failed, so the lesson is, never try. - Homer J. Simpson.

  16. Re: Reload of .bash_history

    Nikos Chantziaras wrote:
    > Also, if you need to do any tricks or fancy stuff each time you logout,
    > you can just put the commands in ~/.bash_logout


    To me it is like "Hotel Callifornia". I want to check out but not leave.

    houghi
    --
    You tried, and you failed, so the lesson is, never try. - Homer J. Simpson.

  17. Re: Reload of .bash_history

    houghi wrote:
    > Nikos Chantziaras wrote:
    >> Also, if you need to do any tricks or fancy stuff each time you logout,
    >> you can just put the commands in ~/.bash_logout

    >
    > To me it is like "Hotel Callifornia". I want to check out but not leave.


    I use to put the command 'clear' in ~/.bash_logout for security reasons
    when I *do* logout at some point. This is an issue in the first console
    (F1) since it's not automatically cleared.

    But we're talking about a public machine here; at home you probably
    won't need that.

+ Reply to Thread