3

Before I start - I am a 69-year-old Linux newbee - take it easy on me!

Is there an easy way to copy the entire contents of a Terminal (many pages) - "man pages", which I am told are not the same as Terminal pages but look the same to newbee me - see comment below - so that I can transfer it to a text editor? Presently I have to highlight and copy one page at a time, which is rather laborious.

I have seen the explanations of how to copy only a section of the contents of a many-paged Terminal - and this is a little tricky for me - - - I was hoping there was a quick and easy way to do the entire contents?

Thank you for your patience.

Duncan
  • 1,053
  • 2
    You haven't told us what Ubuntu you are using, and what DE (which could be GNOME or Unity, or different if it's a Ubuntu flavor such as Xubuntu) which is useful. As I'm running Xubuntu, I'm using xfce4-terminal, and I can edit ALT E (or click the EDIT menu) and then SELECT ALL and all text in the terminal is selected. I could then select COPY, or COPY AT HTML, or I'd just hit CTRL-INS to copy it to my buffer, and then paste into my text editor. This would work in all Xubuntu's (i'm using 19.04 but that doesn't matter). You could always install xfce4-terminal but there may be better... – guiverc Nov 14 '18 at 12:38
  • 2
    You can do something similar all in one command. From a terminal window type in man find > /tmp/temp.txt && gedit /tmp/temp.txt 2>/dev/null – Terrance Nov 14 '18 at 14:16
  • The following comment has been made - I don't really understand it but the writer seems to know what he is talking about and has asked me to include it here - so, here goes: This looks unrelated to the original question. Is your real intention to save man pages? Then please edit your question or create a new one since man pages are quite different from what you wrote earlier. They are not printed to the terminal altogether by default (using less as the pager) and the ways suggested by others to copy the terminal contents won’t work for them. – Duncan Nov 15 '18 at 19:54

5 Answers5

4

Two options that don't require selecting, copying and pasting text are:

save output from a single command to a file: this question has several useful answers covering different ways you can pipe command output to a file. Such as: command 2>&1 | tee ~/outputfile.txt which will write both standard and error output to outputfile.txt (refer to above link for other variations).

or

save a whole session to a log with: script logfile
(as mentioned here). everything that follows will be logged to "logfile"
then type exit when your done to stop logging.

Starbuck
  • 1,003
  • 8
  • 21
  • 1
    Happy to help and share my experience, because I would have been lost on many things If not for the help of others. If one of these answers was what you were looking for, don't forget to choose it as the one that solved your problem so others that come across your question know what solution worked for you. – Starbuck Nov 16 '18 at 02:57
  • The script suggestion is priceless, thank you. I had a situation where tee wasn't going to cut it and I thought I was out of luck. – glaucon Mar 21 '22 at 03:43
3

The default terminal emulator on Ubuntu, gnome-terminal should have a "Select all" option in its "Edit" menu.

Once everything is selected, you can copy it with Ctrl+Shift+C, or right-click and selecting "Copy", or "Copy" from the "Edit" menu.

Note however that the terminal buffer is limited by default to a few thousand lines. If your session accumulates more lines, those will be truncated and you only get the most recent part. If you need more, you can change the size of the scrollback buffer in the menu "Edit" > "Profile preferences" > "Scrolling" > "Limit scrollback to ___".


Update based on your clarification in comments:

man uses a pager (should be less by default) which uses a different terminal mode to provide scrollable text on a single screen, instead of relying on the terminal emulator to let you scroll through the backlog.

To get the whole content of a man page in your terminal at once, so that you can select and copy it all, you can tell it to not use any pager by adding the argument --pager=, like:

man --pager= find

If you want this behaviour to be the default, you can append the line below to your ~/.bashrc file:

export MANPAGER=""

Alternatively, the pages is also disabled if you pipe the output through any other command, like e.g. cat, which just reproduces it as it is:

man find | cat

Or if your actual goal is to save the manual to a text file, you can redirect the command output to a file directly:

man find > find.txt
Byte Commander
  • 107,489
  • Many thanks for your comment. However, it seems my question was not clear - best I describe in point form so you understand the problem: 1. Using a Termnial in Ubuntu, I opened the "man find" page - which is many pages long. I would like to copy this, in its entirety, to transfer elsewhere (e.g. to a text editor). I hope this describes my problem better - sorry for the lack of clarity but, being a newbee, I have difficulty with terminology. Thank you for your patience! – Duncan Nov 14 '18 at 12:40
  • duplicate erased – Duncan Nov 14 '18 at 12:41
  • Oh - I see - I don't have to open the terminal at all - I can just open the text editor to find the "man find" file and take it from there. Sorry, I did not realise this - see what a newbee I am! Thanks for your patience! – Duncan Nov 14 '18 at 12:54
  • @Duncan while you can open man page files (for example, /usr/share/man/man1/find.1.gz) they are compressed files with embedded markup - probably not something you will find useful as-is. If you really want to use a text editor, then you will probably want to use the man command to pre-process the file and save that to a plain text file that you can open/edit e.g. man find > manfind.txt then vi manfind.txt. Alternatively you may want to check out Graphical user interface to view man page? – steeldriver Nov 14 '18 at 13:33
  • I updated my answer @Duncan – Byte Commander Nov 14 '18 at 13:49
  • I think this answer seems a bit more complicated than it needs to be though I may have overlooked something in the comments. But what is wrong with man find > some_file then open some_file with your favorite text editor? – j-money Nov 14 '18 at 20:19
2

If you want many pages but not all

You can right click at the bottom of the terminal window and drag your mouse up to the window title bar.

The text will scroll as it is highlighted. After appropriate number of pages are highlighted, press the mouse's right button. A context sensitive menu appears where you can select copy.

Move cursor to your editor and right-click again. Now select paste.

1

I use Ubuntu 16. I am trying to learn Linux and the use of the Terminal. I was wanting to know how to find files. I was directed to "man find" to find the information of how to use the "find" function in the Terminal. So, I went to the Terminal, typed "man find" which took me to those particular pages of the manual - many pages long. I wanted to copy all of that text and transfer it elsewhere (to a text file editor) but did not know how to copy all the text at once - I could only copy one page at a time from the Terminal pages.

SOLUTION: One does not need to use the Terminal at all - one just goes to the text editor and "man find" within that - and here one can copy all the text easily. Hope this helps some other newbee!

Duncan
  • 1,053
  • 3
    Or you can send the man page to a file: man find > temp.txt will save the manual in file temp.txt in your current directory. – Jean-Marie Nov 14 '18 at 13:15
  • 1
    manual pages are available to view in a web browser as well! check out https://linux.die.net/man/ or just do a search for "man somecommand" – Starbuck Nov 14 '18 at 14:42
  • 2
    This looks unrelated to the original question. Is your real intention to save man pages? Then please edit your question or create a new one since man pages are quite different from what you wrote earlier. They are not printed to the terminal altogether by default (using less as the pager) and the ways suggested by others to copy the terminal contents won’t work for them. – Melebius Nov 15 '18 at 14:35
1

I have found the easiest ways to address my problem: 1. The "script" command works: It makes a copy of what is in the terminal / man pages and formats it in a way which can be printed from a text file. 2. just add " >> tempfile.log" at the end of every command - one can then edit it later as you want in libreoffice

Duncan
  • 1,053