Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I was trying to create a symbolic link using the following command:

ln -s "~/Foo Bar/" Foo

... but it didn't work (i.e. when I go into finder and try double clicking it, it says that it's pointing to an invalid path and prompts me to delete the alias or fix it). I had to rename the folder to FooBar and then run the following command:

ln -s ~/FooBar/ Foo

How can I create the link without having to remove the space from the folder's name?

I'm looking for a way to do this in Terminal and not in Finder's UI.

share|improve this question
1  
While Gordon Davisson is right, you should be aware that aliases and symbolic links (symlinks) are different. ln -s makes symlinks. The Finder makes aliases. They are almost identical in practical, common use, but it's important to recognize that they are different. Symlinks point to a directory path, while aliases point to a file. If you have both pointing to the same file and you move the file to a different folder, then make a new file in the old folder, the alias will point to the moved original and the symlink will point to the new file. –  CajunLuke Feb 17 '11 at 20:46
    
@Cajun: thanks for the clarification. It's confusing that finder shows a symbolic link's "Kind" property as "Alias". –  Senseful Feb 17 '11 at 21:25
3  
Tab completion is a wonderful thing too, if you were to do this: ln -s ~/Foo<tab> (where <tab> denotes the actual ⇥ (tab) key on your keyboard), if there is only one folder that starts with "Foo" in ~ then it will automatically expand the path to ~/Foo\ Bar/. –  Jason Salaz Feb 17 '11 at 23:40

2 Answers 2

up vote 16 down vote accepted

The quote marks are preventing ~ from being expanded to your home folder, so you need to either quote just the part with the space in it:

ln -s ~/"Foo Bar/" Foo

Note: exactly how much is quoted doesn't matter, as long as the space is in the quoted portion and the ~ isn't. ~/Foo" "Bar/, ~"/Foo Bar/", ~/Fo"o B"ar/ etc are all equivalent.

You could also use an escape to prevent the space from being treated as a separator:

ln -s ~/Foo\ Bar/ Foo
share|improve this answer
3  
You can serious quote JUST the space? That's awesome! –  Jason Salaz Feb 17 '11 at 23:37

I tested it myself. I don't have a problem with a space in it:

    $ ln -s "/Users/joe/test/foo bar"/ linkToFoo_Bar

ls shows: $ linkToFoo_Bar -> /Users/joe/test/foo bar/ and it works in terminal and finder without any problems.

share|improve this answer
4  
You used a full path, not the ~ helper. –  Jason Salaz Feb 17 '11 at 23:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.