Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My Ubuntu headless server is about to lose both hard drives(raid1). I already saved the most important stuff. Now I'm sitting in front of a Mac OS X client with the terminal open (ssh).

I need to save the whole or at least the most important install commands I wrote. So basically the first 1k commands...

I would like to print that & save it to a file. So I can easily reinstall everything.

By the way, also save some hard researched config files that I don't remember where they are.

share|improve this question
up vote 21 down vote accepted

There is already a hidden file in your home directory called .bash_history which you can print it. One observation here: this file, in a default configuration, doesn't contain the commands used in your current opened terminal session. So, close the terminal before to print it.

But if you want to save the terminal history in another file, then you can use the following command (this new file will contain also and the commands used in your currently opened terminal session):

history > history_for_print.txt

A new file called history_for_print.txt will be created in your currently working directory containing your last used commands (by default HISTSIZE=1000 and HISTFILESIZE=2000, but you can change these values in your ~/.bashrc file).

share|improve this answer
and where is the file? btw i need it on the mac – cocco Jan 23 '14 at 8:07
ok i got i t working thx – cocco Jan 23 '14 at 8:09
@cocco I updated my answer. – Radu Rădeanu Jan 23 '14 at 8:18
You can also run "history -a" to write commands from the current session to the history file without having to exit. – Steven Kath Jan 23 '14 at 17:47

To save your code outputs which display in command window you can use for example ./ &> output.txt This command save all outputs include errors and esults into text file

share|improve this answer
This is not what the question was about. Read the question and accepted answer. – techraf Apr 17 at 8:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.