Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load bash command history from file

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?

like image 930
Shaharg Avatar asked Sep 10 '14 09:09

Shaharg


People also ask

How do I import history into bash?

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.

How bash saves a history in a file?

Saving the History List. By default, when starting a new session, Bash reads the history list from the . bash_history file . The list of commands that are executed in the current session are kept in the memory and saved to the file when the session is closed.

Where is bash command history stored?

In Bash, your command history is stored in a file ( . bash_history ) in your home directory.

How do I run a previous command from history?

Another way to get to this search functionality is by typing Ctrl-R to invoke a recursive search of your command history. After typing this, the prompt changes to: (reverse-i-search)`': Now you can start typing a command, and matching commands will be displayed for you to execute by pressing Return or Enter.


1 Answers

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.

like image 190
chepner Avatar answered Sep 17 '22 17:09

chepner