- How to copy the terminal output?
- 5 Answers 5
- Save console output into a file:
- How to Copy Paste in Linux Terminal [For Absolute Beginners]
- How to copy and paste text and commands in the Linux terminal
- Method 1: Using keyboard shortcuts for copy-pasting in the terminal
- Method 2: Using right-click context menu for copy-pasting in the terminal
- Method 3: Use the mouse to copy and paste into the Linux terminal
- Why Linux terminals do not use the ‘universal’ Ctrl+C and Ctrl+V for
- There are no universal key shortcuts for copy-paste in the Linux terminal. Here’s why!
- Conclusion
- Copying text from a terminal (Русский)
- Общий подход
- Терминалы без поддержки CLIPBOARD
- Xorg
- Перехват вывода команды
- Получение вывода Linux-терминала
- Сравнение популярных эмуляторов терминала
- Особые случаи
- putty
- urxvt
- xterm
- mlterm
How to copy the terminal output?
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 5
- 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
- Redirect the text to a file using redirection
P.S. from the comments below,
- Select the text to be pasted, and use mouse middle button (scroll wheel button) to paste it at desired place.
There’s also the buffer. In most terminal emulators I’ve used, if you copy over some text, you can paste it elsewhere with a click of the scroll wheel.
@Rob: not only in terminals, anywhere. This trick is little known, even by some old time Linux users.
Save console output into a file:
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
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 CTRL D 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
How to Copy Paste in Linux Terminal [For Absolute Beginners]
Here are various ways to copy paste text and commands in Linux terminal along with explanation on why Ctrl+C and Ctrl+V doesn’t work in the terminal.
I have been using Linux for a decade now and this is why sometimes I take things for granted. Copy-pasting in the Linux terminal is one such thing. I thought everyone already knew this until one of the It’s FOSS readers asked me this question. I gave the following suggestion to the Ubuntu user:
Use Ctrl+Insert or Ctrl+Shift+C for copying and Shift+Insert or Ctrl+Shift+V for pasting text in the terminal in Ubuntu. Right-click and select the copy/paste option from the context menu is also an option.
I thought of elaborating on this topic especially when there is no single universal way of copying and pasting in the Linux terminal.
How to copy and paste text and commands in the Linux terminal
Method 1: Using keyboard shortcuts for copy-pasting in the terminal
On Ubuntu and many other Linux distributions, you can use Ctrl+Insert or Ctrl+shift+C for copying text and Shift+Insert or Ctrl+shift+V for pasting text in the terminal. The copy-pasting also works for external sources. If you copy a command example from It’s FOSS website (using the generic Ctrl+C keys), you can paste this command into the terminal using the Ctrl+Shift+V into the terminal. Similarly, you can use Ctrl+shift+C to copy text from the terminal and then use it to paste in a text editor or web browser using the regular Ctrl+V shortcut. Basically, when you are interacting with the Linux terminal, you use the Ctrl+Shift+C/V for copy-pasting.
Method 2: Using right-click context menu for copy-pasting in the terminal
Another way of copying and pasting in the terminal is by using the right-click context menu. Select the text in the terminal, right click and select Copy. Similarly, to paste the selected text, right-click and select Paste.
Method 3: Use the mouse to copy and paste into the Linux terminal
Another way to copy-paste in a Linux terminal is by using only the mouse. You can select the text you want to copy and then press the middle mouse button (scrolling wheel) to paste the copied text. Please keep in mind that these methods may not work in all the Linux distributions for a specific reason that I explain in the next section.
Why Linux terminals do not use the ‘universal’ Ctrl+C and Ctrl+V for
No Linux terminal will give you Ctrl+C for copying the text. This is because by default Ctrl+C keybinding is used for sending an interrupt signal to the command running in the foreground. This usually stops the running command. This behaviour has been existing long before Ctrl+C and Ctrl+V started being used for copy-pasting text. Since the Ctrl+C keys are ‘reserved’ for stopping a command, they cannot be used for copying.
Used Ctrl+S and hanged the terminal?
The keyboard shortcut CTRL + S in the Linux terminal is used to send a «stop» signal to the terminal, which results in a frozen terminal. Just use Ctrl+Q and you can use the terminal again.
There are no universal key shortcuts for copy-paste in the Linux terminal. Here’s why!
The keybindings for copy-pasting are dependent on the terminal emulator (commonly known as terminal) you are using. If you didn’t know that already, a terminal is just an application, and you can install other terminals like Guake or Terminator. Different terminal applications may have their own keybindings for copying and pasting like Alt+C/V or Ctrl+Alt+C/V. Most Linux terminals use the Ctrl+Shift+C/V keys but if it doesn’t work for you, you may try other key combinations or configure the keys from the preferences of the terminal emulator.
Conclusion
I know this is elementary for the Sherlock Holmes of the Linux world but it could still be useful to the Watsons. If you are absolutely new to the terminal, this is going to help you a great deal. New or not, you may always use shortcuts in the Linux terminal to make your life easier. If you really care about increasing productivity through the Linux terminal, these handy Linux command tips and tricks will be a good starting point. 💬 Do you still have questions? The comment section is all yours.
Copying text from a terminal (Русский)
Состояние перевода: На этой странице представлен перевод статьи Copying text from a terminal. Дата последней синхронизации: 26 января 2022. Вы можете помочь синхронизировать перевод, если в английской версии произошли изменения.
Большинство современных эмуляторов терминала позволяют пользователям копировать или сохранять их содержимое.
Общий подход
В графических эмуляторах терминалов содержимое обычно выделяется с помощью мыши и может быть скопировано с помощью контекстного меню, меню Правка или комбинации клавиш, например Ctrl+Shift+C .
Терминалы без поддержки CLIPBOARD
Xorg
Некоторые эмуляторы не поддерживают буфера CLIPBOARD нативно и копируют данные в буфер PRIMARY. Для них можно использовать xclip :
$ xclip -o | xclip -selection clipboard -i
Эта команда читает данные из буфера PRIMARY и записывает в буфер CLIPBOARD.
Некоторые менеджеры буфера обмена (например autocutsel ) предоставляют автоматическую синхронизацию между этими двумя буферами.
Перехват вывода команды
Команда tee позволяет скопировать вывод команды в файл.
$ команда 2>&1 | tee файл-для-вывода
Получение вывода Linux-терминала
Прочитать буфер вывода нативного терминала /dev/ttyN можно в соответствующем файле /dev/vcsN . Например, сохранить содержимое терминала /dev/tty1 в файл можно так:
# cat /dev/vcs1 >файл-для-вывода
Сравнение популярных эмуляторов терминала
The factual accuracy of this article or section is disputed.
Сочетание клавиш для копирования у большинства терминалов Ctrl+Shift+c , если не указано иное.
Эмулятор | Выделение в PRIMARY | CLIPBOARD | ||||
---|---|---|---|---|---|---|
Сочетание клавиш | Контекстное меню | Меню окна | Выделение | |||
Alacritty | Да | Да | Нет | Нет | Нет | |
aterm AUR | Да | Нет | Нет | Нет | Нет | |
eterm AUR | Да | Нет | Нет | Нет | Нет | |
germinal AUR | Да | Да | Да | Нет | Нет | |
Guake | Да | Да | Да | Нет | Нет | |
Konsole | Да | Да | Да | Да | Опционально | |
lilyterm-git AUR | Да | Да Ctrl+Delete | Да | Нет | Нет | |
lxterminal | Да | Да | Да | Да | Нет | |
mate-terminal | Да | Да | Да | Да | Нет | |
mlterm AUR | Да | Да | Нет | Нет | Да | |
pantheon-terminal | Да | Да | Да | Нет | Нет | |
PuTTY | Да | Нет | Нет | Нет | Нет | |
qterminal | Да | Да | Да | Да | Нет | |
roxterm AUR | Да | Да | Да | Да | Нет | |
rxvt AUR | Да | Нет | Нет | Нет | Нет | |
sakura AUR | Да | Да | Да | Да | Нет | |
st | Да | Да | Нет | Нет | Нет | |
Terminator | Да | Да | Да | Нет | Нет | |
terminology | Да | Да | Да | Нет | Нет | |
Termite | Да | Да | Нет | Нет | Нет | |
Tilda | Да | Да | Да | Нет | Нет | |
urxvt | Да | Да Ctrl+Alt+c | Нет | Нет | Опционально | |
xfce4-terminal | Да | Да | Да | Да | Нет | |
xterm | Да | Опционально[1] | Нет | Нет | Да | |
Yakuake | Да | Да | Да | Нет | Опционально |
Особые случаи
putty
Подход xclip работает и для putty: нужно только помнить, что вызов xclip должен быть выполнен на локальном компьютере (в другом терминале), а не на удалённой машине, к которой подключен putty.
urxvt
Для выделения текста в CLIPBOARD требуется perl-расширение selection-to-clipboard. Подробнее смотрите rxvt-unicode (Русский)#Вырезать и вставить.
xterm
Доступ к буферу CLIPBOARD в xterm требует дополнительных шагов.
mlterm
В дополнение к Ctrl+Shift+c также доступно сочетание клавиш Ctrl+Insert , если вы не хотите случайно завершить процесс.