Is it possible in the Unix terminal to change some of the keyboard keys?

For example: when I press , then _ gets printed?

If this is indeed possible, how do I go about doing that?

I'm on Ubuntu.

  • Do you want to do this in all terminal windows? Or only in a specific terminal window (e.g. by invoking the terminal emulator with a special configuration file or command-line option)? Or in all applications? Mar 20, 2012 at 16:36
  • I want to be able to change what gets written when i type in the terminal. And that means, whenever I start the terminal.. that's a window who will receive my keyboard input in this new way.
    – john-jones
    Jan 22, 2013 at 13:21
  • @PierreVriens Please read meta.stackexchange.com/a/10648/186664 and stop making titles perfectly good title into questions.
    – Anthon
    Apr 7, 2015 at 6:08

3 Answers 3


To quote from here:

Custom table

You can create your own map and store it in your home directory (i.e. ~/.Xmodmap). Print the current keymap table into a configuration file:

xmodmap -pke > ~/.Xmodmap

Make the desired changes to ~/.Xmodmap and then test the new configuration with:

xmodmap ~/.Xmodmap

To activate your custom table when starting Xorg add the following:

if [ -f $HOME/.Xmodmap ]; then
    /usr/bin/xmodmap $HOME/.Xmodmap

Alternatively, edit the global startup script /etc/X11/xinit/xinitrc.

Test changes

You can also make temporary changes for the current session. For example:

xmodmap -e "keycode  46 = l L l L lstroke Lstroke lstroke"
xmodmap -e "keysym a = e E"


See man xmodmap for more details.


To clarify: the xmodmap ~/.Xmodmap may be used in many places, not just when starting Xorg. For example, I have these two functions in my ~/.bashrc:

   # map caps to esc

      xmodmap -e "clear lock"
      xmodmap -e "keycode 0x42 = Escape"
      echo mapcaps: caps-lock set to Escape via xmodmap
      xmodmap -e "keycode 0x42 = Caps_Lock"
      xmodmap -e "add lock = Caps_Lock"
      echo unmapcaps: caps-lock set to caps-lock via xmodmap

This is so I can dynamically map Caps to Esc.

Really there is no limitation. Feel free to call xmodmap from ~/.xinitrc, ~/.bash_profile, from a custom script, etc.

  • if [ -f $HOME/.Xmodmap ]; then - I guess when xorg is started, on many systems nobody is logged in, since they use a graphical login, so $HOME might not set. Mar 20, 2012 at 21:08
  • If that is the case, one can always manually activate the custom keymap with xmodmap ~/.Xmodmap. In fact, I have this very command in my ~/.xinitrc file, so that it only runs when I start my window manager (in this case dwm). The downside to this is that the custom keymap is not enabled when using pure X. Still, having the ability to call xmodmap whenever is a great advantage which allows much flexibility. You can put the xmodmap command wherever, including ~/.bash_profile, which guarantees that there is a user logged in.
    – Emil
    Mar 20, 2012 at 21:15
  • Yes, or if it is a single user machine, like most desktops, put the file into /etc/.Xmodmap or reference /home/herrmann/.Xmodmap. Mar 20, 2012 at 21:35
  • I find this very confusing actually. So I make a Xmodmap file in my home directory (there is no such file currently, im using L-Ubuntu 11.04). So how do I for instance, make that file turn 'A' into 'B'?
    – john-jones
    Jan 22, 2013 at 13:20
  • It would be something like keycode 38 = e E e E. View your current keymap with xmodmap -pke.
    – Emil
    May 13, 2013 at 17:08

To be honest I have never tried to do what you are trying. I have added alternate key bindings (key combination) for a terminal (non-X) before though.

You can see your key bindings with: showkey or showkey -s

You will use the related programs to do the additional research and modifications.

loadkeys dumpkeys keymaps setkeycodes

For me to make the change in Slackware it is pretty easy I spent some time looking around in Ubuntu but did not find the same files /usr/share/kbd/keymaps/i386/qwerty/*map.gz files. Though I only had access to a live booted Ubuntu system. You might fare better.


If you want to do this in the X Windowing System, you can use Xmodmap. I've never had a grip on the syntax, so find a working example, and go from there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .