How to Stop a Program in Linux Terminal

It's amusing how the simplest of the things like stopping a running program could be overwhelming when you are new to the Linux command line.
Warp Terminal

It’s amusing how the simplest of 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, but it is also 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 designed to keep running until interrupted. You feel like you have to cancel the command, use Ctrl+C.

You can find the process ID and kill a running process in a more complicated method. 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, some other commands and command line tools 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 an excellent 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.

About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries πŸ•΅οΈβ€β™‚οΈ

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.