Ctrl+C does not work in gnome-terminal
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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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
Method 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.
Method 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
.
Method 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.
Method 5
Check to see that you don’t have CTRL+C
already mapped as a Copy to Clipboard
shortcut. If so, this will override the CTRL+C to quit
that you’re used to.
Linux terminals often come with SHIFT+CTRL+C
as the default Copy to Clipboard
shortcut and many users (including me) change this to CTRL+C
as that’s more intuitive coming from another OS.
Consider mapping the stop process shortcut to CTRL+X
so you don’t have to change your Copy to Clipboard
muscle memory:
stty intr ^x
Method 6
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.Method 7
I know it is an old topic, but stupid mistakes have no age! 😉
I recently had changed CTRL–C to a shortcut for copying text and forgot about it.
After changing the shortcut for copy to SHIFT–INS now CTRL–C is working again in the terminal!
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0