Reputation: 53873
I've got a program which has a lot of output. Once it's done I often want to scroll back to the begin of the run so that I can look at some things there. Since the output is so long though, I see myself endlessly scrolling with PageUp and trying to drag the scrollbar on the right to the point where it could have begun. Over a while this starts getting quite tiresome, so I wonder:
Is there a way to easily have the terminal scroll back to the part where the last command was given?
Upvotes: 48
Views: 20794
Reputation: 683
VTE based terminals, such as e.g. GNOME Terminal, GNOME Console, Xfce4 Terminal, Terminator, Tilix, Guake and more, support this feature since the GNOME 46 (VTE 0.76) release in March 2024.
The hotkey is hardcoded for the time being, it's Ctrl+Shift+Left and Ctrl+Shift+Right.
Under the hood, VTE uses the quasi-standard OSC 133 shell integration escape sequences to see where the prompts are, like several other terminals already do.
Upvotes: 2
Reputation: 144
On MacOS with iTerm2:
You have to have Shell Integration installed (iTerm -> Install Shell Integration) and open a new tab afterwards.
Press ⌘+Shift+Up to jump to the last mark. Also available under Edit -> Marks and Annotations -> Next Mark.
Upvotes: 9
Reputation: 51
ACHIEVING IT IN LINUX
Add to your prompt an identifier (for example add in the bottom of your .bashrc):
promptCount=0 PROMPT_COMMAND=promptCount=$((promptCount+1)) PS1="/\$promptCount\\ $PS1"
Now use the search funcionality of the terminal, perhaps Ctrl + Shift + F, for the prompt line you wish.
Making it more handy:
Install
xdotool
(command-line X11 automation tool)Create a function that will press the exact keys that you would press when finding the
N
prompt line through the searching functionality (add in the bottom of your .bashrc):gp () { xdotool key ctrl+shift+F; xdotool type /$1\\ ; xdotool key KP_Enter;sleep 0,2; xdotool key Alt+F4; }
(At least these are the exact keys that I would press to do it in Manjaro Xfce)
Now:
There is a little frame not shown in the gif where the little search window appears, the identifier for N
is written, key Enter is pressed and then the windows is closed. You can try to make this faster changing the value of the argument given to the sleep command. In my case it works well until 0,11 or so.
Upvotes: 5
Reputation: 12819
We could clear the terminal prior to running the command, with Ctrl-L.
Then after running the command, come back all the way up with Ctrl-Home.
Upvotes: 1
Reputation: 31
I pipe the output to less
, for example command | less
, because it has tons of useful keys for quick navigation plus it supports search. You also automatically start at the very start of output.
Here are some useful commands for quick navigation:
f
or SPACE
to move forward a page, b
to move back a page. A page refers to terminal window size worth of output.g
to go to the very start, G
to go to end, [n]g
to jump to n
th line. For example 5g
will jump to 5th line./pattern
to search for a term then navigate with n
for next and N
for previous occurrence. Supports RegExp.q
to quit.For more info just do man less
. Man pages also use less
by default so all of the above works.
Upvotes: 3
Reputation: 2179
A simple Hack which works if it takes some time until most of the output is printed (like when you call make):
Scroll up a very little bit (e.g., one line) immediately after executing the command. Since you're no longer at the bottom, this prevents most terminals from auto-scroll down. As soon as you think that output has been printed (scrollbar position and feeling are good indicators), you can scroll down. Just avoid to scroll to the very last line while it's printing.
Upvotes: 3
Reputation: 607
I use iTerm2
in macOS, I came up with a method. First, you should make sure you check the Unlimited scrollback
in iTerm2's preferences.
After you run a command in terminal and got a long long output.
Press Cmd
+F
(maybe ctrl
+F
in windows) then your can search in terminal like this:
Finally, just search your user name and press Enter
, generally speaking you will jump to the last command:
Upvotes: 6
Reputation: 379
I have just found this in Terminal for OSX:
Edit > Navigate > Jump to Previous Mark: cmd + UP.
Upvotes: 37
Reputation: 691
If you work with screen
, I think there is a way.
screen
commandCtrl+a
followed by [
. screen enters copy mode.Also screen
has lot of advantages. Check http://kb.iu.edu/data/acuy.html
Upvotes: 0
Reputation: 99
Is it not easier to simply redirect the output to a file, thereby keeping your terminal window "clean"?
something like: command >> output_file
Upvotes: 0
Reputation: 58788
If you're using a terminal like GNOME Terminal, you can search backwards. For example, Ctrl+Shift+f then enter either the literal command or a regular expression to match it (and make sure "Match as regular expression" is set accordingly).
A workaround would be to send the output to a pager such as less
, where you can navigate and inspect the output, then return to the command line as if nothing had been printed.
Upvotes: 3