mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
commit
40a85ced26
@ -1,97 +0,0 @@
|
||||
[#]: subject: "How to Stop a Program in Linux Terminal"
|
||||
[#]: via: "https://itsfoss.com/stop-program-linux-terminal/"
|
||||
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
How to Stop a Program in Linux Terminal
|
||||
======
|
||||
|
||||
It’s amusing how the simplest of the things could be complicated when you are new to something.
|
||||
|
||||
The other day, I found my friend could not figure out how to exit the top command. Instead of stopping the command, he closed the entire terminal application.
|
||||
|
||||
That’s not only unnecessary, it is a not good thing to do.
|
||||
|
||||
### Stopping programs in Linux
|
||||
|
||||
In Linux, you can use the Ctrl+C keys to stop a running program in the terminal. This works for Ubuntu as well as any other Linux distribution.
|
||||
|
||||
Take the ping command for example. If you do not stop it, it will keep on displaying the result.
|
||||
|
||||
Hold the Ctrl button and press the C key at the same time. It sends the [SIGKILL signal][1] to the running program to force quit the command.
|
||||
|
||||
![Stopping a program in the Linux terminal][2]
|
||||
|
||||
Do you see the ^C? The caret (^) means Ctrl. So basically, the terminal shows the Ctrl+C keystrokes as ^C.
|
||||
|
||||
The Ctrl+C works very well for the commands that are designed to keep on running until interrupted. You feel like you have to cancel the command, use Ctrl+C.
|
||||
|
||||
In a more complicated method, you can [find the process ID and kill a running process][3]. That’s more advanced stuff and used only when the process is running in the background or by another user or in another terminal window.
|
||||
|
||||
Apart from that, there are some other commands and command line tools that have their own exit commands. Let me briefly mention some of them here.
|
||||
|
||||
#### How to exit Vim editor
|
||||
|
||||
[Existing Vim editor][4] has made so many jokes in the Linux world. It is difficult to figure out when you are new to this powerful command line based text editor. Among several ways of quitting vim, the most common is to press the Esc key and then type a colon (:) and then type `q!` for force quit without save or `wq` for save and quit.
|
||||
|
||||
![][5]
|
||||
|
||||
#### How to exit Nano editor
|
||||
|
||||
Quitting the [Nano editor][6] is a bit simpler than exiting Vim. Why? Because Nano mentions the shortcut at the bottom. You may not understand it if you are new to it but at least you’ll be able to figure it out the next time.
|
||||
|
||||
To exit Nano, press Ctrl+X. It will ask if you want to save the changes made to the file or not. You can enter your choice.
|
||||
|
||||
![][7]
|
||||
|
||||
#### How to exit less command
|
||||
|
||||
The less is a wonderful command that lets you view without cluttering your terminal screen like the cat command. If you are inside the less command view, use the key `q` to exit less.
|
||||
|
||||
#### How to exit the terminal
|
||||
|
||||
To exit the terminal itself, instead of closing the terminal, either use Ctrl+D keyboard shortcut or type the exit command:
|
||||
|
||||
```
|
||||
exit
|
||||
```
|
||||
|
||||
This actually exists you from the current shell. When you [open a terminal in Ubuntu][8] or any other Linux distribution, it runs the default shell. When you exit from this shell, terminal ends as well. Ctrl+D is the shortcut to do the same and quit the terminal.
|
||||
|
||||
I hope you find this quick tutorial helpful. I highly recommend learning these [Linux command tips][9].
|
||||
|
||||
**Recommended Read:**
|
||||
|
||||
![][10]
|
||||
|
||||
#### [21 Super Handy Linux Command Tips and Tricks That Will Save you a lot of Time and Increase Your Productivity][9]
|
||||
|
||||
Questions or suggestions? Please leave a comment below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/stop-program-linux-terminal/
|
||||
|
||||
作者:[Abhishek Prakash][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/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://linuxhandbook.com/sigterm-vs-sigkill/#what-is-sigkill
|
||||
[2]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/09/stop-a-program-linux-terminal.png?resize=800%2C373&ssl=1
|
||||
[3]: https://itsfoss.com/how-to-find-the-process-id-of-a-program-and-kill-it-quick-tip/
|
||||
[4]: https://itsfoss.com/how-to-exit-vim/
|
||||
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2017/05/how-to-exit-vim.png?resize=737%2C422&ssl=1
|
||||
[6]: https://itsfoss.com/nano-editor-guide/
|
||||
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/05/nano-editor-save-and-exit.png?resize=799%2C503&ssl=1
|
||||
[8]: https://itsfoss.com/open-terminal-ubuntu/
|
||||
[9]: https://itsfoss.com/linux-command-tricks/
|
||||
[10]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/07/linux-command-tips.png?fit=800%2C450&ssl=1
|
@ -0,0 +1,90 @@
|
||||
[#]: subject: "How to Stop a Program in Linux Terminal"
|
||||
[#]: via: "https://itsfoss.com/stop-program-linux-terminal/"
|
||||
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
如何在 Linux 终端中停止一个程序
|
||||
======
|
||||
|
||||
有趣的是,当你刚接触一些东西时,最简单的事情也会变得复杂。
|
||||
|
||||
有一天,我发现我的朋友搞不清楚如何退出 top 命令。他没有停止这个命令,而是关闭了整个终端程序。
|
||||
|
||||
这不仅是不必要的,而且是一件不好的事情。
|
||||
|
||||
### 在 Linux 中停止程序
|
||||
|
||||
在 Linux 中,你可以使用 Ctrl+C 键来停止终端中的运行程序。这对 Ubuntu 和其他 Linux 发行版都适用。
|
||||
|
||||
以 ping 命令为例。如果你不停止它,它将持续显示结果。
|
||||
|
||||
按住 Ctrl 键并同时按下 C 键。它向正在运行的程序发送 [SIGKILL 信号][1]以强制退出该命令。
|
||||
|
||||
![Stopping a program in the Linux terminal][2]
|
||||
|
||||
你看到 ^C 了吗?这个插入符号(^)代表 Ctrl。所以基本上,终端将 Ctrl+C 的按键显示为 ^C。
|
||||
|
||||
Ctrl+C 对于那些被设计为持续运行直到被打断的命令非常有效。你觉得你需要取消命令,就用 Ctrl+C。
|
||||
|
||||
在一个更复杂的方法中,你可以[找到进程 ID 并杀死一个正在运行的进程][3]。这是更高级的东西,只有进程在后台或由其他用户运行或在另一个终端窗口运行时使用。
|
||||
|
||||
除此以外,还有一些其他的命令和命令行工具也有自己的退出命令。让我在这里简单地提一下其中的一些。
|
||||
|
||||
#### 如何退出 Vim 编辑器
|
||||
|
||||
[退出 Vim 编辑器][4]在 Linux 世界里闹出了很多笑话。当你刚接触这个强大的基于命令行的文本编辑器时,是很难搞清楚的。在几种退出 vim 的方法中,最常见的是按 Esc 键,然后输入冒号(:),再输入 `q!` 表示不保存而强制退出,或者 `wq` 表示保存并退出。
|
||||
|
||||
![][5]
|
||||
|
||||
#### 如何退出 Nano 编辑器
|
||||
|
||||
退出 [Nano 编辑器][6]比退出 Vim 要简单一些。为什么?因为 Nano 在底部有快捷方式。如果你是新手,你可能不明白,但至少你下次就能搞清楚了。
|
||||
|
||||
要退出 Nano,按 Ctrl+X。它将询问你是否要保存对文件所做的修改。你可以输入你的选择。
|
||||
|
||||
![][7]
|
||||
|
||||
#### 如何退出 less 命令
|
||||
|
||||
less 是一个奇妙的命令,它可以让你在不像 cat 命令那样杂乱的终端屏幕上进行查看。如果你在 less 命令的视图内,使用 `q` 键来退出 less。
|
||||
|
||||
#### 如何退出终端
|
||||
|
||||
要退出终端本身,不是关闭终端,而是使用 Ctrl+D 键盘快捷键或输入退出命令:
|
||||
|
||||
```
|
||||
exit
|
||||
```
|
||||
|
||||
这实际上是让你从当前的 shell 中退出。当你[在 Ubuntu 或其他发行版中打开一个终端][8],它会运行默认的 shell。当你从这个 shell 退出时,终端也会结束。Ctrl+D 是做同样事情的快捷方式,并退出终端。
|
||||
|
||||
我希望你觉得这个快速教程对你有帮助。我强烈建议你学习这些 [Linux 命令技巧][9]。
|
||||
|
||||
有问题或建议?请在下面留下评论。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/stop-program-linux-terminal/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://linuxhandbook.com/sigterm-vs-sigkill/#what-is-sigkill
|
||||
[2]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/09/stop-a-program-linux-terminal.png?resize=800%2C373&ssl=1
|
||||
[3]: https://itsfoss.com/how-to-find-the-process-id-of-a-program-and-kill-it-quick-tip/
|
||||
[4]: https://itsfoss.com/how-to-exit-vim/
|
||||
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2017/05/how-to-exit-vim.png?resize=737%2C422&ssl=1
|
||||
[6]: https://itsfoss.com/nano-editor-guide/
|
||||
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/05/nano-editor-save-and-exit.png?resize=799%2C503&ssl=1
|
||||
[8]: https://itsfoss.com/open-terminal-ubuntu/
|
||||
[9]: https://itsfoss.com/linux-command-tricks/
|
Loading…
Reference in New Issue
Block a user