20

I am moving from one server to another, but want to keep my history, so I dumped it into a file.

history > file.txt

Is there a way to overwrite the commands-history of bash and load it from a file?

Shaharg
  • 971
  • 1
  • 11
  • 26
  • 1
    simply copy your `$HOME/.bash_histroy` file and youre done... Don't need the "export". – clt60 Sep 10 '14 at 09:27
  • For some reason it seems that my .bash_history file is not getting updated. This might be related for the fact I use a grid gateway that has a common file system with other gateways. In any case. The accepted answer below solved my problem. Thanks – Shaharg Sep 11 '14 at 06:50
  • strange, just tried `scp .bash_history my@panda:~` and logged in to panda and got my history. IMHO probably because you tried replace it _in the current shell_, and when you logged out the `savehist` overwrite the file with the current history. – clt60 Sep 11 '14 at 07:03

2 Answers2

30

The following will append the contents of file.txt to the current in-memory history list:

history -r file.txt

You can optionally run history -c before this to clear the in-memory history.

chepner
  • 497,756
  • 71
  • 530
  • 681
0

You can try to edit this file and paste everything in there:

emacs -nw ~/.bash_history

Here's an interesting post about the command-history: http://www.ducea.com/2006/05/15/linux-tips-take-control-of-your-bash_history/

the_marcelo_r
  • 1,847
  • 22
  • 35