Linux(Ubuntu) Terminal-how to view previous pages not visible anymore - linux

When you scroll up, say to see a log, the first portion of it will not be visible since the terminal only supports a limited no. of lines. So if you want to scroll up and be able to see everything, at least a few pages up, how do you do it?

Use Shift+Page Up and Shift+Page Down.

Piping the output to a pager like the following is a better choice:
command | less
command | more

You can enable unlimited scroll back (or a huge amount if you want).
To do this, go to
File → Profile preferences → Scrolling [tab]
Then, check Unlimited, or set the number of lines desired. And of course, it only applies to the next typed lines.

Some tricks I use-
some terminal applications (gnome-terminal) allow you to increase the scroll-back buffer size
pipe output to a file:
command > file.log
pipe your command to less:
command | less
tail log and pipe to grep to reduce output
tail -f example.log | grep 'search text'

An alternative to screen is using tee to copy all output to a file while still printing it on the terminal:
yourcommand | tee output.txt

Try using the screen command, and set its scrollback buffer to a larger size.
screen has many other benefits and wonderful features.
If all you're doing is looking at a log, you could alternately use a pager such as less

If you want to scroll line by line, you can use
Control+Shift+Up/Down Arrows.

If you are using gnome-term (the default), then you can change your settings. Either set the no. of lines to unlimited, or to a much larger buffer size than the default.

Essentially seconding to #zerick's solution but if you're on gnome-terminal you can modify its config. See this.

If you are in tmux (can create multiple terminal sessions in a single terminal session, highly recommended), you can easily use your normal navigation keys to scroll around after you do Ctrl-b then [, for more details let's take a look at: How do I scroll in tmux?

None of these answer the original question. All answers are how to make new terminal windows (or current one) start behaving a certain way. The question is about how to see whats already scrolled away.
To answer this, each terminal session should have it's own "history" file (not to be confused with what command history is) containing all the stuff that relates to stdin/stdout displayed. I could be wrong but this may be different depending on the terminal emulator you use. Some just trash it when you close the window/ end the session.
I am trying to get this figured out myself so here is the more direct answer in a different thread.
https://unix.stackexchange.com/questions/145050/what-exactly-is-scrollback-and-scrollback-buffer
From what this tells me, I suspect best advice you can get is, for whatever terminal emulator you use, look for where it stores the scrollback buffer and that might be your only hope. It's what I am going to try right now. (and that is IF the session is currently still open, not closed terminal windows)

Related

xterm dump of full scrollable window content

I want to know if anyone does know a way to dump or copy the whole lot of viewable messages in a xterm window on linux. The very important thing is I don't want to know how to send a command out and kapture its output for stream 1 and 2 as well as the input, as this is well known to me.
I may explain for what this is needed. You do something and expect not any complications but than you got pages of msg's als err msg or normal output. To be able to see later after it you should be able to get them in a file and as long as you are able to scroll that all back and forther with your mouse it is sure the data is there some where. But the time may be not to scroll and screenshot and scroll ....
I would be glad to help me out in such cases and it would be fine to have the full view including all your own typing and all the msg's in same order as you watch it when you scroll it back.
I don't really know where this is stored and how you could get that saved. I know that I could dump the whole lot of Memory and search it for a part of the xterm window, but that is a bit over the top I think.
There is a control sequence, which I had forgotten. This question reminded me. In XTerm Control Sequences, it is noted "print all pages":
CSI ? Pm i
Media Copy (MC, DEC-specific).
Ps = 1 -> Print line containing cursor.
Ps = 4 -> Turn off autoprint mode.
Ps = 5 -> Turn on autoprint mode.
Ps = 1 0 -> Print composed display, ignores DECPEX.
Ps = 1 1 -> Print all pages.
That dates from 1999 (patch #119), so you likely have it in your xterm. You could do this in a shell command like this:
printf '\033[?11i'
A comment mentions the page Hidden gems of xterm, which uses the corresponding action print-everything (something that can be executed via the translations resource). It is in the manual page, of course. The same comment points to Extra characters in XTerm printerCommand output, which mentions the resource printAttributes. By default, the control sequences for the printer tell xterm to send extra control characters (to reconstruct video attributes). The resource can be modified (set to 0) to suppress that. That is even older (patch #74).
Without that — Conceivably one could construct an application which used the X SendEvent protocol to construct a series of events which would be interpreted as xterm actions to scroll back, select text and copy it chunk-by-chunk via the clipboard. You could even write it in Perl (there is a module for X protocol). But seriously, no.
If you want to capture text which was written to xterm, you can do this by preparing before the text is needed by different methods (see manual):
turn on the xterm logging feature (not that user-friendly because it generates the filename). This can be enabled using the "Log to File (logging)" menu entry.
use the printer control sequences to write lines as they are written (again, not that friendly, though there is a menu entry to turn it on and off, "Redirect to Printer (print-redir)")
use script to capture all output to the terminal. I use this, because it works with any terminal on any POSIX-like system (even Cygwin).
Each of these methods produces a file containing escape/control sequences, which requires filtering out. The hypothetical program using SendEvent could in principle eliminate that.

Go to beginning of output command created - shortcut

I can scroll trough bash output using shift+pgup/pgdown.
But lets say, some command outputted lot of text, I have to pageup few times to go to beginning of output of this command.
Can I just simply do this by some shortcut? Something that simply allows me to scroll between previous commands (not history!), seeing their output.
You could try piping the output into less:
someCommand | less
less will allow you to search and scroll through the output text pretty easily.
once in less you can just type % to jump back to the top of the page. Essentially that means jump to 0% of the page. There are also a bunch of extra commands on the page I linked to above.
Another option is to use screen and use backward search (beware: read the Overview first, especially the part about the C-a prefix) to e.g. search for some specific characters in your prompt (like your username).
The scroll back history in Unix shells is a shell specific functionality, meaning that it is up to the specific shell (xterm, rxvt, text console, etc) to handle it. The functionality you request would require the shell to identify the individual program runs, to know where to scroll to. Scanning text is not technically hard per se, but as prompts and command display can differ due to user settings it can be hard to make it work generally good. Some communication between the shell and the terminal could make it better.
There sure are some nice fancy terminal programs doing things like this, to for example show syntax help when writing commands, but for your case I agree with previous answer, that piping commands to less is a good way to isolate the output. It might be a bit cumbersome first, as it requires you to think about it first, and not just go back in history, but if you learn the shell better and learn to use the command history it will probably work fine. I recommend you to, if you haven't already. What I mean is ctrl-r etc. More described for example here:
http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/

Display big numbers in terminal

tmux can display big time like the picture below,
is there any way to display big numbers like that,
for example I want to show number of users in real time.
To the extent of my knowledge, there is no such feature in tmux. You could use watch (part of the procps tools) and figlet to implement such a feature:
watch runs a command periodically and prints the output on the screen. It always clears the screen before running the command.
figlet renders a string in a ASCII-Art style font. There a several fonts availiable.
So for instance you could show the number of users on a system (at least on Linux) using the following command line:
watch "who | wc -l | figlet -f big"
Unfortunatly the text won't be centered, as it is with clock-mode.

disable automatic line wrapping in Ubuntu terminal

I used some sql command to join two tables and the result was two terminal line long for each row of resulted table.
I dont want so ... i mean is there any way to get scroll bar at the bottom so that a row can be fit into a terminal line. and it will be a well structured and readable output
I hope you get my question.
There is no way on a standard terminal. You could use e.g. less as your pager for you sql-client.
I propose to pipe the output into the command less -S:
$ mysql-command-doing-the-SELECT | less -S
(To achieve this in the interactive mysql console, you can type pager less -S.)
Then all lines are displayed without being wrapped, and you can scroll sideways using the arrow keys. You can also use the command less (without the option -S) and then interactively type - S to achieve the non-wrapping. (Type again to toggle.)
If you need a real scroll bar, I propose to pipe the output into a real file and then use a more sophisticated program like gedit (which can be switched to a non-wrapping display) to display it with a decent scroll bar.
Another solution: copy the data from the terminal and paste it into your favorite editor. The copied text will not have any line breaks "\n".
(Offtopic: on a linux system you can just select the text with a mouse and mouse-middle-click in your editor. This will copy the text without filling out the main copy-paste buffer.)

How do I view a log file generated by screen (screenlog.0)

So I just found out I can create log files of everything I do in screen (C-a H). Sounds like a nice way to keep track of potential goofs in a particular screen session. However, when I went to try it out the logfile is reported as being a binary file (and can't be viewed like a regular text as such). So am I missing something? A quick man page looksee and searching Google (and SO) turns up nothing about this.
So my question is: How do I generate plain text log files in screen?
Assuming the answer is "What a noob... how about you try making them? RTFM." my question becomes: How do I use less to view screen logfiles I've created (since less screenlog.0 does not work on a binary file)?
EDIT: So cat works fine but less complains that the file is binary... why?
SOLUTION: as jcomeau_ictx helpfully pointed out, you can view these logfiles fine with cat or more but with less you must add the -r flag less -r screenlog.0
I just found a screenlog.0 on the net; it is plain text, with some escape sequences. Just 'cat' the file, you should be able to view it just fine.
[after more checking]
Control-A H is what generates the screenlog on my system. And though 'cat' works, you'll miss a lot of data. Use 'more' instead of 'less' to interpolate the escape codes.
I found neither less nor more nor cat to be an ideal solution for viewing screenlog files. All "replay" some of the control character so that e.g. screen deletions as produced by "clear" (don't remember the corresponding control character) are beeing shown, hiding what has been cleared.
What i know works great is: use "view" or "vi", it just shows the control character in escaped notation. Probably any other text editor works, too (not tested).
-L logs to file,
tail -f 'logfilename' to monitor this file

Resources