Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quickly scroll to the latest / end of command history in bash?

Tags:

bash

Lots of times I'll use Ctrl-R for reverse search and mistype some letter. Bash jumps up hundreds of lines and I'm in the middle of commands I was using a week ago.

Is there a shortcut for jumping back down to the lastest commands I had typed?

Edit: after testing it out on a CentOS server and Mac OS X, it looks like this only happening on OS X.

like image 634
volni Avatar asked Apr 18 '12 01:04

volni


People also ask

How do I scroll through command history?

After you have typed what you are looking for, use the CTRL-R key combination to scroll backward through the history.

How do I scroll to the end of terminal?

And to scroll down in the terminal, use Shift + PageDown. To go up or down in the terminal by line, use Ctrl + Shift + Up or Ctrl + Shift + Down respectively.

How do you repeat the last command in Bash?

Just press the Ctrl and P keys together to fill the prompt with the last executed command and you are ready to go. This method works in bash perfectly even after closing the terminal, but it might not work in zsh after closing the session.

Which Bash shortcut or command copies the last argument of previous commands?

I often use the Bash command yank-last-arg , shortcut M-. or Esc + . . This copies the last argument from the previous history entry into the current line at the current position, so you can check and edit the argument.


2 Answers

I've struggled with this same issue.

You can solve this by aborting with ctrl-c. Whether you're in the middle of a reverse search or scrolling through history with the arrows, aborting returns you to a prompt with the history scroll just after the last command.

UPDATE

Here's a nice trick I just learned. Bash and many other programs use Readline under the hood for command-line interpretation. Key bindings for Readline can be configured in a .inputrc file or with the bind command. The bindings can make use of a few functions provided by Readline. For example, I use Bash in vi mode but I still like to use Emacs-style ctrl-A so I have this line in my .bashrc file:

bind '\C-a:beginning-of-line'

To list all the available Readline functions: bind -l

Among the functions is end-of-history. The function does like its name suggests. The difference between this approach and just using the abort command is that this keeps you on the same prompt.

like image 192
Praxeolitic Avatar answered Oct 05 '22 23:10

Praxeolitic


If using libreadline, Alt-> (or Meta->). More info on Readline shortcuts or search for Commands for Manipulating the History in the man page.

like image 25
luis.parravicini Avatar answered Oct 05 '22 23:10

luis.parravicini