bash 当您处于历史记录中间时导航到历史记录中最早/最新的命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3992074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Navigating to the earliest/latest command in history when you're in the middle of your history
提问by madiyaan damha
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?
假设我在 bash 终端中并且拥有大量命令历史。我按了很多次向上箭头,处于历史的“中间”。我现在想快速导航到历史记录中的第一个或最后一个命令(不要长时间按住向上或向下箭头)。这可能吗?如果是这样,实现这一目标的快捷键是什么?
回答by kokosing
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.
回答by Anthony
Depending on how things are set up for your terminal, you can usually do a Ctrl+Cto break you back to the beginning (no comment) and then go up once or twice to get to the recent command you want.
根据您的终端的设置方式,您通常可以执行Ctrl+C将您打断到开头(无评论),然后向上一两次以到达您想要的最近命令。
Alternatively, using the historycommand 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.
或者,使用该history命令将列出所有最近使用的命令以及与其关联的索引值。索引号!#在哪里#将重新运行该命令。该命令非常有用,history | grep [command]可以尝试在历史记录中查找特定命令。

