39

I have this weird situation on my Mac running OSX Lion where the ~ (tilda) does not go to my user directory. Instead when I type "cd ˜", I get:

-bash: cd: ˜: No such file or directory

Any advice on how to fix this?

rasheqrahman
  • 511
  • 1
  • 4
  • 5

10 Answers10

64

After changing the keyboard (System Preferences>Keyboard>Input Sources) from 'US International - PC' to 'U.S.', I was able to verify tilde sign (~) works as expected from Terminal.

It looks like in some of the macbook, the keyboard is set to 'US International - PC' instead of 'U.S.'

Compares the different keyboard layouts while pressing SHIFT

Ben
  • 2,235
  • 18
  • 17
Venkat Ganesh
  • 641
  • 5
  • 2
50

Try this one:

˜ + <spacebar> 

It's results the tilde you want: ~

The ˜ character's code is 0x02DC and the code that works in bash like shortcut to home directory is 0x07E.

tomrozb
  • 25,773
  • 31
  • 101
  • 122
Rômulo Jales
  • 509
  • 5
  • 5
15

The other answers are correct in that you are not typing the regular tilde character but are using the small tilde character. What the other answers do not explain though is why when you type tilde you are getting the small tilde and not the large tilde.

The same problem plagued me for some time. I found the problem was I was using the 'US - International' key mapping. Try changing it in System preferences > Language and Text > Input Sources. With that keyboard selected you need to type the tilde and then hit the space bar to see it change from small tilde to regular tilde.

Dan Collins
  • 345
  • 4
  • 6
13

There are several characters like a tilde, and yours ˜ is not the one for the homedir ~ (close together: ˜ vs ~).

Wrikken
  • 69,272
  • 8
  • 97
  • 136
4

I've run into a related issue a couple of time that may have prompted the question: bash doesn't do tilde expansion on quoted filepaths (which you might use if you have spaces in the path). For example, cd "~/Documents/My Project" gets you the same error originally posted. The trick is to leave the tilde and the first slash outside the quote: cd ~/"Documents/My Project" works just fine.

Unsigned
  • 9,640
  • 4
  • 43
  • 72
Frederick Solt
  • 356
  • 3
  • 10
4

Yep, that's an enye (option-n) not ~ (shift-`)

Joel
  • 41
  • 1
1

I set up KeyRemap4MacBook application and type ~ with shift+escape

setting tilde key to shift escape in KeyRemap4MacBook

Maxim Yefremov
  • 13,671
  • 27
  • 117
  • 166
0

alt+5 is what you are looking for...

manuele
  • 359
  • 1
  • 2
  • 16
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/faq#reputation) you will be able to [comment on any post](http://stackoverflow.com/privileges/comment). – Nikhil Oct 26 '12 at 08:41
  • uh maybe I miss something... the question was: I have this weird situation on my Mac running OSX Lion where the ~ (tilda) does not go to my user directory. Instead when I type "cd ˜", I get: -bash: cd: ˜: No such file or directory Any advice on how to fix this? the reason is that (as someone else said before) the character used was not the right one. I mean to add that he right character you have to use for this purposes is the tilde you can get pressing "**alt**" and "**5**" buttons together. – manuele Oct 27 '12 at 12:50
0

I'm using the Brazilian ABNT2 layout. Here [~] + [Alt Gr] does the job.

Miguel Pragier
  • 135
  • 2
  • 13
0

As @Venkat Ganesh mentioned, the simple answer to what people are asking is if you're on osx, check to make sure your keyboard didn't get changed to International PC. Once you change it back to US, it resolves the problem. menu bar showing correct US keyboard layout chosen