Results 1 to 8 of 8

Thread: Bash history questions

  1. #1
    Join Date
    Sep 2012
    Location
    Maryland, US
    Posts
    623

    Default Bash history questions

    Hello All,

    I cleared my bash history with this command "history -c" and now I would like to have my history back


    So I look into ~/.bash_history and discover the history of commands is still there inside the file.

    How can I get my history back so I can use it in the Konsole again?

    Can I clean out all the silly commands in .bash_history (ll, ls, cd .., etc...) and then put the file back as a condensed version?
    Kernel: 4.12.14-lp150.12.7-default x86_64 bits:
    64 Desktop: Gnome 3.26.2
    Distro: openSUSE Leap 15.0

  2. #2
    Join Date
    Sep 2012
    Location
    Maryland, US
    Posts
    623

    Default Re: Bash history questions

    So does anyone know the mechanism used by the command "history -c"?

    Obviously the bash_history file is unaffected by this command but yet your history when using the up key has been wiped out.
    Is there a different history file used by the trigger up key?
    Kernel: 4.12.14-lp150.12.7-default x86_64 bits:
    64 Desktop: Gnome 3.26.2
    Distro: openSUSE Leap 15.0

  3. #3
    Join Date
    Jun 2008
    Location
    Earth - Denmark
    Posts
    10,730

    Default Re: Bash history questions

    On 06/07/2013 08:06 PM, anika200 wrote:
    >
    > So does anyone know the mechanism used by the command "history -c"?


    did you look in 'man history'? (i ask because i didn't find the -c in
    there, and i don't really know where you found it or if it is
    actually the command to "clear" the history...maybe it means "confuse
    the user" or "cloke the history" and -uc means to uncloke??....)

    > Obviously the bash_history file is unaffected by this command but yet
    > your history when using the up key has been wiped out.
    > Is there a different history file used by the trigger up key?


    hmmmm....have you looked in 'info history'

    i just glanced at it, and still can't answer any of your questions, but:

    have you tried closing that terminal/konsole/console/xterm/whatever
    and opening another one? (maybe it works?)

    or, hold down Ctrl and press r, does the prompt change? if so just
    type in a part of any command you know was in the history before you
    deleted it...does it find that old command?

    --
    dd
    http://tinyurl.com/DD-Caveat

  4. #4

    Default Re: Bash history questions

    Quote Originally Posted by DenverD View Post
    On 06/07/2013 08:06 PM, anika200 wrote:
    >
    > So does anyone know the mechanism used by the command "history -c"?


    did you look in 'man history'? (i ask because i didn't find the -c in
    there, and i don't really know where you found it or if it is
    actually the command to "clear" the history...maybe it means "confuse
    the user" or "cloke the history" and -uc means to uncloke??....)
    From UNIX man pages : history: ()
    history [n]
    history -c
    history -d offset
    history -anrw [filename]
    history -p arg [arg ...]
    history -s arg [arg ...]
    ... Options, if supplied, have the
    following meanings:
    -c Clear the history list by deleting all the entries.
    -d offset
    Delete the history entry at position offset.
    ...
    -r Read the contents of the history file and use them as the
    current history.
    -w Write the current history to the history file, overwrit-
    ing the history file's contents.

    > Obviously the bash_history file is unaffected by this command but yet
    > your history when using the up key has been wiped out.
    > Is there a different history file used by the trigger up key?


    hmmmm....have you looked in 'info history'

    i just glanced at it, and still can't answer any of your questions, but:

    have you tried closing that terminal/konsole/console/xterm/whatever
    and opening another one? (maybe it works?)
    AFAIK the shell writes the history file back when it quits or when you call "history -w".
    With "history -r" you could read back the old one from the file.
    And with "history -d 3" you would delete the entry at the 3rd position.

  5. #5
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,438
    Blog Entries
    14

    Default Re: Bash history questions

    Quote Originally Posted by anika200 View Post
    So does anyone know the mechanism used by the command "history -c"?

    Obviously the bash_history file is unaffected by this command but yet your history when using the up key has been wiped out.
    Is there a different history file used by the trigger up key?
    Thanks, here goes my weekend . Never bothered about it, thought it should be something we could find in the man pages, aargh, nothing. My point (and yours, no doubt) is that .bash_history doesn't seem to change, and yet the history cannot be called anymore. Think, puzzle.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  6. #6
    Join Date
    Sep 2012
    Location
    Maryland, US
    Posts
    623

    Default Re: Bash history questions

    Quote Originally Posted by wolfi323 View Post
    From UNIX man pages : history: ()



    AFAIK the shell writes the history file back when it quits or when you call "history -w".
    With "history -r" you could read back the old one from the file.
    And with "history -d 3" you would delete the entry at the 3rd position.
    Way to go smarty, you solved another puzzle I was looking forward to at least a couple hours of hunting, ****n online man pages.
    I guess it is a built in Bash function but how it keeps track of when you clear it is a mystery.
    Kernel: 4.12.14-lp150.12.7-default x86_64 bits:
    64 Desktop: Gnome 3.26.2
    Distro: openSUSE Leap 15.0

  7. #7

    Default AW: Re: Bash history questions

    Quote Originally Posted by anika200 View Post
    I guess it is a built in Bash function
    Yes.
    but how it keeps track of when you clear it is a mystery.
    What do you mean exactly?

    Each shell has its own history in RAM, when you clear it you only clear the local shell's RAM copy.
    Only on quit or when you call "history -w" it will be written back to the file.
    And with "history -r" you can read it back from the file (any file actually, by specifying a filename).

  8. #8
    Join Date
    Sep 2012
    Location
    Maryland, US
    Posts
    623

    Default Re: AW: Re: Bash history questions

    Quote Originally Posted by wolfi323 View Post
    Yes.

    What do you mean exactly?

    Each shell has its own history in RAM, when you clear it you only clear the local shell's RAM copy.
    Only on quit or when you call "history -w" it will be written back to the file.
    And with "history -r" you can read it back from the file (any file actually, by specifying a filename).
    Hahahaha, now that I have rebooted my whole history is back again. I feel like a total noob, I even have bash books???
    Kernel: 4.12.14-lp150.12.7-default x86_64 bits:
    64 Desktop: Gnome 3.26.2
    Distro: openSUSE Leap 15.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •