From c395880ee61b315931b84248f2f557ba184bbdf3 Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Tue, 26 Sep 2023 15:41:57 +0800 Subject: [PATCH] ATRP @wxy https://linux.cn/article-16228-1.html --- ...l Shortcuts Pro Linux Users Love to Use.md | 328 ++++++++++++++++ ...l Shortcuts Pro Linux Users Love to Use.md | 356 ------------------ 2 files changed, 328 insertions(+), 356 deletions(-) create mode 100644 published/20230925 21 Useful Terminal Shortcuts Pro Linux Users Love to Use.md delete mode 100644 sources/tech/20230925 21 Useful Terminal Shortcuts Pro Linux Users Love to Use.md diff --git a/published/20230925 21 Useful Terminal Shortcuts Pro Linux Users Love to Use.md b/published/20230925 21 Useful Terminal Shortcuts Pro Linux Users Love to Use.md new file mode 100644 index 0000000000..678ae88ae0 --- /dev/null +++ b/published/20230925 21 Useful Terminal Shortcuts Pro Linux Users Love to Use.md @@ -0,0 +1,328 @@ +[#]: subject: "21 Useful Terminal Shortcuts Pro Linux Users Love to Use" +[#]: via: "https://itsfoss.com/linux-terminal-shortcuts/" +[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/" +[#]: collector: "lujun9972/lctt-scripts-1693450080" +[#]: translator: "ChatGPT" +[#]: reviewer: "wxy" +[#]: publisher: "wxy" +[#]: url: "https://linux.cn/article-16228-1.html" + +21 个专业 Linux 用户喜爱的实用终端快捷键 +====== + +![][0] + +> 掌握这些极致实用的快捷键,让你的 Linux 终端操作效率大幅提升。 + +学习 Linux 命令无疑是你的首要任务,但当你能熟练 [运用命令行][1] 之后,有另一样东西值得你去关注。 + +**那就是终端快捷键!** + +如果你不知道如何利用它们提升终端会话的效率,那你就无法真正理解它们的重要性。 + +在本教程中,我将为你详细讲解顶级的终端快捷键,并且举例说明它们的用法。 + +在我逐一解释快捷键之前,先来看一下这个备忘录,它对我将在本教程中讨论的内容进行了概览: + +快捷键 | 功能描述 +---|--- +`Ctrl + A` | 光标快速跳至行首。 +`Ctrl + E` | 光标快速跳至行尾。 +`Ctrl + U` | 删除光标至行首的所有内容。 +`Ctrl + K` | 删除光标至行尾的所有内容。 +`Ctrl + W` | 删除光标前的一个单词。 +`Ctrl + L` | 清空整个终端屏幕。 +`Ctrl + C` | 停止正在执行的进程或命令。 +`Ctrl + D` | 注销或退出终端。 +`Ctrl + Z` | 暂停正在执行的进程(之后可恢复执行)。 +`Ctrl + R` | 在命令历史中进行逆向搜索。 +上箭头 `↑` | 从命令历史中显示先前的命令。 +下箭头 `↓` | 从命令历史中显示后续的命令。 +`!!` | 重复执行最近的命令。 +`!n` | 重复执行命令历史中的第 n 条命令。 +`Tab` | 自动补全命令,文件名或目录名。 +连续按 `Tab` 两次 | 列出所有可能的补全选项。 +`Ctrl + Shift + C` | 复制所选文本或命令。 +`Ctrl + Shift + V` | 粘贴已复制的文本或命令。 +`Ctrl + Shift + N` | 打开新的终端窗口。 +`Ctrl + Shift + T` | 在当前终端中打开新的选项卡。 +`Ctrl + Tab` 或 `Ctrl + PageDown` | 在终端的选项卡之间切换。 + +> 📋 虽然我在这篇文章中用的是大写字母,但实际上我们不需要使用大写来输入它们。比如 `Ctrl+A`,意思是同时按下 `Ctrl` 键和 `A` 键,并不意味着需要同时按下 `Shift` 键和 `a` 键来输入大写的 `A`。 + +接下来,我们更详细地看看这些快捷键如何使用。 + +### 1、Ctrl + A:光标切换至行首 + +当你在终端中按下 `Ctrl + A` 组合键,光标就会迅速跳到命令的起始处。这个功能在你需要修改一条长命令序列起始部分的时候十分实用。 + +例如,在以下示例中,你可以看到无论光标处在何位置,只需按下 `Ctrl + A`,光标就会立刻跳转至行首: + +![使用 Ctrl + A 快捷键在 Linux 终端内前往行首][2] + +### 2、Ctrl + E:光标切换至行尾 + +在使用终端的过程中,如果你想迅速跳到当前行的末尾,直接按下 `Ctrl + E` 组合键就可以了。 + +在下面的示例中,我使用了一段样本文本,并按下 `Ctrl + E` 来快速移动到行尾: + +![使用 Ctrl + E 在 linux 终端内前往行尾][3] + +### 3、Ctrl + U:删除光标位置至行首的内容 + +有些时候,你可能需要删除从光标位置到行首的所有内容。 + +此时,你只需使用左箭头键将光标移动至你想要开始删除的位置,然后按下 `Ctrl + U` : + +![使用 Ctrl+U 从光标位置删除到行首的内容][4] + +> 💡 在输完 `sudo` 命令输入密码时,不确定是否输入正确?没必要用退格键一路删除,只需简单地使用 `Ctrl+U` 快捷键重新开始输入密码即可。 + +### 4、Ctrl + K:从光标删除至行尾 + +如你所猜想,当你按下 `Ctrl + K` ,它会移除光标至行尾的所有内容(光标位置右侧的所有)。 + +使用这种快捷操作时,你先要把光标放在你想从那里开始删除的位置,然后按下 `Ctrl + K`,如下图展示的那样: + +![在 Linux 终端利用 Ctrl + K 删除光标至行尾的内容][5] + +### 5、Ctrl + W:删除光标前的一个词 + +我日常常用该快捷键,因为我时常打错命令,需要删除命令的一部分,这个时候只需要简单地按 `Ctrl + W` 就可以了。 + +当你按下 `Ctrl + W` 键时,它只会删除光标前的一个词: + +![在 Linux 终端通过按 Ctrl + W 删除光标前的一个词][6] + +### 6、Ctrl + L:清理终端显示(或者理解为整理显示内容) + +按下 `Ctrl + L` 并不会彻底地 [清空终端显示][8],但它可以整理显示内容。如果你向上滚动,你还能找到之前的命令和执行记录。 + +它与 `clear` 命令有所不同。`clear` 命令会消除历史记录,而且你会在命令历史中找到 `clear` 命令的执行。 + +但是当你按下 `Ctrl + L` 时,它只是整理当前屏幕的显示内容,并不会出现在历史记录中,因为它本身并不是一条命令。 + +比如在这个示例中,我执行了历史命令,随后按下 `Ctrl + L` 键进行了屏幕清理: + +![利用 Ctrl+L 清理 Linux 终端屏幕显示][9] + +### 7、Ctrl + C:终止当前进程/执行 + +有没有想要 [停止进行中的命令][10],却不知所措,最后只好关闭终端呢?解决办法其实很简单,按下 `Ctrl + C` 就行了。 + +当你按下这一组键时,它将发送 `SIGINT` 信号以终别过程。 + +例如,在这里,我结束了正在执行的命令进程: + +![利用 Ctrl+C 终端快捷键来中止运行中的命令][11] + +最后,你会看到 `^C` 符号,表示你按下了 `Ctrl + C` 来中止当前执行。 + +但是,有些进程可能不会被 `Ctrl + C` 信号所中止,此时,你可以使用 Linux 中的其他 [中止信号][12] 来终止。 + +> **[如何在 Linux 中使用 SIGINT 和其它中止信号][12]** + +### 8、Ctrl + D:退出登录或者退出终端 + +你总是可以使用 `exit` 命令来关闭 Shell 会话和终端。你也可以选择使用 `Ctrl+D` 快捷键。 + +当你按 `Ctrl + D` 时,如果你正在 SSH 中使用,它会结束会话,如果再次按下,它将直接关闭终端: + +![利用 Ctrl+D 来关闭会话][14] + +### 9、Ctrl + Z:暂停当前进程 + +总是杀掉命令并不是个好主意,因为你有可能需要重新启动过程。 + +这种情况下,你可以按 `Ctrl + Z` 来暂停当前的进程,然后可以从之前暂停的地方继续。 + +例如,在这里,我暂停了更新进程: + +![利用 Ctrl+Z 挂起一个进程][15] + +你想更多地了解 [如何暂停命令及如何恢复它们][16] 吗?这里有一篇为此准备的详细指南: + +> **[如何在 Linux 中暂停并稍后恢复一个进程][13]** + +### 10、Ctrl + R:搜索命令历史 + +当你按 `Ctrl + R` 时,它会打开一个搜索模式的提示,从中你可以键入命令的任何部分,并将找到匹配你输入的字符串的命令。 + +一旦你找到那个命令,只需按 `Enter` 键,它就会执行那个命令。 + +例如,在这里,我搜索了 `update`,返回的结果是在 Ubuntu 中的仓库更新命令(`sudo apt update`): + +![利用 Ctrl + R 快捷键从历史记录中搜索命令][17] + +> 📋 如果你对历史记录中的任何建议都不满意,可以使用 `Ctrl+C` 退出搜索模式。 + +### 11、上箭头:呈现命令历史中的上一条 + +当你按下上箭头 `↑` 键时,命令历史中之前执行过的命令将会按次序逐一显示: + +![使用箭头键向下遍历历史记录][18] + +### 12、下箭头:呈现命令历史中的下一条 + +当你按下上箭头 `↑` 键时,它会展示先前的命令,但在有些情况下,你可能无意间点击了多次,这时你希望展示之前已显示过的命令。 + +这个时候,你可以使用下箭头 `↓` 键。 + +在以下图示中,我首先多次按下了上箭头键,然后为了返回到先前显示的命令,我按下了下箭头键: + +![使用箭头键向下遍历历史记录][19] + +> 📋 `Page Up` 和 `Page Down` 键也可以用于同样的目的。 + +### 13、!!:重复最后一条命令 + +有时候,你可能需要重复执行一次或多次最近的命令,此时你只需要输入 `!!`(两个感叹号)即可: + +``` +!! +``` + +比如,在这里,我执行了一个 `echo` 命令,随后我用了 `!!` 来重复执行相同的命令: + +![!! 命令能够重复执行你最近在终端输入的命令][20] + +但是,这个快捷键最常用且最实用的场景是,当你忘记给命令加上 `sudo`。这样你无需重新输入整个命令,只需使用 `sudo !!` 就可以了 + +![在 Linux 终端中使用 !! 快捷键的实践应用][21] + +> 💡 一个类似的键盘快捷键是 `Alt+.`,这个快捷键会给你提供上一条命令的最后一个参数或部分。假设你刚使用了 `ls /etc/apt/sources.list.d`,现在你想进入这个目录。只需输入 `cd` 然后使用 `Alt+.` 就可以。这就如同你输入 `cd /etc/apt/sources.list.d` 一样。 + +### 14、!n:重播历史中的第 n 条命令 + +你可以通过执行 Bash 的 `history` 命令来查看命令历史,每个命令都会有一个相应的索引号: + +``` +history +``` + +![从历史中选择命令][22] + +现在,假设我想要执行倒数第二个 `echo` 命令,我会这样使用: + +``` +!1998 +``` + +![][23] + +### 15、Tab:命令自动补全 + +我认为这应是终端快捷键列表的首个条目。 + +在输入长命令时,你可以输入一部分,然后点击 `Tab` 键,它将为你进行自动补全。 + +例如,这里,我通过 `Tab` 键来自动完成我的脚本执行: + +![点击 Tab 来查看命令,选项与参数建议][24] + +### 16、Tab(连击两次):列出所有可能的自动补全 + +如果按 `Tab` 键无效果,那可能是因为当前输入的命令存在多种可能。 + +在这种场合,你可以连击两次 `Tab` 键,以列出所有可能的补全选项: + +![连击两次 Tab 键可列出所有可能的自动补全建议][25] + +> ✋ 接下来的一些快捷键取决于终端的模拟器。虽然这些快捷键应该适用于大多数的终端应用,但不能完全确定。 + +### 17、Ctrl + Shift + C:复制所选文本 + +[复制终端中的文本][26],你需要先用鼠标选取文本,然后按下 `Ctrl + Shift + C` 来复制选中的内容: + +![按下 Ctrl+Shift+C 进行复制][27] + +### 18、Ctrl + Shift + V:粘贴已复制的文本 + +当你通过选取和按下 `Ctrl + Shift + C` 复制了文本后,你可以通过按下 `Ctrl + Shift + V` 在任何地方粘贴: + +![在终端按下 Ctrl+Shift+V 进行粘贴][28] + +### 19、Ctrl + Shift + N:打开新的终端窗口 + +当你按下 `Ctrl + Shift + N` 时,会打开一个新的终端窗口,且新窗口的工作目录与之前那个窗口内的工作目录相同: + +![][28A] + +### 20、Ctrl + Shift + T:开启新的终端标签页 + +就像使用网络浏览器一样,终端也支持开启多个标签页来进行不同的任务。要开启一个新的标签页,只需按下 `Ctrl + Shift + T` 就可以了: + +![][29] + +### 21、Ctrl + Tab 或 Ctrl + PageDown:切换标签页 + +如果你按照之前的方式创建了多个标签页,你或许需要在它们之间进行切换。 + +为此,你可以使用 `Ctrl + Tab` 或 `Ctrl + PageDown`: + +![][30] + +> 💡 这可能更多是 Ubuntu 的功能。你可以通过 [按下 Ctrl+Alt+T 键来打开新的终端窗口][31]。 + +### 接下来:必知的 Linux 命令 + +你喜欢这个“必备”键盘快捷键列表吗?可能你会对 [最基本却必备的 Linux 命令列表][34] 也感兴趣: + +> **[31 个最基本却必备的 Ubuntu Linux 命令][34]** + +我明白起初你可能不容易记住所有这些终端快捷键。但通过不断实践,它们会逐渐深入你的肌肉记忆。 + +另外,你有一些没有在这里列出的钟爱的快捷键吗?欢迎在评论区分享。 + +*(题图:MJ/992e3559-4ed7-4529-9aea-85d52484cccf)* + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/linux-terminal-shortcuts/ + +作者:[Sagar Sharma][a] +选题:[lujun9972][b] +译者:[ChatGPT](https://linux.cn/lctt/ChatGPT) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/sagar/ +[b]: https://github.com/lujun9972 +[1]: https://itsfoss.com/linux-terminal-basics/ +[2]: https://itsfoss.com/content/images/2023/09/Ctrl-A.svg +[3]: https://itsfoss.com/content/images/2023/09/Ctrl-E.svg +[4]: https://itsfoss.com/content/images/2023/09/Ctrl-U.svg +[5]: https://itsfoss.com/content/images/2023/09/Ctrl-K.svg +[6]: https://itsfoss.com/content/images/2023/09/Ctrl-W.svg +[7]: https://public-files.gumroad.com/akcz661m3xkpsztskivjmh2agj22 +[8]: https://itsfoss.com/clear-terminal-ubuntu/ +[9]: https://itsfoss.com/content/images/2023/09/Ctrl-L.svg +[10]: https://itsfoss.com/stop-program-linux-terminal/ +[11]: https://itsfoss.com/content/images/2023/09/Ctrl-C.svg +[12]: https://linuxhandbook.com/termination-signals/ +[13]: https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png +[14]: https://itsfoss.com/content/images/2023/09/exit-from-the-ssh-session-and-close-the-terminal-using-shortcut.gif +[15]: https://itsfoss.com/content/images/2023/09/stop-ongoing-process-in-Linux-terminal.gif +[16]: https://linuxhandbook.com/suspend-resume-process/ +[17]: https://itsfoss.com/content/images/2023/09/Ctrl-R.svg +[18]: https://itsfoss.com/content/images/2023/09/Up_arrow.svg +[19]: https://itsfoss.com/content/images/2023/09/Down_arrow.svg +[20]: https://itsfoss.com/content/images/2023/09/Use----to-exccute-the-most-recent-command.png +[21]: https://itsfoss.com/content/images/2023/09/using---terminal-shortcut.png +[22]: https://itsfoss.com/content/images/2023/09/Use-the-history-command-to-find-previously-executed-commands.png +[23]: https://itsfoss.com/content/images/2023/09/Use-the--n-shortcut-to-execute-any-command-from-the-command-history-in-Linux-terminal.png +[24]: https://itsfoss.com/content/images/2023/09/Tab.svg +[25]: https://itsfoss.com/content/images/2023/09/Tab_twice.svg +[26]: https://itsfoss.com/copy-paste-linux-terminal/ +[27]: https://itsfoss.com/content/images/2023/09/Copy-text-in-Linux-terminal.gif +[28]: https://itsfoss.com/content/images/2023/09/Paste-text-in-terminal.gif +[28A]: https://itsfoss.com/content/media/2023/09/Open-new-terminal-window.webm +[29]: https://itsfoss.com/content/images/2023/09/Open-new-tab-in-Linux-terminal.gif +[30]: https://itsfoss.com/content/images/2023/09/Switch-between-tabs-in-Linux-terminal.gif +[31]: https://itsfoss.com/open-terminal-ubuntu/ +[32]: https://itsfoss.com/content/images/2023/04/efficient-at-linux-command-line-horizontal.png +[33]: https://amzn.to/3MPjiHw +[34]: https://itsfoss.com/essential-ubuntu-commands/ +[35]: https://itsfoss.com/content/images/size/w256h256/2022/12/android-chrome-192x192.png +[0]: https://img.linux.net.cn/data/attachment/album/202309/26/153948umngxcj8pemmejfe.jpg \ No newline at end of file diff --git a/sources/tech/20230925 21 Useful Terminal Shortcuts Pro Linux Users Love to Use.md b/sources/tech/20230925 21 Useful Terminal Shortcuts Pro Linux Users Love to Use.md deleted file mode 100644 index 4b339544f0..0000000000 --- a/sources/tech/20230925 21 Useful Terminal Shortcuts Pro Linux Users Love to Use.md +++ /dev/null @@ -1,356 +0,0 @@ -[#]: subject: "21 Useful Terminal Shortcuts Pro Linux Users Love to Use" -[#]: via: "https://itsfoss.com/linux-terminal-shortcuts/" -[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/" -[#]: collector: "lujun9972/lctt-scripts-1693450080" -[#]: translator: " " -[#]: reviewer: " " -[#]: publisher: " " -[#]: url: " " - -21 Useful Terminal Shortcuts Pro Linux Users Love to Use -====== - -Sure, learning the Linux commands should always be your priority but once you [get a grip on the command line][1], there's one other thing you should focus on. - -_**Terminal shortcuts!**_ - -You have no idea how helpful they are until you know how to use them to make your terminal sessions super productive. - -So in this tutorial, I will walk you through the top terminal shortcuts with examples of how to use them. - -Before I explain all the shortcuts individually, here's a cheat sheet of what I'll be discussing in this tutorial: - -Shortcut | Description ----|--- -`Ctrl + A` | Move to the start of the line. -`Ctrl + E` | Move to the end of the line. -`Ctrl + U` | Delete from the cursor to the start of the line. -`Ctrl + K` | Delete from the cursor to the end of the line. -`Ctrl + W` | Delete the word before the cursor. -`Ctrl + L` | Clear the terminal screen. -`Ctrl + C` | Stop the current process/command. -`Ctrl + D` | Log out or exit the terminal. -`Ctrl + Z` | Pause the current process (can be resumed). -`Ctrl + R` | Search command history (backward search). -`Up Arrow` | Show the previous command (from the command history). -`Down Arrow` | Show the next command (from the command history). -`!!` | Repeat the last command. -`!n` | Repeat the nth command from history. -`Tab` | Auto-complete commands, files, or directories. -`Tab` twice | List all possible completions. -`Ctrl + Shift + C` | Copy the selected text or command. -`Ctrl + Shift + V` | Paste copied text or command. -`Ctrl + Shift + N` | Open a new terminal window. -`Ctrl + Shift + T` | Open a new tab in the terminal. -`Ctrl + Tab`or`Ctrl + PageDown` | Switch between terminal tabs. - -📋 - -Though I have used the capital letters, you don't have to type them in caps. I mean Ctrl+A means pressing Ctrl and the A key together. You don't have to press Shift+a key to get the uppercase A. - -Now, let's have a look at them individually. - -### 1\. Ctrl + A: Move to the start of the line - -When you press the `Ctrl + A`, it will shift the cursor to the beginning of the file which can be really helpful when you write a long command and want to make changes at the beginning of the line. - -For example. here, I've demonstrated how you can press the `Ctrl + A` anywhere and it will shift you to the beginning of the line: - -![Go to the beginning of the line in Linux terminal using Ctrl + A shortcut][2] - -### 2\. Ctrl + E: Move to the end of the line - -While using the terminal if you want to jump to the end of the line, you can simply press the `Ctrl + E` and it will do the job. - -In the following example, I used a sample text and pressed `Ctrl + E` to get to the end of the line: - -![Go to the end of the line in linux terminal using Ctrl + E][3] - -### 3\. Ctrl + U: Delete from the cursor to start - -There are times when you want to remove everything from the cursor position to the beginning of the line. - -In that case, all you have to do is use the left arrow keys to place the cursor from where you would like to delete to the start of the line and then press `Ctrl + U` : - -![Use Ctrl+U to delete from the cursor to the beginning of the line][4] - -💡 - -Entering the account password with sudo command and unsure whether you typed it correctly? Instead of pressing backspace all the way, just use Ctrl+U keyboard shortcut and start typing the password again. - -### 4\. **Ctrl + K:** Delete from the cursor to the end - -As you can guess from the title, when you press the `Ctrl + K`, it will remove everything from the cursor to the end of the line (everything from the cursor position to the right-hand side). - -To use this shortcut, first, you have to place your cursor from where you want to remove text to the end and then press the `Ctrl + K` as shown here: - -![Delete text from the cursor to the end in Linux terminal using Ctrl + K][5] - -### 5\. **Ctrl + W:** Delete a single word before the cursor - -This is what I use daily as I often mistype commands and want to remove one part of the command for that, you can simply press the `Ctrl + W` . - -When you press the `Ctrl + W` key, it will only remove a single word before the cursor: - -![Delete single word before the cursor in Linux terminal by pressing Ctrl + W][6] - -![][7] - -### 6\. **Ctrl + L:** Clear terminal screen (kind of) - -It does not [clear the terminal screen][8] in a true manner but declutters the screen and if you scroll up, you will still find the previous command and execution history. - -Yes, it is different than the `clear` command as it removes the history and you will find the execution of the `clear` command in the command history. - -But when you press `Ctrl + L`, it just declutters your current screen and you won't find it inside of the history (as it is not a command itself). - -For example, here, I executed the history command and then pressed the `Ctrl + L` key to clear the screen: - -![clear terminal screen in Linux using Ctrl+L][9] - -### 7\. **Ctrl +C:** Stop the current process/execution - -How many times did it happen when you wanted to [stop the command execution][10] and you had no idea how to do it and ended up closing the terminal itself? - -Well, in any case, all you have to do is press `Ctrl + C`. - -When you press the keys, it sends the `SIGINT` signal that will eventually kill the process. - -For example, here, I killed the ongoing point command execution: - -![Use Ctrl+C terminal shortcut to stop a running command][11] - -In the end, you'll see the `^C` symbol indicating you pressed the `Ctrl + C` to kill the ongoing execution. - -But there are several processes that may not be killed using the `Ctrl + C` signal and in that case, you can use the other [termination signals in Linux][12]: - -![][13] - -### 8\. **Ctrl + D:** Logout or exit from the terminal - -You can always use the exit command to close a shell session and terminal. You can also use the Ctrl+D shortcut keys as well. - -When you press the `Ctrl + D`, it will log you out from the ongoing session if you use it in SSH, it will close the session and if pressed again, it will close the terminal itself: - -![Use Ctrl+D to close a session][14] - -### 9\. **Ctrl + Z:** Pause the current process - -Killing an ongoing process is not a good idea always as you have to start over again. - -So in that case, what you can do is press `Ctrl + Z` to stop the ongoing process and later on can be continued from where it was left. - -For example, here, I stopped the update process: - -![Use Ctrl+Z to suspend a process][15] - -Want to know more ways to [stop ongoing processes and how to resume them][16]? Here's a detailed guide for that purpose: - -![][13] - -### 10\. **Ctrl + R:** Search command history - -When you press `Ctrl + R`, it opens a search mode prompt from where you can type any part of the command and it will find you the command with matching string you've entered. - -Once you find that command, you simply press the `Enter` key and it will execute that command. - -For example, here, I searched for the `update` and it gave me the command to update the repository in Ubuntu (sudo apt update): - -![Search commands from history using the shortcut Ctrl + R][17] - -📋 - -If you don't like any of the suggestions from the history, use Ctrl+C to come out of the search mode. - -### 11\. Up Arrow: Show the previous command from history - -When you press the `Up Arrow` key, it will show you previously executed commands one by one from the command history: - -![Navigating down the history using arrow key][18] - -### 12\. Down Arrow: Show the next command from history - -When you press the `Up Arrow` key, it shows you previous commands but there are times when you accidentally press it many times and now you want to show the previously shown command. - -In that case, you can use the `Down Arrow` key. - -In the following illustration, first I pressed the up arrow key multiple times, and then to come back to previously shown commands, I pressed the down arrow key: - -![Navigating down the history using arrow key][19] - -📋 - -Page Up and Page Down keys are also use for the same purpose. - -### 13\. !!: Repeat the last command - -There are times when you want to execute the most recent command one or more times and in that case, you can simply type `!!` (exclamation twice): - -``` - - !! - -``` - -For example, here, I executed an echo command and then used the `!!` twice to use the same command again and again: - -![The !! repeats what you entered in the terminal previously][20] - -But the most common and useful execution of this shortcut is when you forget to use sudo with a command. Instead of writing the entire command again, you just use `sudo !!` - -![Practical use of the !! keyboard shortcuts in Linux terminal][21] - -💡 - -A similar keyboard shortcut is Alt+.. This one gives you the last argument/part of the last command. Say, you used ls /etc/apt/sources.list.d previously and now you want to enter this directory. Just type cd and use Alt+.. It will be like typing cd /etc/apt/sources.list.d - -### 14\. !n: Repeat the nth command from history - -You can access the history of executed commands by simply executing the bash history command in the terminal and each will have an index number associated with it: - -``` - - history - -``` - -![Select commands from the history][22] - -Now, let's suppose I want to execute the 2nd last echo command, then I will be using the following: - -``` - - !1998 - -``` - -![][23] - -### 15\. Tab: Auto-complete the command - -I think I should have started the terminal shortcuts list with this one. - -While typing a long command, you can type half of it and then press the `Tab` key and it will auto-complete for you. - -For example, here, I pressed the `Tab` key to auto-complete my script execution: - -![Press tab to see command, options and argument suggestions][24] - -### 16\. Tab (twice): List all the possible auto-completes - -If pressing the `Tab` key does not work, it means there are multiple possibilities of the currently typed command. - -In that case, what you can do is press the `Tab` key twice to list all the possibilities: - -![Press tab twice to list all possible auto complete suggestions][25] - -✋ - -The next few shortcuts are terminal emulator dependent. They should work with most terminal applications but that's not a surety. - -### 17\. Ctrl + Shift + C: Copy the selected text - -[To copy the text in the terminal][26], you have to select the text using the mouse and then press the `Ctrl + Shift + C` to copy the selected text: - -![Press Ctrl+Shift+C to copy text][27] - -### 18\. Ctrl + Shift + V: Paste the copied text - -Once you copy the text by selecting the text and pressing `Ctrl + Shift + C`, now you can paste it anywhere by pressing `Ctrl + Shift + V` : - -![Press Ctrl+Shift+V to paste text in terminal][28] - -### 19\. Ctrl + Shift + N: Open a new terminal window - -When you press the `Ctrl + Shift + N`, it will open a new terminal window with the same working directory you were working in the previous window: - -0:00 - -/0:03 - -1× - -### 20\. Ctrl + Shift + T: Open new tab - -Like web browsers, in the terminal, you can open tabs to separate different tasks. To open a new tab, all you have to do is press `Ctrl + Shift + T` : - -![][29] - -### 21\. Ctrl + Tab or Ctrl + PageDown: Switch tabs - -If you created multiple tabs using the above method, you may want to switch between them. - -And for that purpose, you can use `Ctrl + Tab` or `Ctrl + PageDown`: - -![][30] - -💡 - -This is more likely an Ubuntu thing. [Press Ctrl+Alt+T keys to open a new terminal][31]. - -![][32] - -##### New Book: Efficient Linux at the Command Line - -Pretty amazing Linux book with lots of practical tips. It fills in the gap, even for experienced Linux users. Must have in your collection. - -[Get it from Amazon][33] - -### Next: Must-know Linux commands - -Liked this list of 'essential' keyboard shortcuts? Perhaps you would like this list of the [most basic yet essential Linux commands:][34] - -![][35] - -I understand that you may not remember all of these terminals shortcuts, at least not initially. But practice them and gradually they will be in your muscle memory. - -By the way, do you have some of your favourite shortcuts that have not been included here? Share it in the comments? - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/linux-terminal-shortcuts/ - -作者:[Sagar Sharma][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://itsfoss.com/author/sagar/ -[b]: https://github.com/lujun9972 -[1]: https://itsfoss.com/linux-terminal-basics/ -[2]: https://itsfoss.com/content/images/2023/09/Ctrl-A.svg -[3]: https://itsfoss.com/content/images/2023/09/Ctrl-E.svg -[4]: https://itsfoss.com/content/images/2023/09/Ctrl-U.svg -[5]: https://itsfoss.com/content/images/2023/09/Ctrl-K.svg -[6]: https://itsfoss.com/content/images/2023/09/Ctrl-W.svg -[7]: https://public-files.gumroad.com/akcz661m3xkpsztskivjmh2agj22 -[8]: https://itsfoss.com/clear-terminal-ubuntu/ -[9]: https://itsfoss.com/content/images/2023/09/Ctrl-L.svg -[10]: https://itsfoss.com/stop-program-linux-terminal/ -[11]: https://itsfoss.com/content/images/2023/09/Ctrl-C.svg -[12]: https://linuxhandbook.com/termination-signals/ -[13]: https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png -[14]: https://itsfoss.com/content/images/2023/09/exit-from-the-ssh-session-and-close-the-terminal-using-shortcut.gif -[15]: https://itsfoss.com/content/images/2023/09/stop-ongoing-process-in-Linux-terminal.gif -[16]: https://linuxhandbook.com/suspend-resume-process/ -[17]: https://itsfoss.com/content/images/2023/09/Ctrl-R.svg -[18]: https://itsfoss.com/content/images/2023/09/Up_arrow.svg -[19]: https://itsfoss.com/content/images/2023/09/Down_arrow.svg -[20]: https://itsfoss.com/content/images/2023/09/Use----to-exccute-the-most-recent-command.png -[21]: https://itsfoss.com/content/images/2023/09/using---terminal-shortcut.png -[22]: https://itsfoss.com/content/images/2023/09/Use-the-history-command-to-find-previously-executed-commands.png -[23]: https://itsfoss.com/content/images/2023/09/Use-the--n-shortcut-to-execute-any-command-from-the-command-history-in-Linux-terminal.png -[24]: https://itsfoss.com/content/images/2023/09/Tab.svg -[25]: https://itsfoss.com/content/images/2023/09/Tab_twice.svg -[26]: https://itsfoss.com/copy-paste-linux-terminal/ -[27]: https://itsfoss.com/content/images/2023/09/Copy-text-in-Linux-terminal.gif -[28]: https://itsfoss.com/content/images/2023/09/Paste-text-in-terminal.gif -[29]: https://itsfoss.com/content/images/2023/09/Open-new-tab-in-Linux-terminal.gif -[30]: https://itsfoss.com/content/images/2023/09/Switch-between-tabs-in-Linux-terminal.gif -[31]: https://itsfoss.com/open-terminal-ubuntu/ -[32]: https://itsfoss.com/content/images/2023/04/efficient-at-linux-command-line-horizontal.png -[33]: https://amzn.to/3MPjiHw -[34]: https://itsfoss.com/essential-ubuntu-commands/ -[35]: https://itsfoss.com/content/images/size/w256h256/2022/12/android-chrome-192x192.png