Ctrl+C does not work in gnome-terminal
Solution 1
Try to do this
$ stty sane
and see if it fixes the problem, also check if the intr is set correctly using
$ stty -a
If you find that intr
is set to something different than ^C, then you can also fix it by typing
$ stty intr ^v^c
Solution 2
The default settings in gnome-terminal
binds the Ctrl-C
and Ctrl-V
keys to emulate the copy-and-paste behaviour of Windows. It was meant to be a feature not a bug :)
To disable this, at the gnome-terminal,
- navigate to
Menubar -> Edit -> Keyboard Shortcuts
- click on the Ctrl+C in the Shortcut Key column until you see
New Accelerator...
. - press the Backspace or Delete key to disable the key binding
- verify that
Disabled
now appear in the Shortcut Key column.
Note that this change will be immediately effective on all gnome-terminals.
Tip: gnome-terminal --show-menubar
will force gnome-terminal to show the Menubar if it is not shown.
Solution 3
Since it looks like a broken gnome-terminal
configuration, you can try letting it restore the defaults using
mv .gconf/apps/gnome-terminal{,-BROKEN}
(You'll need to re-start the terminal to see the effects.)
If everything is fine after that, do a rm -rf .gconf/apps/gnome-terminal-BROKEN
.
Solution 4
I'm going to take a guess here: Ctrl-C does work, but because ps -e
takes a long time to run relative to the rest of the script, that all you do is send SIGINT to the "ps" process. "ps" exits, and the script picks right up with another iteration through the loop code.
Do a sleep 10
in your bash window, while it runs, control-C it. See if that works. If it does, run your original script, and control-C it multiple times. Sooner or later, you'll get lucky and the bash process that interprets the script will get the SIGINT.
Solution 5
When I looked at my shortcuts for terminal I see that the shortcut for "copy" is set to Control+C. So I changed it to Control+Shift+V (for copying).
Now everything is working.
Be sure to check
stty -a
and make sure intr is set to ^C
before checking the shortcuts.
Related videos on Youtube
Cees
Updated on September 18, 2022Comments
-
Cees over 1 year
On my Linux host, Ctrl+C does not seem to work and I do not know how to proceed to make it work. I am using Ubuntu 10.04 with bash 4.1.5(1), and working in Gnome-terminal.
When I pressed Ctrl+C while this script was running, it did not cause it to quit.
#!/bin/bash for i in `seq 500` do ps -e > /dev/null echo $i done
-
Admin over 12 yearsWhat do you mean by “does not work”? Where did you press that key, what did you expect to happen, what actually happened?
-
Admin over 12 yearsMaybe you can describe further details of why you think that Ctrl-C does not work -- there are certain kernel level things which is not interruptible -- for example a process hanging waiting for a (failed) NFS answer can frequently not be interrupted
-
Admin over 12 yearsI updated my answer. Basically Ctrl C did not terminate a script, that I think should be terminated on doing Ctrl C.
-
Admin over 12 yearsDoes
stty -a
output containintr=^C
? How do you run the script? -
Admin over 12 yearsPlease do not cross-post questions. Choose the site you want to ask on, and tailor it to that site.
-
Admin over 12 yearsYou're right that the script should be terminated if you press
Ctrl+C
. In what terminal did you do this? Does it happen in another terminal? What happens if you runsleep 5
and then pressCtrl+C
? -
Admin over 12 yearsIts regular terminal in Ubuntu. It is /dev/pts/0 if that helps. It happens in any terminal on my computer. If I do sleep 5 and do Ctrl C nothing happens. Nothing is printed to the console also.
-
Admin over 12 yearsI run the script by doing ./hello.sh
-
Admin over 12 years@abc: have you tried to use a different terminal emulator (xterm, rxvt, …)?
-
Admin over 12 yearswhen I tried using xterm I was able to Ctrl C sleep 10. But with gnome-terminal Ctrl C on sleep 10 did not work. Why is that ?
-
Admin over 12 yearsSo using gnome-terminal Ctrl C works but Ctrl c does not. So to interrupt sleep 10 if I do Ctrl + Shift + c it works. But doing Ctrl + c does not work. Why is it case sensitive.
-
-
Cees over 12 yearsThis did not help. stty -a shows "intr = ^C" ( without the quotes)
-
Cees over 12 yearsDo I have to type the ^ character or press the Ctrl key?
-
Soren over 12 yearsyou just have to press the Ctrl key (^ is short for Ctrl-)
-
Soren over 12 yearsMaybe you can describe further details of why you think that Ctrl-C does not work -- there are certain kernel level things which is not interruptible -- for example a process hanging waiting for a (failed) NFS answer can frequently not be interrupted
-
Cees over 12 yearsI added more details to my question. Basically Ctrl C is not terminating a script that I am running, which I expect to be terminated on Ctrl C.
-
Cees over 12 yearsCtrl C on sleep 10 does not work either.
-
Cees over 12 yearsSo using gnome-terminal Ctrl C works but Ctrl c does not. So to interrupt sleep 10 if I do Ctrl + Shift + c it works. But doing Ctrl + c does not work. Why is it case sensitive.
-
Cees over 12 yearsSo using gnome-terminal Ctrl C works but Ctrl c does not. So to interrupt sleep 10 if I do Ctrl + Shift + c it works. But doing Ctrl + c does not work. Why is it case sensitive.
-
Tom St almost 4 yearsnot sure why this answer was minused, its really good :)