I would like to know how I can disable ALL keyboard shortcuts via the terminal. I know you can disable them by going to:

system settings>keyboard>shortcuts

but I want to disable them via terminal. anyone knows how this can be done?

  • What keyboard shortcuts are you talking about? There are very many different sets. You have some that work on the command line, some that activate GUI stuff etc. They are completely separate. – terdon May 6 '14 at 12:37
  • If you go to system settings>keyboard>shortcuts there are all the shortcuts in ubuntu and I want to disable all of them. – user278551 May 6 '14 at 12:54
  • OK, so you mean only the GUI shortcuts. I assume you are using the default Ubuntu so your desktop environment is Unity. Is that correct? – terdon May 6 '14 at 13:01
  • yes that is correct. – user278551 May 6 '14 at 13:04

I have no idea why you would want to do this and I should warn you that it may well be complicated to get the shortcuts back. If this is really what you want to do, the commands below will disable all keyboard shortcuts. Both those set up through Unity's GUI and any you might have set up using ccsm

A. Disable the Unity keyindings

  1. First make a backup of the current bindings so you can re-enable them later

    gsettings list-recursively org.gnome.desktop.wm.keybindings | 
       perl -pe 's/(.*)\s*(\[.*?\])\s*$/$1\t$2\n/' | 
        while IFS=$'\t' read -r key val; do echo -e "$key\t$val"; done > old_settings

    This will create a file called old_settings in the following format:

    schema key <TAB> value

    For example:

    org.gnome.desktop.wm.keybindings unmaximize <TAB> ['<Control><Super>Down']
  2. Now disable the shortcuts

    gsettings list-recursively org.gnome.desktop.wm.keybindings | 
        perl -pe 's/(.*)\s*(\[.*?\])\s*$/$1\t$2\n/' | 
            while IFS=$'\t' read -r key val; do gsettings set $key ['']; done


    • gsettings list-recursively org.gnome.desktop.wm.keybindings : this lists all keybindings and their current values
    • perl -pe 's/(.*)\s*(\[.*?\])\s*$/$1\t$2\n/' : this simply adds a TAB character (\t) separating the value from the key. This step is needed to be able to read them properly in the next one.
    • while IFS=$'\t' read -r key val : go through each line and read the key into $k and its value into $val. $IFS=$'\t' means split on tabs so that the key and value are read correctly.
    • gsettings set $key [''] : this actually sets the value to blank, effectively disabling your shortcuts.

    Note that you may have to log out and log back in again for this to take effect.

  3. Get (some of) your shortcuts back

    while IFS=$'\t' read -r key val; do 
        gsettings set "$key" "$val"
    done < old_settings 

    WARNING: This will probably not work for all settings since some of them seem to have an extra parameter @as in the key name and I don't know how to deal with that one. As I said, this is all not a very good idea.

B. Disable your custom shortcuts set in ccsm

gsettings set org.gnome.settings-daemon.plugins.media-keys active false

This time, getting them back is easy. All you need to do is run

gsettings set org.gnome.settings-daemon.plugins.media-keys active true
| improve this answer | |
  • Thank you great work, I think still missing Compiz shortcuts? – user.dz May 7 '14 at 17:09
  • @Sneetsher part B. should deal with the user-defined compiz shortcuts. Not sure about the default ones. Let me check. – terdon May 7 '14 at 17:12
  • Added a script to be a little bit more of a usable front-end to do the above: github.com/fatso83/dotfiles/blob/master/utils/scripts/… – oligofren Jun 19 '18 at 9:13
  • Regarding the "I have no idea why you would want to do this" the use case for everyone on my dev team is that the default shortcuts overlap with known key bindings in popular programs. In our case, most of the IntelliJ shortcuts didn't work, and we all really just need a handful of the Gnome shortcuts (like Alt-Tab and window resizing). – oligofren Jun 20 '18 at 12:05
  • @oligofren sure, but why would you then need to disable all shortcuts from the terminal? That's what I found strange. But anyway, to each their own :) – terdon Jun 20 '18 at 12:15

I built upon @terdon's answer and made a script to do the same, but does so in a somewhat more user friendly fashion.

You could use it like this:

gnome-key-bindings --unset-all --except 'close|switch-applications'

As I like using the default keybindings Alt-F4 and Alt-Tab (and their reverse using shift), this would remove all keybindings except these.

It also has a nice help menu:

List/disable/enable/set gnome-key-bindings

gnome-key-bindings [-h | option] [value]

   --list              Lists all the current keybindings
   --set=key           Set a specific keybinding
   --unset=key         Unsets a specific keybinding
   --unset-all         Unsets all keybindings
   --except=REGEX      Filter out keys matching REGEX from being unset
   --print-default     Prints the default shortcuts per Ubuntu 18.04


     Clearing all keys except a few:
       gnome-key-bindings --unset-all --except "close|switch-applications|switch-input-source|show-desktop"

     Setting a shortcut
       gnome-key-bindings --set=maximize "<Super>Up"    

To use it on your own machine

curl -s https://raw.githubusercontent.com/fatso83/dotfiles/master/utils/scripts/gnome-key-bindings -o gnome-key-bindings
curl -s https://raw.githubusercontent.com/fatso83/dotfiles/master/utils/scripts/easyoptions.sh -o easyoptions.sh
curl -s https://raw.githubusercontent.com/fatso83/dotfiles/master/utils/scripts/easyoptions.rb -o easyoptions.rb
chmod +x ./gnome-key-bindings
sudo mv ./gnome-key-bindings easyoptions.* /usr/local/bin/
| improve this answer | |

For gnome on Ubuntu 18.04, I found this to work:

gsettings list-keys org.gnome.shell.keybindings | xargs -I@ gsettings set org.gnome.shell.keybindings @ ['']
gsettings list-keys org.gnome.mutter.keybindings | xargs -I@ gsettings set org.gnome.mutter.keybindings @ ['']
gsettings list-keys org.gnome.settings-daemon.plugins.media-keys | xargs -I@ gsettings set org.gnome.settings-daemon.plugins.media-keys @ ['']
gsettings set org.gnome.mutter overlay-key ''

I'm not sure if that's all the shortcut keys, but it seems to be the bulk of them

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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