2

Is there a shortcut (keyboard) to automatically scroll back to the beginning of a response to a command?

Example: I open the terminal and type the 'last' command and press enter. A long lost of previously logged in users appears but I am at the end (i.e. oldest users). Scrolling back up to the top can be a bit of a pain. Is there a way to jump to the top of the output of this command?

I checked the man page for 'last' doesn't seem to contain such a function.

1

Not that I'm aware of, you'd normally pipe the output into a pager like less.

$ last | less
  • Thanks @rusty shackleford i'm new to Linux, i've come across the last command before but never realized I had a use for it until now. It suits my purpose perfectly. For future reference you run the following command $ last | less, the output from last will open in some kind of editor window (I don't know a better way to describe this). Navigating to the top or the bottom of this open file/window is simple type gg to go to the top and shift+g to go to the bottom. – MarkMark Jun 6 '18 at 15:38
-1

I'm afraid there is no a general, terminal-agnostic way to do that. In general, you have to find a way to go back to a previous prompt. For example, if you use GNU screen you can enter copy/scrollback mode with C-a [, move one line up, enter ? and type a part of your prompt. In xfce4-terminal you can select Terminal->Find and then enter a part of your prompt and press Previous. You don't even have to use mouse to do that - Shift-Controlf, type your query and press Alt-p. See a possible solution for tmux here: Jump to last prompt in terminal (or tmux).

The only minor drawback of that solution is that your prompt might be constructed dynamically and might be different after each command but usually there is a common part that you can use to search for backwards.

  • Please do not leave downvotes without an explanation. – Arkadiusz Drabczyk Jun 6 '18 at 14:46
  • Thanks for you help @Arkadiusz Drabczyk, the answer provided by rusty shackleford (above) is exactly what I was looking for in this instance but I am sure I will need your process for something in the future. I didn't down vote your answer by the way, I appreciate your time and effort. – MarkMark Jun 6 '18 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.