How can I transfer my bash history to a new system?

6,324

Your bash history is saved in a plain text file, called by default .bash_history.

Unless you modified the $HISTFILE variable you should find it in your home directory:

$ echo $HISTFILE
/home/sylvain/.bash_history

If you keep your home partition when updating or reinstalling your system and if $HISTFILE is saved on this partition, there's nothing else to do.

To transfer the file to a new computer, just save it on a USB drive and replace the existing .bash_history of the target system.

If HISTTIMEFORMAT was set on the "old" system, don't forget to set it again otherwise the timestamps of the new commands won't be saved as comments in the "new" .bash_history file.

In case you would like to merge both old and new with new being saved at the end of the history file, you can use this method:

sudo apt-get install moreutils
cat .bash_history.old $HISTFILE | sponge $HISTFILE
Share:
6,324

Related videos on Youtube

Sylvain Pineau
Author by

Sylvain Pineau

I'm an early user and advocate of Linux, and more generally Open Source Software, in the business world. I've been around with computers and particularly linux for some time now, and during all these years I've been using and promoting opensource technologies. I started using Linux in 1995 with a French Slackware, called Kheops. My first contact with Ubuntu was in 2006 with Edgy. Former Perl Monger, my preferred language is now Python. I know about web standards and design, HTML/CSS, and some QML/Javascript. The early years of my career were spent developing the French high speed train (TGV) RTOS. My professional activities also led me to several QA related positions and to Android phones integration before joining Canonical in 2010. I'm now working for the Hardware Certification Team at Canonical.

Updated on September 18, 2022

Comments

  • Sylvain Pineau
    Sylvain Pineau over 1 year

    My bash history is my memory, it contains commands that I don't want to loose when I update to a newer version of Ubuntu or change my computer.

    Is it possible to transfer the commands database to a fresh installation?

  • fiatux
    fiatux almost 9 years
    Why 2 calls to cat? cat can read multiple files: cat .bash_history.old $HISTFILE | sponge $HISTFILE
  • Sylvain Pineau
    Sylvain Pineau almost 9 years
    @glennjackman Absolutely, fixed.