I have a problem with a remote server having a keyboard layout in the console different from my physical keyboard.

I need to copy a @ letter to be able to paste in a browser forum.

The server is in a VPN without external access, so a simple googling for 'at symbol' doesn't work.

Is there some trick to have a @ printed in the console so I can copy and paste it? Is there a well-known file to simply do a cat and show a @ inside it? A README or similar.

  • 4
    If you are using some sort of remote management console solution (HP iLO, Sun/Oracle ILOM, Dell iDRAC etc.) then note that the management console often has a setting that tells it which keyboard layout the server OS is configured to use. If that setting is incorrect, the mapping from the workstation characters back to low-level keyboard scan-codes and then again to characters at the remote server is likely to cause very odd results. In some cases it can be easier to temporarily revert the remote server to US keyboard layout (localectl set-keymap us in many modern distros).
    – telcoM
    Aug 19 at 12:50
  • 3
    Making a @ part of your prompt would make it always accessible.
    – Kusalananda
    Aug 20 at 13:38
  • 2
    Attacking the actual problem, the @ symbol is probably where " is. Or use loadkeys or something to set your actual keyboard layout.
    – OrangeDog
    Aug 20 at 20:59
  • @OrangeDog, that's not always so easy. Some remote console systems need to send keyboard scan-codes to the remote system (because they emulate a USB keyboard there), even if they only get characters from the client side (after the client OS handles the keyboard layout mapping). That means that some point in the connection needs to do mapping back from the characters to scan codes, which isn't what you usually do. It should be doable if you know the keyboard layout, but I recall having problems with that with VMware or some such.
    – ilkkachu
    Aug 21 at 11:09

With the bash shell:

echo $'\x40'

With a POSIX shell:

printf '\100'

You can use man ascii to show the set of ASCII characters and cut-n-paste from that output.

(If you have the ascii program from Plan 9 or other things installed, you can specify that you want the man page from section 7 explicitly: man 7 ascii, but that usually isn't necessary.)

  • 1
    If you have /usr/bin/ascii installed, you can run it; its default output includes literal versions of all the printable ASCII characters. Aug 20 at 18:00

If the GNU variants of sed and cut are installed, you could extract the @ character from the bug reporting address displayed in sed --version:

sed --version |grep bug-sed|cut -d : -f2|cut -d d -f2|cut -d g -f1
  • 3
    Using sed instead of grep|cut|cut|cut : sed --version | sed -n '/.*bug-sed\(.\)gnu.org.*$/s//\1/p'
    – ImHere
    Aug 19 at 21:15
  • 6
    if all you need is something to copy and paste, surely sed --version alone would suffice Aug 20 at 20:28

If you have Perl, you can get all printable ASCII characters with minimal need for special characters like this (works with double-quotes too):

shell$ perl -l -e 'print map chr, 32..126'

or even more minimally (just letters and dot):

shell$ perl
print chr for 32..126

This are some methods that have not been mentioned before:

printf  '\x40'
printf  '\u40'
echo -e '\u40'
echo   $'\u40'
echo 40 | xxd -p -r
perl -le 'print chr 64'
python <<<'print chr(64)'
python3 -c 'print(chr(64))'
php -r 'echo chr(64);'

[1] The 40 value is the hexadecimal value of an ASCII character @. Or 64 in decimal (used later). That is expressed in \x40, or read as hexadecimal (\x) value 40. The command printf converts it to a byte of such value and the console prints a @.

And it is also the Unicode code point value of the same character @. It so happens that Unicode code points and ASCII character values are exactly the same (by design) up to 127 (hex 7F or octal 177).

There is, however, a difference between \x40 (or \100) and \u40. The latter will always produce an UNICODE code point, no matter what locale, language or condition is set for the OS or computer that runs the code. While printf '\100' would output a space. And, also by design, code points in UNICODE have been assigned as static values. It is expected that they won't change in the future. In short, a \u40 should produce a @ even on an EBCDIC-based system (for example). For ASCII values that might seem as an small gain, but for higher code point characters, it is a real advantage as \u2225 should always produce parallel () no matter the locale or language being used.

Support for \uxxxx was first added in GNU printf (the standalone utility) in 2000. Then to zsh's print/printf/echo/$'...' in 2003 and a few other shells later. The $'\uxxxx' syntax is even planned for inclusion in POSIX. You need the 4 digits in the standalone printf: printf '\u0040'. In bash, ksh93 and zsh from 1 to 4 digits are allowed. A \Uxxxxxxxx is required to use up to 8 hex digits.

[1] Initial Idea from a (now erased) comment of Stéphane Chazelas


Resolved !

I used man ifconfig and scrolled to the boottom. I found an email address, from where I can copy a @

  • 14
    If you like this method, you might find man ascii an even better "source" of characters. Aug 19 at 11:54

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.