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?

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?

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

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.

Thanks, here goes my weekend :D. 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.

Way to go smarty, you solved another puzzlelol! 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.

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).

Hahahaha, now that I have rebooted my whole history is back again. I feel like a total noob, I even have bash books???