33

I have two aliases in my home directory: devbootcamp and bookshelf. I can cd into devbootcamp but not bookshelf but I'm not sure why. I don't remember how I made the alias to devbootcamp but I followed this tutorial to create the bookshelf alias. Also strangly in my terminal devbootcamp is purple but bookshelf is not. How do I make it so they have the same functionality?

enter image description here

3

1 Answer 1

44

If you are trying to cd into an alias, it will not work; this is by design as an alias works at the Finder level, not the underlying UNIX level.

I have excerpted some of the key aspects of aliases, symbolic links (symlinks), and hard links from the article "What Are Aliases, Symbolic Links, and Hard Links in Mac OS X?" below.


Aliases

This type of shortcut is the oldest for the Mac; its roots go all the way back to System 7. Aliases are created and managed at the Finder level, which means that if you're using Terminal or a non-Mac application, such as many UNIX apps and utilities, an alias won't work. OS X seems to see aliases as small data files, which they are, but it doesn't know how to interpret the information they contain.

Symbolic Links

This type of shortcut is part of UNIX and Linux file systems. Because OS X is built on top of UNIX, it fully supports symbolic links. Symbolic links are similar to aliases in that they are small files that contain the pathname to the original object. But unlike aliases, symbolic links don't contain the inode name of the object. If you move the object to a different location, the symbolic link will be broken, and the system won't be able to find the object.

Hard Links

Like symbolic links, hard links are part of the underlying UNIX file system. Hard links are small files that, like aliases, contain the original item's inode name. But unlike aliases and symbolic links, hard links don't contain the pathname to the original object. You would typically use a hard link when you want a single file object to appear in multiple places. Unlike with aliases and symbolic links, you can't delete the original hard-linked object from the file system without first removing all hard links to it.

What works in both Terminal & Finder

Just create a symlink in Terminal

ln -s <path to some folder> <destination of link>

For example, on my Desktop, I created a symlink to my /Volumes folder

ln -s /Volumes /Users/allan/Desktop/Volumes

On my Desktop, I got this icon automagically:

enter image description here

You can even give it a different name:

ln -s /Volumes /Users/allan/Desktop/Stuff

And automagically...

enter image description here

3
  • Great explanation. It helped me to think about it abstractly ln -s [what/dir] [to/where] Commented Dec 20, 2018 at 17:02
  • 1
    Please note that if terminal access is not a necessity, always use the mac alias counter part instead. This is because it also tracks the location of the linked file, updating itself automatically. Try running mkdir a b; cd b; ln -s ../a .;, then move the original directory of a to else where. The symbolic link will corrupt. Now repeat for mac alias, it will work.
    – ed9w2in6
    Commented Jul 29, 2020 at 23:28
  • @ed9w2in6 - Please note that if terminal access is not a necessity.... The entire premise of the question is about Terminal access. You don't cd using Finder, do you?
    – Allan
    Commented Jul 30, 2020 at 0:18

You must log in to answer this question.

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