TransWikia.com

How to copy the terminal output?

Super User Asked by Andy Frédéric ANDRIANIAINA on December 29, 2021

I executed commands in the terminal and there are outputs shown in the terminal. I want to select all the screen shown. How to achieve that ?

5 Answers

First define a shortcut for marking all. (https://askubuntu.com/a/1291548/676490)

  1. Go to Menu->Preferences->Shortcuts
  2. From Edit selection choose "Select All"
  3. Then to assign press Ctrl+Shift+A

CC-BY-SA: Biddut Mitra


  • Ctrl+Shift+A
  • Ctrl+Shift+C
  • go whereever you want to paste it
  • Ctrl+v

Answered by JoKalliauer on December 29, 2021

For windows users

I know this is off-topic to the question, but having all info under the same question helps rather than creating a dupe

Scenario

  • You didn't think through and let a command display it's output rather than save it to a file
  • My speciic solution is for cmd.exe on windows, might work for poweshell as well (not tested)

1. Small amount of text

Option 1: use your mouse

  1. click and drag mouse across the text you want to copy See example screenshot here
  2. click enter (return key)

Now the text is in your clipboard

Option 2: use the "mark" menu

  1. right click on the title bar and navigate down and select mark. See screenshot below select mark menu item
  2. click and drag mouse across the text you want to copy See example screenshot here
  3. click enter (return key)

Now the text is in your clipboard

2. Large amount of text

  • Say, you have a lot of terminal output you want to copy
  • This is limited to your terminal buffer size, so you should have selected a large terminal buffer in either defaults or in the properties of cmd window (see above screenshot for that menu item), else that text is just lost (not sure if windows stores cmd output somewhere).
  • This is the main "trick" I wanted to note here. Cause even though I consider myself a power user, I didn't know this.

Here are the steps

  1. right click the titlebar and nagivate and click select all Click select all menu item
  2. click enter (return key)

Now all the text is in your clipboard

Answered by Dheeraj Bhaskar on December 29, 2021

As opposed to the solutions suggested above, you may get into a situation where the output was already printed and you weren't smart enough to know beforehand that you'd like to record it somehow.

In that case, you can at least save to a file the text that can be seen at the moment in your TTY using the backlog via /dev/vcs#. For example if you were using /dev/tty1, this terminal's backlog is available in /dev/vcs1 so for example:

# cat /dev/vcs1 > tty1.log

Credits are reserved for The Arch Wiki: https://wiki.archlinux.org/index.php/Copying_text_from_a_terminal#Accessing_Linux_terminal_backlog

Answered by Doron Behar on December 29, 2021

Save console output into a file:

  1. tee command

tee command - read from standard input and write to standard output and files.

It automatically creates file and save, all the output of cmd ps -ax into a file named as processes_info in the same folder from where the cmd has run.

user@admin:~$ ps -ax | tee processes_info
  1. script command

script command - make typescript of terminal session.

user@admin:~$ script my_console_output.txt

This creates a file named as my_console_output.txt and will open a subshell and records all information through this session. After this, script get started and whatever the console output, it will get stored in the file my_console_output.txt; unless and until the script ends when the forked shell exits. (e.g., when the user types exit or when CTRLD is typed.)

user@admin:~$ script -c "ps ax" processes_info.txt
  • it starts the script;

  • creates the file processes_info.txt;

  • stores the console output into the file;

  • end (close) the script.

    Other example:

     script -c 'echo "Hello, World!"' hello.txt
    

Answered by akD on December 29, 2021

There are 2 options,

  1. Either you can copy-paste the selected text using Ctrl + Shift + C and Ctrl + Shift + V in which you have freedom what things to copy OR

  2. Redirect the text to a file using redirection

    program1 >outputfile.txt 2>errorfile.txt

    here, all the stdout will go to outputfile.txt while all the stderr will go to errorfile.txt.

P.S. from the comments below,

  1. Select the text to be pasted, and use mouse middle button (scroll wheel button) to paste it at desired place.

Answered by Vineet Menon on December 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP