Navigating to the earliest/latest command in history when you're in the middle of your history

安稳与你 提交于 2019-12-31 08:41:52

问题


Say I am in a bash terminal and have a large history of commands. I pressed the up arrow a whole bunch of times and am in the "middle" of the history. I want to now navigate to the first or the last command in my history quickly (without holding down the up or the down arrow for a long time). Is this possible? If so, what is the shortcut key to achieving this?


回答1:


Take a look in the man page:

man bash

Here I copied for you the thing you were looking for:

previous-history (C-p)
    Fetch the previous command from the history list, moving back in the list.  
next-history (C-n)
    Fetch the next command from the history list, moving forward in the list.  
beginning-of-history (M-<)
    Move to the first line in the history.  
end-of-history (M->)
    Move to the end of the input history, i.e., the line currently being entered.



回答2:


Depending on how things are set up for your terminal, you can usually do a Ctrl+C to break you back to the beginning (no comment) and then go up once or twice to get to the recent command you want.

Alternatively, using the history command will list all the recent commands used with index values associated with them. !# where # is the index number will rerun that command. There's a nice usefulness of the command history | grep [command] to try and find a specific command in your history.



来源:https://stackoverflow.com/questions/3992074/navigating-to-the-earliest-latest-command-in-history-when-youre-in-the-middle-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!