sources/tech/20210907 How to Stop a Program in Linux Terminal.md
4.7 KiB
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 to the running program to force quit the command.
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. 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 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.
How to exit Nano editor
Quitting the Nano editor 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.
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 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.
Recommended Read:
21 Super Handy Linux Command Tips and Tricks That Will Save you a lot of Time and Increase Your Productivity
Questions or suggestions? Please leave a comment below.
via: https://itsfoss.com/stop-program-linux-terminal/
作者:Abhishek Prakash 选题:lujun9972 译者:译者ID 校对:校对者ID