Save the terminal history to a file for print

173,967

Solution 1

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).

Solution 2

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

Share:
173,967

Related videos on Youtube

cocco
Author by

cocco

Nodejs,canvas,js,websockets,css33d fun! https://www.youtube.com/playlist?list=PLL9y8ZNSfDQxqg37X4-2A9T-r98RcAOAs http://jsfiddle.net/Mjagk/1/ - http://jsfiddle.net/Mjagk/4/ http://jsfiddle.net/LxX34/11/ http://jsfiddle.net/hP8Me/4/ - http://jsfiddle.net/qZm4e/ - http://jsfiddle.net/qZm4e/5/ http://jsfiddle.net/znT2H/ http://jsfiddle.net/trjsJ/ http://jsfiddle.net/pc76H/2/ http://jsfiddle.net/DAbh8/ - http://jsfiddle.net/DAbh8/4/ http://jsfiddle.net/RAu8Q/5/ golf http://jsfiddle.net/CA6GM/2/ nojs http://jsfiddle.net/KLXMw/ http://jsfiddle.net/ufcqc/ fastclick http://jsfiddle.net/UK4Es/ http://jsfiddle.net/98NHn/ http://jsfiddle.net/qzm6X/ http://jsperf.com/dgfgghfghfghghgfhgfhfghfhgfh http://jsfiddle.net/brm0kuda/ http://jsfiddle.net/brm0kuda/1/ http://jsfiddle.net/8qp5cvjs/ http://jsfiddle.net/7Nedw/5/ http://jsfiddle.net/0c10oujz/ http://jsfiddle.net/LxX34/18/ http://jsperf.com/bidirectionalindexof

Updated on September 18, 2022

Comments

  • cocco
    cocco over 1 year

    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.

  • Steven K
    Steven K about 10 years
    You can also run "history -a" to write commands from the current session to the history file without having to exit.
  • techraf
    techraf almost 8 years
    This is not what the question was about. Read the question and accepted answer.
  • Ace.C
    Ace.C about 4 years
    It is a related and useful answer. The goal of SO is to be a useful resource.
  • Honey
    Honey about 3 years
    daghighan......