Monday, December 10, 2012

Symbolic link and alias in Mac.

In Mac OS X, you have two choices when you want to have a symbolic link: alias (Command L), and symbolic link (Shift-Command L).

PastedGraphic-2012-12-10-10-25.png

In a command line tools can understand symbolic link, not an alias. For GUI tools such as PathFinder, both of them will work. Automator however also works only with alias. It’s understandable thinking that symbolic link is a legacy from UNIX, so is command line tools. Automator is a legacy from Mac, so is alias.

You’ll notice that alias link is larger, which means has more information. An alias has two pieces of information: UID of the file that it links to, and the physical path and file name that it links to. As a result alias will understand the changes you make to the original file.

A symbolic link doesn’t contain the UID. As a result symbolic link will be shown as broken when you change the name of the file that it links to.

Demo

  1. Using “command-L”, I create an Alias. PastedGraphic1-2012-12-10-10-25.png
  2. Rename the progress directory as “progress_update”. PastedGraphic2-2012-12-10-10-25.png
  3. Click the “progress_update” to check Path Finder finds the linked directory correctly. PastedGraphic3-2012-12-10-10-25.png

And this is an example for symbolic link.

  1. Using “Shift-Command-L”, I create a symbolic link. PastedGraphic4-2012-12-10-10-25.png
  2. Change directory name. PastedGraphic5-2012-12-10-10-25.png
  3. Check Path Finder finds the link OK. PastedGraphic6-2012-12-10-10-25.png

For the command line tools, the alias is just a file (color in black), however the symbolic link is recognizable (color in pink).

PastedGraphic7-2012-12-10-10-25.png

And you can use command line tools for the change.

PastedGraphic8-2012-12-10-10-25.png

In short

  • Use symbolic link when you want to use command line tools, for example when you want to use Linux to login your mac account.
  • Use alias when you work with your mac, as it will understand your changes.

References

1 comment:

  1. Thanks for the post. I didn't know about the Command+L shortcut -- very useful!

    Unfortunately, Shift + Command + L to create a symbolic link doesn't work on newer macs (I'm running OSX 10.8.5). Seems like the only way to make them without using external software is to do it through terminal using
    ln -s [original folder name] [symlink folder name]

    ReplyDelete