The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 3,353,956β€…    Votes:  19β€…
Tag : command-line  
Link: πŸ” See Original Answer on Ask Ubuntu πŸ”—

URL: https://askubuntu.com/q/1198795
Title: How do I save terminal output to a file?
ID: /2019/12/27/How-do-I-save-terminal-output-to-a-file_
Created: December 27, 2019    Edited:  December 13, 2021
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


The script command

There are two different questions here. The first is in the title:

How do I save terminal output to a file?

The second question is in the body:

How do I save the output of a command to a file?

All the answers posted here address the second question but none address the first question which has a great answer in Unix & Linux:

This answer uses a little known command called script which saves all your shell’s output to a text file until you type exit. The command output still appears on your screen but also appears in the text file.

The process is simple. Use:

$ script ~/outputfile.txt
Script started, file is /home/rick/outputfile.txt
$ command1
$ command2
$ command3
$ exit
exit
Script done, file is /home/rick/outputfile.txt

Then look at your recorded output of commands 1, 2 & 3 with:

cat ~/outputfile.txt

This is similar to earlier answer of:

command |& tee ~/outputfile.txt

Send output to clipboard

Many times we want the output to go to the clipboard so we can paste it later. From this answer you can use:

cat ~/.bashrc | xclip -selection clipboard

Now you can use Ctrl+V in almost any application to paste the terminal output into your document. To paste the terminal output in the clipboard back into your terminal use Ctrl+Shift+V instead.

⇧ What is the purpose of the special parameter "_" (single underscore) in environment? Is there a way to show external IP in top bar using GNOME 3.28.2 in Ubuntu 18.04  β‡©