I'm used to holding the left Alt and entering the ASCII character whenever I'm using an unknown keyboard configuration and want to type a special character.

For example, Alt + 0 + 9 + 2 makes a backslash (\).

That's on Windows. Is there a way to do this in Ubuntu?

Note: I also want to be able to use this in console mode. That means I don't want a solution involving software with a GUI.


5 Answers 5


If you are using Gnome (stock Ubuntu does) you can do that by holding down both the Ctrl and Shift keys and typing u followed by the hexadecimal value of the character.

To produce the backslash \, you would hold Ctrl + Shift and press U, 5 and C.

On Windows you type the decimal value while on Linux you type the hexadecimal value (which is usually shorter if you go in the higher numbers). The u stands for Unicode.

A pretty complete table of hexadecimal values can be found here. Warning, page can take a long time to load!

  • 4
    The "hexadecimal value" is in fact the Unicode codepoint, unlike "Alt codes" which are ASCII Oct 7, 2010 at 18:33
  • Wow. Exactly what I needed ! Works everywhere like a charm. Thank you. Oct 12, 2010 at 15:08
  • 1
    Now I only need to learn all the codes in hexa.... :( Oct 12, 2010 at 15:14
  • Does somebody know, how to get this work in Sublime Text?
    – imrek
    Jul 6, 2016 at 12:37
  • Doesn't work on Ubuntu 18.04
    – razor
    Feb 19, 2020 at 9:41

Linux's console driver doesn't have a facility for entering characters this way... but it isn't really needed since shells can handle this themselves.

$ echo $'\x5c'
  • 1
    Thats a very nice method.... I can't even find it in the man pages of echo but it works! Is there a way to provide the decimal code instead of the hexidecimal one ? (I learned the decimal codes by heart) Oct 7, 2010 at 13:15
  • Is there a way to use this when I'm in vi or nano ? Oct 7, 2010 at 13:17
  • 2
    No, they can only be entered in hex (\xNN) or octal (\NNN). You can use printf if you want to see the hex code for a value. In vim you can type Ctrl-V U and then the 4-digit Unicode codepoint. Also, QUOTING section. Oct 7, 2010 at 14:06
  • 2
    @Silence: (1) Because it's a feature of your shell (usually bash), not of echo. Oct 7, 2010 at 18:33
  • @PhilippeCarriere In vi you can execute shell commands by prepending :! like :!ls. You can also insert the output into the current buffer using :r !. I often lack the tilde character so I use :r !echo $'\x7e'. A little more on that here.
    – valid
    Jul 14, 2014 at 9:54

Another option (but it does not insert a character by ASCII/Unicode code) is to activate the ComposeKey (like right Alt in my case), so that you can then type things like:

  • Alt + = + e → €
  • Alt + ' + e → é
  • Alt + ^ + e → ê

etc. In case you want to enter frequently used latin letters (as in Spanish, French, etc), this might be faster than having to learn the Unicode code points. It's all about having choice!

  • Don't you need an non-US keyboard layout for this? Jun 1, 2014 at 0:23
  • 2
    @CristianCiupitu: No, you need to enable a Compose key. Jul 14, 2014 at 9:48
  • @IgnacioVazquez-Abrams, you're right. It seems that my XFCE 4.10 desktop environment didn't set the Compose key at all, but after setting it to the right Alt key, the answer worked (therefore +1 from me). Jul 14, 2014 at 18:41

From the UTF-8 and Unicode FAQ for Unix/Linux by Markus Kuhn:

Extend your keyboard mapping using xmodmap. This is particularly convenient if your keyboard has an AltGr key, which is meant for exactly this purpose (some US keyboards have instead of AltGr just a right Alt key, others lack that key entirely unfortunately, in which case some other key must be assigned the Mode_switch function). Write a file ~/.Xmodmap with entries such as

keycode 113 = Mode_switch Mode_switch
keysym d = d NoSymbol degree        NoSymbol
keysym m = m NoSymbol emdash        mu
keysym n = n NoSymbol endash        NoSymbol
keysym 2 = 2 quotedbl twosuperior   NoSymbol
keysym 3 = 3 sterling threesuperior NoSymbol
keysym 4 = 4 dollar   EuroSign      NoSymbol
keysym space = space  NoSymbol      nobreakspace NoSymbol
keysym minus = minus  underscore    U2212        NoSymbol
keycode 34 = bracketleft  braceleft  leftsinglequotemark  leftdoublequotemark
keycode 35 = bracketright braceright rightsinglequotemark rightdoublequotemark
keysym KP_Subtract = KP_Subtract NoSymbol U2212    NoSymbol
keysym KP_Multiply = KP_Multiply NoSymbol multiply NoSymbol
keysym KP_Divide   = KP_Divide   NoSymbol division NoSymboll

and load it with xmodmap ~/.Xmodmap from your X11 startup script into your X server. You will then find that you get with AltGr easily the following new characters out of your keyboard:

  • AltGr+d → °
  • AltGr+[ → ‘

Not exactly what the OP is asking, but maybe it's enough for whoever is reading this.

Depending on your selected keyboard layout, you may already be able to type some unicode and ASCII characters; just like in macOS. Click on the language selector near the tray icon (if you have it), then Show Keyboard Layout, and have a look at the alternative characters of the individual keys.

For instance, you can type … (ellipsis) with right ALT + ., and ÷ (division) with right ALT + SHIFT + ..

Moreover, these keystrokes even work in Sublime, which proved to be more stubborn towards CTRL + SHIFT + U.

You must log in to answer this question.

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