5

No matter how I try to create an symbolic link OS X refuses to play along and instead creates an alias. I've tried several tools and also through the terminal using the ln command.

I am on a fresh install and using the ln command worked fine before. Any idea what's up?

Thanks, Will

  • 1
    What command did you tried exactly ? – Matthieu Riegler Jan 24 '14 at 23:12
  • @MatthieuRiegler I've tried ln -s <source> <dest> and tools like: seiryu.home.comcast.net/~seiryu/symboliclinker.html – user68523 Jan 24 '14 at 23:15
  • ln only knows how to make links, alias are from Apple tools only - How do you know it is an alias? – Mark Jan 24 '14 at 23:21
  • @Mark Finder classifies it as an alias and if I run ls -la it calls it an alias as well. – user68523 Jan 24 '14 at 23:26
  • Make sure that ln is really ln. In the terminal, execute type ln to make sure it is /bin/ln. – ithos67 Jan 25 '14 at 3:27
12

Let's try a few experiments, and look at a few things.

In a terminal emulator, such as Terminal.app in /Applications/Utilities, go to your home directory (cd ~) and create a directory (mkdir [directory]).

Make sure you go in the directory we just created (cd [directory]).

cd ~
mkdir directory
cd directory

After that, make a file; a simple text file will do:

echo "This is a simple text file" > originalfile.txt
ls -l@

Now, try creating a hard link, like this:

/usr/bin/ln originalfile.txt hardlink.txt

Then, try creating a symbolic link, like this:

/usr/bin/ln -s originalfile.txt symboliclink.txt

Now, open the directory in Finder with open . and make an alias.

In the terminal emulator you opened before, another ls should get us this:

Testarossa:test tonyw$ ls -l@
total 2528
-rw-r--r--  2 tonyw  staff      19 25 Jan 15:51 file.txt
-rw-r--r--@ 1 tonyw  staff  426048 25 Jan 15:52 file.txt alias
com.apple.FinderInfo        32 
com.apple.ResourceFork  850686 
-rw-r--r--  2 tonyw  staff      19 25 Jan 15:51 hard.txt
lrwxr-xr-x  1 tonyw  staff       8 25 Jan 15:53 symbolic.txt -> file.txt

The Finder GUI should result in this, too:

The Finder GUI with the original file, a hard link, and a symbolic link.

Please note that the Finder GUI displays a symbolic link as an alias.

A symbolic link is not the same thing as an alias. A real alias has extended attributes than a symbolic link.

In the Finder GUI, there is no way of telling a hard link is anything but a file.

For any symbolic links, there is an 'l' at the left hand end of the attributes, and the ls command tells us where it points.

When you try this, exactly what do you get?

  • So to piggyback on this idea, is there anyway we can force OSX/Finder to relabel symlinks as such instead of as aliases? – Daron Spence Jan 28 '15 at 5:13
  • ...there is no way of telling a hard link is anything but a file. That's because there is no difference. When you created originalfile.txt you were creating a file with one hard-link, and when you created hardlink.txt, that was a second hard link to the same file. There is no way (in the finder, or at the command prompt, or anywhere else) to tell which name was the original and which is the "link". They're both links. Every file has at least one hard link. – Solomon Slow Sep 3 '16 at 18:10
1

OS X can create both, but in different ways. As you seem to be using the word alias it is a file (or directory) shortcut that was created in Finder for anything you see listed there, whereas a symlink (symbolic link) can be created in a shell instance started by your terminal app by using the command:

ln -s <source file path><target file path>

A symlink cannot be created directly in a Finder window (indirectly perhaps by calling an AppleScript script from a shell script or vice-versa).

But there is an ambiguity here because there is another kind of alias, which is a user-defined nickname that you can give to a sequence of shell commands when you open a terminal session. For example in a bash shell window:

$ alias listall=ls -al`

This defines a nickname listall for the command ls -al to list all files in the current directory. In this context 'alias' describes command nicknames - alias is actually a bash shell built-in command for creating such nicknames.

I am not an expert on the OS X filesystem, just a user and scripter, but from what I have read the reason why a Finder alias does not break in OS X is because it contains a unique serial number for its target file (called an inode number, that exists for each file and directory) that is independent of its file path. This means that if you move the target to another directory then the alias will still point to it, whereas a symlink would break because it uses the file path of the target.

0

You can't natively create symlinks (symbolic links) in Finder, only aliases. You can, however, use AppleScript to create symlinks if this is what you ultimately need.

To understand why this is so, we must understand the difference between aliases, symlinks, and hard links:

  • Aliases are Finder conventions; meaning they only work within Finder and not in the UNIX environment of OS X. They are small data files and your shell (bash, sh, zsh, etc.) don't know how to interpret them.

  • Symbolic Links (symlinks for short) are shortcuts that are part of the *NIX filesystem. Finder treats them as quasi aliases, you can see them and use them, but they contain none of the extra metadata that Finder aliases contain.

  • Hard Links are quite similar to aliases in Finder except they don't contain the path to the the original file. Hard links appear as regular files within Finder; you will not know you are not working with the original file, rather the linked one. Hard links are what ln creates by default when you omit the -s flag.

For further details, I have written about this more in depth on this answer.

The bottom line here is that you will only be able to create symlinks and hard links in Terminal (UNIX environment of OS X) but use them globally. You will only be able to create and use aliases within Finder. (IMO) Because of this, I stay away from aliases and use symlinks pretty much exclusively.

-1

I had this problem. Tried saving the link to a different folder. With a bit of trial and error it worked. No idea why.

You must log in to answer this question.

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