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.

stop a program linux terminal
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. 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 Vim editor in Linux

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.

Save and Exit Nano editor

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:


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.

.ugb-a4f08a0-wrapper.ugb-container__wrapper{border-radius:0px !important;padding-top:0 !important;padding-bottom:0 !important;background-color:#f1f1f1 !important}.ugb-a4f08a0-wrapper > .ugb-container__side{padding-top:35px !important;padding-bottom:35px !important}.ugb-a4f08a0-wrapper.ugb-container__wrapper:before{background-color:#f1f1f1 !important}.ugb-a4f08a0-content-wrapper > h1,.ugb-a4f08a0-content-wrapper > h2,.ugb-a4f08a0-content-wrapper > h3,.ugb-a4f08a0-content-wrapper > h4,.ugb-a4f08a0-content-wrapper > h5,.ugb-a4f08a0-content-wrapper > h6{color:#222222}.ugb-a4f08a0-content-wrapper > p,.ugb-a4f08a0-content-wrapper > ol li,.ugb-a4f08a0-content-wrapper > ul li{color:#222222}

Recommended Read:

.ugb-921b5c0 .ugb-blog-posts__featured-image{border-radius:0px !important}.ugb-921b5c0 .ugb-blog-posts__title a{color:#000000 !important}.ugb-921b5c0 .ugb-blog-posts__title a:hover{color:#00b6ba !important}

Questions or suggestions? Please leave a comment below.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.