21

I'm running Ubuntu Server as a virtual machine (using VirtualBox) on my mac.

Normally on the Mac, I'd press alt + 3 to input the hash (#) sybmol.

However, if I do this in my Ubuntu Server's console, it gives me "Unrecognized Command" when inside nano.

How can I input this symbol? I need this to be able to add comments to my apache configuration file.

Thanks

Daniel Beck
  • 111,893

7 Answers7

32

Alt is used as Meta on your system. That's why it behaves strangely in nano and bash.


On Ubuntu server (command-line only) with British keyboard layout, you need to press the right alt key to get the hash symbol #: Only the right alt is interpreted as alt-gr by your Linux system, and that's the modifier key required on non-Mac OS systems for the alternative characters on the keyboard.

Daniel Beck
  • 111,893
6

I just came across this as I'm doing my LPIC and using a MB Pro running CentOS in a VM.

Ended up being CTRL+\

2

In Terminal preferences, go to Profiles then Keyboard. Disable the Use Option as Meta Key option.

enter image description here

Mike
  • 121
2

For me it's just the \ key.

(Jessie, Virtualbox on El Capitan, UK keyboard)

mwal
  • 121
2

Ubuntu 12.04 with UK keyboard, installed on a MacBook Pro. Unfortunately the right-side Alt3 only emits a superscript "2", not the hash, And the left-side Alt3 prints nothing.

Going to System Preferences ยป Keyboard I can see that my current keyboard is listed as: English (UK, MacIntosh international).

Clicking on the little "keyboard" button at the bottom shows the position of all characters on each key. So for me the hash # is Right-Ctrl|\ (right Alt, pipe and backslash). One of the previous posts said Alt but it was Ctrl

Luna
  • 21
0

In late 2018, on the latest Macbook Pro with F keys as F keys, I need to type fn+option+3 to get # in terminal. Perhaps it's because in iTerm, under Profiles/Keys I have loaded preset "Natural Text Editing" (to allow travelling across words with option (alt)).

jbasko
  • 143
0

I don't know what terminal the OP is using - probably the built-in terminal (Terminal.app), but in case anyone has this problem with iTerm2, here is what fixed it for me:

In iTerm2 Preferences > Keys > Navigation Shortcuts > "Shortcut to choose a split pane" was opt+number, so opt+3 was mapped to focus the 3rd pane in your tab had been split into panes, but this was overriding the normal mapping of opt+3 to #. I changed it to "No shortcut" and could then type hash symbols in iTerm.

I never had this problem before, but recently bought a new MacBook Pro M1 with MacOS Monterey, installed iTerm2 on it amongst other things, and then was was amazed to find that I couldn't type a hash symbol in the terminal - for example, for making comments in Python code or Bash scripts. I certainly didn't set it that way - so it must have been in the default setup of iTerm2. Why on earth the developers thought that was a good setting to have on by default, I don't know.

drkvogel
  • 457