5

This question already has an answer here:

Why do we have to use all this shortcut to quit the programs in terminal ?

For example :

  • ctrl+c in order to quit top
  • ctrl+z in order to quit man
  • ctrl+x in order to quit nano

ctrl+c isn't suppose to kill the program ?

marked as duplicate by karel, Kaz Wolfe, muru, Gilles 'SO- stop being evil', Eric Carvalho Sep 9 '14 at 18:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

10

Because it's specified in POSIX, the IEEE norm for Unix-like computer systems.

Check Section 10.2 - Output Devices and Terminal Types of the POSIX.1 2008 (the latest) specification for all the shortcuts available.

To add up to your question, this is a brief explanation of what those shortcuts actually do.

When you press Ctrl-[letter], you are actually sending a signal to the process. A signal is a "flag" you provide to the process that gets interpretated and associated with an action.

  • Ctrl-C sends SIGINT, a signal that causes the process to terminate.

  • Ctrl-Z sends SIGTSTP, a signal this causes the process to suspend execution. In this case, it is resumable - try executing a command that will take a while and press Ctrl-Z; you'll see something in the lines of

    [1]+ Stopped [your command].

    Type fg in your Terminal and you'll see the process resuming, if it didn't end before resuming it.

  • Ctrl-X, in this case, is the shortcut nano uses to exit the process. Incidentally, there is a signal associated to Ctrl-x, but it's not related to nano.

TL;DR It's specified in POSIX.

  • fg for "foreground" if it helps you remember it. Also jobs to list – seth10 Jul 25 '17 at 21:06
  • Would be very usefull to also add "bg" (background) for resuming a process in the background, i.e., keeping the terminal available for other commands – vanadium Jan 4 at 7:39
  • Why doesn't man handle ctrl-c? – cowlinator Jul 17 at 0:06
2

+z and +c are shell signals.

ctrl+z is not killing the programm, it is sending it a signal (SIGTSTP) to suspend. Type fg to resume it. ctrl+c is another signal, this time the SIGINT to terminate. kbd+x is just a nano key binding.

Not the answer you're looking for? Browse other questions tagged or ask your own question.