TranslateProject/sources/tech/20210907 How to Stop a Program in Linux Terminal.md
DarkSun 889dbd148d 选题[tech]: 20210907 How to Stop a Program in Linux Terminal
sources/tech/20210907 How to Stop a Program in Linux Terminal.md
2021-09-07 05:03:25 +08:00

4.7 KiB
Raw Blame History

How to Stop a Program in Linux Terminal

Its 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.

Thats 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.

Stopping a program in the Linux terminal

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. Thats 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 youll 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

本文由 LCTT 原创编译,Linux中国 荣誉推出