53

I've been stopping commands with the trash can for too long. Command period doesn't work on Mac. I can't find anywhere how to stop the terminal via a command. What is it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
faceyspacey.com
  • 2,510
  • 2
  • 20
  • 29

14 Answers14

97

You can terminate with the Trash icon like you do, or press Ctrl + C. That's the shortcut from the default Terminal application and it also works in Visual Studio Code.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
PetarS
  • 1,213
  • 9
  • 4
  • 6
    thats crazy. i had done command C in the past, and totally missed that it was control lol – faceyspacey.com Aug 17 '17 at 16:11
  • 1
    Cmd + c is obvious, but it doesn't work. Nothing happens. I am using karabiner app, so... maybe this is the reason?.. – John Smith Oct 28 '19 at 21:01
  • @JohnSmith same with me. did you find any solution? – Mehul Parmar Nov 10 '21 at 16:41
  • @MehulParmar, unfortunately, no. Just close/open the whole terminal. – John Smith Nov 11 '21 at 12:45
  • Is that simple?! thanks alot best way to stop running code in terminal – Hello-experts Nov 18 '21 at 18:48
  • This only worked for me after disabling key chords in the terminal. You can find this setting by pressing Ctrl+Shift+P, then search for "Preferences: open user settings", and look under User >> Features >> Terminal and uncheck the mark under "Terminal > Integrated: Allow Chords" – Martin Apr 07 '22 at 20:49
  • Wrong on both fronts. The trash can icon does not kill the running process. It just makes that terminal window go away inside VS Code. The process will continue to run in the background. Also by default, the keyboard shortcut Ctrl+C in the VS Code terminal is just "copy". – still_dreaming_1 Apr 05 '23 at 22:35
  • @JohnSmith I found this key mapping for karabiner that does the trick, I still needed to do a simple mapping of left ctrl + c => left cmd + c, but now my right ctrl + c (and other combos) works as expected. https://github.com/rux616/karabiner-windows-mode – Nick Jul 20 '23 at 22:43
10

Ctrl + C works in the terminal, but it didn't work for me in Visual Studio Code. However, hitting Q did (when running a git diff for example).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Blingers
  • 789
  • 1
  • 9
  • 22
6

In certain cases, such as running a Node.js server, Ctrl + C wouldn't work. Instead, you can stop the app or command by pressing Ctrl + Alt + M (i.e., Ctrl + Option + M for Mac users).

Sample JavaScript code to demonstrate this:

const http = require('http');

http.createServer((req, res) => {
    res.write('Hello, World!!');
    res.end();
}).listen(5000, () => console.log('Server running...'));
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
wintermute
  • 488
  • 1
  • 9
  • 22
3

If you are on Linux, open the shortcuts:

Enter image description here

Then type kill, and this option will appear.

Double-click on the record, choose a shortcut for it, open the terminal, Ctrl + J, and press the shortcut you chose.

Enter image description here

The difference in pressing Ctrl + J and then Ctrl + J again to close, is that it will not keep the terminal process, but only close it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Taffarel Xavier
  • 381
  • 5
  • 11
2

Neither Ctrl + C nor the trash icon actually stopped the server for me.

If you are using the Live Server extension by Ritwick Day, there should be a label on the bar at the bottom for the status of the server.

If it reads Port: 5500 it means it's running. Just click on it to stop it.

Stop live server

The same label now should say Go Live. Click on it in order to do exactly that.

Start live server

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
eugeflow
  • 21
  • 4
2

Many Mac users (including me) get confused with the Cmd and Ctrl keys. But Ctrl + C should work fine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
S_Mirza
  • 31
  • 1
  • 6
1

Hitting Esc clears out the terminal and cancels everything.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

You can stop any running command by pressing Ctrl + C on your keyboard.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Foysal imran
  • 111
  • 1
  • 11
1

If it is ':' you see, then Q + Enter.

For example: git config --list (this will take you to the colon(':') and you may not be able to escape this)

Blue Clouds
  • 7,295
  • 4
  • 71
  • 112
1

In Visual Studio (2022) the shortcut may actually Ctrl+Pause/Break instead of Ctrl+C.

Eivind Gussiås Løkseth
  • 1,862
  • 2
  • 21
  • 35
0

In Visual Studio Code, first hit Ctrl + C.

It will ask the following question;

Terminate batch job (Y/N)?

Press Y + Enter.

After this, run the following command on the prompt:

exit + <Enter>

It will stop the instance.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Syed
  • 1
  • 2
0

You can kind of bypass the issue by writing system("pause") at the very end of your main function. That works for me like a charm...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

POSIX signals should work - ctrl+c (SIGINT) usually works, but occasionally I find I need something more powerful - ctrl+\ (SIGQUIT - "terminate the application dumping core") usually does it.

SIGKILL is even more brutal, and generally not advisable as it can cause system instability, and there is not usually a shortcut set up for that in most shells.

drkvogel
  • 2,061
  • 24
  • 17
0

you can use the "kill terminal button" killbutton

morsotom
  • 19
  • 2