Using control-z suspends the process (see the output from stty -a which lists the key stroke under susp). That leaves it running, but in suspended animation (so it is not using any CPU resources). It can be resumed later.
If you want to stop a program permanently, then any of interrupt (often control-c) or quit (often control-\) will stop the process, the latter producing a core dump (unless you've disabled them). You might also use a HUP or TERM signal (or, if really necessary, the KILL signal, but try the other signals first) sent to the process from another terminal; or you could use control-z to suspend the process and then send the death threat from the current terminal, and then bring the (about to die) process back into the foreground (fg).
Note that all key combinations are subject to change via the stty command or equivalents; the defaults may vary from system to system.
Using control-z suspends the process (see the output from stty -a which lists the key stroke under susp). That leaves it running, but in suspended animation (so it is not using any CPU resources). It can be resumed later.
If you want to stop a program permanently, then any of interrupt (often control-c) or quit (often control-\) will stop the process, the latter producing a core dump (unless you've disabled them). You might also use a HUP or TERM signal (or, if really necessary, the KILL signal, but try the other signals first) sent to the process from another terminal; or you could use control-z to suspend the process and then send the death threat from the current terminal, and then bring the (about to die) process back into the foreground (fg).
Note that all key combinations are subject to change via the stty command or equivalents; the defaults may vary from system to system.
If you do Ctrl + Z and then type exit, it will close background applications.
Ctrl + Q is another good way to kill the application.
shell - How do I exit or cancel a bad bash command? - Unix & Linux Stack Exchange
Keyboard shortcut to exit terminal while a process is running (Ctr+D doesn't work if you're running something out of the terminal)
How do i exit the "terminal mode"?
How do I really exit Terminal?
Videos
To close a terminal window you can use the exit command . Alternatively you can use the shortcut ctrl+shift+w to close a terminal tab and ctrl+shift+q to close the entire terminal including all tabs.
You can use the ^D shortcut - that is, hitting Control and d. This works in many shells and shell-like environments. Technically speaking, this key combination emits the end-of-transmission character (ASCII code 04). In gnome-terminal, i.e. bash and other shells, this is interpreted as finishing the interactive session. You can also see this behavior in programs like cat which read from standard input (the keyboard). Try running it without arguments; you can terminate by entering ^D.
You can always try the obvious things like ^C, ^D (eof), Escape etc., but if all fails I usually end up suspending the command with ^Z (Control-Z) which puts me back into the shell.
I then do a ps command and note the PID (process id) of the command and then issue a kill thePID (kill -9 thePID if the former didn't work) command to terminate the application.
Note that this is not a tidy (no pun intended) way to terminate the application/command and you run the risk of perhaps no saving some data etc.
An example (I'd have used tidy but I don't have it installed):
$ gnuplot
G N U P L O T
Version 4.2 patchlevel 6
....
Send bug reports and suggestions to <http://sourceforge.net/projects/gnuplot>
Terminal type set to 'wxt'
gnuplot>
gnuplot> ##### typed ^Z here
[1]+ Stopped gnuplot
$ ps
PID TTY TIME CMD
1681 pts/1 00:00:00 tcsh
1690 pts/1 00:00:00 bash
1708 pts/1 00:00:00 gnuplot
1709 pts/1 00:00:00 ps
$ kill 1708 ###### didn't kill the command as ps shows
$ ps
PID TTY TIME CMD
1681 pts/1 00:00:00 tcsh
1690 pts/1 00:00:00 bash
1708 pts/1 00:00:00 gnuplot
1710 pts/1 00:00:00 ps
$ kill -9 1708 ### -9 did the trick
$
[1]+ Killed gnuplot
$ ps
PID TTY TIME CMD
1681 pts/1 00:00:00 tcsh
1690 pts/1 00:00:00 bash
1711 pts/1 00:00:00 ps
Try pressing Ctrl-D or Ctrl-C. If it fails, kill the process .
Trying with the tidy command you mentioned, Ctrl-D works.
Is there anything to force close the window, regardless of whether something is running?
I'm using KDE Neon if that makes a difference, checked in keyboard shortcuts but didn't find anything
The accurate answer for MAC Keyboard on terminal is:
Command + . (dot/period)
This is equivalent to Ctrl + C or break.
Refer to the:
Terminal Help > Keyboard Shortcuts > Other Shortcuts > Break
The Control or Ctrl key is not a regular modifier in macOS.
However, if you are using a regular Windows keyboard with macOS then Ctrl + C works since there is no Command key in this case.
Try:
Ctrl + C
It should be the same as Linux.
Duplicate of: this question
If I type exit, it does something but Terminal is still running. Is there some line in Terminal besides exit that exits and quits Terminal?
man bash
exit [n] [...] A trap on EXIT is executed before the shell terminates.
Such traps are often used to clean up tmpfiles on exit, see https://stackoverflow.com/questions/687014/removing-created-temp-files-in-unexpected-bash-exit
Define an exit trap like this (for better testing in a new shell):
$ bash
$ trap "rm filetodelete" EXIT
Show defined EXIT trap:
$ trap -p EXIT
trap -- 'rm filetodelete' EXIT
Test:
$ exit
rm: cannot remove ‘filetodelete’: No such file or directory
Note that exit may be "called" implicitly too. So instead of exit you could have also triggered the trap by kill -HUP $$.
Well usually you would only see execution upon exiting a shell if you've manually configured this. But maybe one of the packages you've installed came with a bash exit shell script...
check;
~/.bash_logout
maybe you'll find a script call from there, it's an odd one...
Ctrl + C
Ctrl + C is a the standard *nix way of signaling a process to abort.
Try Ctrl + C. Also, Ctrl + Z might help if you want to suspend a process.
For further information, man kill.
If you're curious about the difference between suspend and terminate, this answer is a good starting point; the TL;DR version is, a suspended process can be resumed later and its execution can continue. A terminated (and killed) process will be gone.
Hello, I find it annoying that everytime I type the code command it opens VSCode and I then have to go back, click on the terminal, and type "exit". I'd much rather just have it automatically close whenever I type the command. I tried going into the file for the command and adding "exit" at the end, but that doesn't work. Will you please help me figure this out. Thank you!
