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?
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.
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.
In Bash, your command history is stored in a file ( . bash_history ) in your home directory.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With