Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A brief tutorial on symbolic links UNIX
OS X's file structure mounts all partitions under the "/Volumes" directory at the root level of the filesystem. However, when navigating the filesystem with "cd" and other commands, it can be annoying to type "/Volumes/volume_name" each time you want to access a different partition. To learn about symbolic links and use them to add shortcuts at the root level of your filesystem, read the rest of this article. This assumes you are moderately comfortable in the Terminal, and that you have administrative privileges.

What is a Symbolic Link?
If you've ever made an "Alias" to a file in classic Mac OS, or a "Shortcut" to a file in Windows, you will easily be able to understand the UNIX equivalent (where "aliases" and "shortcuts" came from in the first place!), called a "Symbolic Link". The easiest definition to understand is directly from the man page, "[A Link] is useful for maintaining multiple copies of a file in many places at once without using up storage for the 'copies'; instead, a link 'points' to the original copy." (If you want to read more about it, type man ln in the Terminal.)

Let's say you have two partitions or drives - "X" containing OS X and "Classic" containing OS 9. To navigate to "X", you simply type
cd /
To navigate to "Classic", though, you'd have to type
cd /Volumes/Classic
If you have many partitions and/or drives, and you are trying to manage many files across them, it can get annoying to type "/Volumes" every time. Moreover, you cannot simply create an Alias to the drive/partition to accomplish this because the command line utility "cd" does not handle Mac OS aliases properly. However, a symbolic link will solve the problem.

To create the link, simply type the following:
cd /
ln -s /Volumes/Classic/ Classic
That's it. ln -s makes a new file called Classic which points to /Volumes/Classic/. To see that this worked, you can simply type
ls -la | more
(note the "|" character is called "pipe" and is found above the "Return" key). You should see a line with the following text:
Classic -> /Volumes/Classic/
The arrow shows you exactly what you did... A file named Classic points to /Volumes/Classic.

Links have many possibilities around the filesystem, and I encourage you to read more about them in the man page. While command line utilities cannot recognize Mac OS aliases, the Mac OS Finder will recognize symbolic links you construct in the terminal, or via Third-Party Utilities such as SNAX so you can use links just like aliases in the Finder.

  • Currently 3.59 / 5
  You rated: 4 / 5 (17 votes cast)

A brief tutorial on symbolic links | 13 comments | Create New Account
Click here to return to the 'A brief tutorial on symbolic links' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
re: symbolic links/aliases
Authored by: rusto on Nov 06, '01 01:57:31PM
thx for the tip, while fiddling with symbolic links and comparing them to the traditional Mac way of making aliases (command-option-drag) I discovered that the terminal-created symbolic link may be smaller. Do this: make an alias of a folder in the finder then make a symbolic link of that same folder. Then look at the file size in Get Info. I'm not exactly sure what the second figure is but I see this: Finder alias: Symbolic link: Note that while their size "on disk" are both 4k, the symbolic link has only 9 bytes to the right of that while the alias has 650 bytes. Does anyone know what this second figure represents?

[ Reply to This | # ]
re: symbolic links/aliases
Authored by: jmil on Nov 06, '01 02:25:19PM
This has to do with the HFS+ file structure. HFS+ has a minimum file size of 4KB. This means that any file you create (even a text file with just the letter "a", only 1 byte large) will take up a minimum block of 4 kilobytes. Isn't this inefficient? Well, yes and no. It's inefficient because you have wasted space. However, it makes finding files easier (because the blocks of data are much larger than one byte), and nearly all files in the old Mac OS were much larger than 4 KB anyway. Now with OS X, we have several hundred thousand files, but most are still larger than 4KB and the cost of hard drives is so amazingly cheap now that it wouldn't matter anyway. I hope that helps to clear things up.


[ Reply to This | # ]
re: symbolic links/aliases
Authored by: normcook on Nov 06, '01 02:27:24PM

that size in bytes is how much space the file really needs. however, the smallest amount of space that can be allocated for something is 4k. so 9 bytes or 650 bytes, it is going to use 4k of disk space.

[ Reply to This | # ]
re: symbolic links/aliases
Authored by: russoedu on Apr 26, '10 03:08:52AM
Aliases and Symbolic Links differs in lots of things. SymLinks just points to the original file location, so, if you move the original, it will not find it! Aliases points in a "magic" way that allways find the original, even if you move it or rename it. I had a big discussion about this with A. S. Tanembaun!!! And even him could tell how Mac Alias work, it's really a big magic to always point to the right place. That's why Alias files are bigger that SymLinks. Hardlinks, on the other way, points to the "node" (you have to understand how HFS+ works to understand this deeply) of the original file, so it IS the original file. That's why when you check it's size, it will look like the original. But the magic is that it does not take more file space than the original! You can test this in a big video file: do a HardLink and check how much of your disk was taken. Probably only 4kb (of HFS+ minimum file size). I made a video about Aliases to show to Tanembaun how it works: YouTube video link

[ Reply to This | # ]
How to hide your links.
Authored by: serversurfer on Nov 06, '01 03:13:03PM
By *NIX convention, file whose name begins with a period are 'hidden'. The Finder honors this, so if you name your link '.Classic', instead of 'Classic', you won't see an alias to Classic when you look in your 'X' volume in the Finder or when you ls /. (use ls -a /)

Bonus Tip!:
This will add a character you have to type when you cd, but if you use the right naming convention, you can use tab-complete to make it faster than ever! Do this:

cd /
ln -s /Volumes/Classic .qclassic
cd ~
cd /.qc

The last line means type '/.qc' then press tab (with no space in between). I prefixed the volume name with 'q' because it stands for 'quick' and no other files there are likely to be called .qsomething. I used a lower case 'c' because tab-complete is case-sensitive by default.

[ Reply to This | # ]
yet another way...
Authored by: charlietuna on Nov 06, '01 03:36:31PM

this provides similar functionality, but not exactly the same. i prefer it because it keeps my root folder uncluttered. as it is i already have enough "TheVolumeSettings" and "Desktop DB" stuff that makes it look unelegant... but to the tip:

in tcsh you can set a variable called "cdpath" that includes a list of directories which are searched whenever you "cd" to another directory. perhaps this also would apply to pushd as well.

currently, you can type "cd Music" anywhere in your filesystem and if you aren't in a directory that contains a directory named Music, you will be switched over to ~/Music. if you do this in your .cshrc:

set cdpath = (~/ /Volumes)

you can do the same thing. if you have a partition named Classic, you can type "cd Classic" and you'll be put at /Volumes/Classic. tab completion does not work here, so you'll have to type the full name yourself.

[ Reply to This | # ]
Authored by: foamy on Nov 06, '01 03:54:25PM

That was very cool. Using it already.

[ Reply to This | # ]
yet another way...
Authored by: jmil on Nov 06, '01 04:01:10PM


[ Reply to This | # ]
Important differences with aliases
Authored by: Anonymous on Nov 06, '01 08:11:50PM


* keep pointing to the same file/folder, even when it is moved
(although not when moved to a different partition / drive)
* store a separate copy of the icon and can have different icons
* not usable from the command line

sym links:

* just store the location of the original. If it moves, they break.
If something else of the same name is put there it now points to that.
* uses the icon of the original
* Did not use to work in Classic / OS9, but seem to now - is this a 9.2 change?

The most important bit of this to remember is that aliases are pointers to objects and
symbolic links are pointers to locations. For most tasks, I think aliases are thus more useful.


[ Reply to This | # ]
Important differences with aliases
Authored by: owain_vaughan on Nov 07, '01 06:21:23AM

Of course UNIX has an equivalent to aliases as well. Rather than using symbolic links you can use 'hard' links. Just use the ln command without the -s option and you will create a hard link. Same caveats as Mac aliases - only work on the same partition, but the cool thing is, both the 'original' and the new hard link are entirely equivalent. You can delete the original, but the file will still exist, because there is another 'link' to it. You can have as many hard links as you like, and as long as you have one the file will still exist.

[ Reply to This | # ]
A brief tutorial on symbolic links
Authored by: PicklePumpers on May 30, '10 01:51:11PM

Thank you so much! This is exactly what I needed.

Now I can share common interface and WTF folders among 2 computers and 4 copies of WoW! No more painfully long reconfiguration days when updates come out. Now I can just change it once and it's changed on all computers in all copies of WoW.

Thanks again!

[ Reply to This | # ]
A brief tutorial on symbolic links
Authored by: yangzone on Jul 04, '11 02:41:44AM

Will the App Store update an App that is represented by a symbolic link in the startup Applications folder even though the actual App is on another (always connected) drive?

[ Reply to This | # ]
A brief tutorial on symbolic links
Authored by: iciarch on Aug 27, '11 04:58:01PM

Questions and statements:

The reason for the organization of files and partitions is as follows, I am an Architect that utilized software that required Rosetta, and it will not be updated. So coming from the PC world about 4 years ago, I was used to partitioning for data and having software from any directory go there. SO I probably used the wrong logic, I hope not, since this all came about by migrating to a new machine (came with 10.6.8 installed).

I did the following:

Clone of old machine in Partition #1 - Intended to Install Lion into this one.
Clone of my PC Partition put in new Partition #2
Clone of Graphics Partition put in Partition #3-"DATA"
Migrated Old Macine into Partition #4 - Keeping Snow as woking partiton.

Wanted Both partitions to go after DATA in a third Partition, depending on what I booted into. All data stays coordinated and easily backed up.

All the following is happening with programs running in Partion #1 : pre-conversion to Lion.

I followed instructions and all went well. But I may have done something that this command does not allow. I moved all my data (Folder=ARCH) to a partition called "Data" in Partition #3. Removed "ARCH" folder from my documents folder in Partition #1. and did the Link.

Now the issues:
1. Running Parallels and my windows-7 Cad program; everything worked, getting my data loaded (from Partition #3) and getting Virtual files loaded from Partion #2.

Then went to Quicken for windows. Loaded files OK, but when I went to back them up Quicken could not see the new "ARCH" folder in Partiton #3. SO loading files worked but after , writing files did not work. ??????

2. Moved to Partition #4, a clone of Partition #1. Booted and went to do another link from this loaction to the "ARCH" data folder in Partition #3. All I got in the Finder was a "ARCH" folder with a round red dot, it was a empty folder. ???????

Was my logic wrong? Should I have loaded a clone of the "ARCH" folder/data into Partition #3 rather then moving it from partition #1, and then link it?

Been doing the since CPM as a operating system, but no experience in Unix/Apple.

Any info would be greatly appreciated.


[ Reply to This | # ]