HOM 14: Aliases, What Are They Good For?

Beep boop - this is a robot. A new show has been posted to TWiT…

What are your thoughts about today’s show? We’d love to hear from you!

3 Likes

I know that @Leo tried to keep it as simple as possible so that people that had never come across Unix shell wouldn’t be scared off, however, it led to inconsistent and partially incorrect information this time, so I’d like to pull that no-you’re-all-wrong-Leo-thing he keeps talking about on the Tech Guy and try to straighten it out.

First, the main thing an alias differs from a link is, the former works on the application layer (Finder, to be exact), whereas the latter is resolved by the filesystem. This distinction is crucial and has some serious consequences. You can use a link just like a regular file (well, in most circumstances) with every application that knows how to deal with files, while an alias needs Finder to substitute its name for the actual file path before a given program can open it.

The other thing I found misleading was saying that hard-linked files share a directory entry, which is incorrect. A hard link is essentially another directory entry referencing the same file (well, its i-node, to be exact), and those references are indistinguishable, so there is no original file nor its copy anymore.

Soft links and hard links also have different use cases. You should use soft links wherever you wanna create a “shortcut” to a file and perform all tasks you would normally do on the file it points to. A common practice in Unix is providing global configuration files or directories for different daemons that expect them in different places, and you don’t wanna (and neither should you) edit all copies of it, which would be necessary otherwise.

Hard links are often used to modify a program’s behavior depending on the name it’s invoked with. The most common example are different Unix shells, which share binary code, and run in a different way depending on what name they’re referenced with.

A caution must be used when hard links are writable. Since they’re indistinguishable, writing to either of them alters the same stream of data.

@Leo also mentioned the Time Machine using hard links in a fancy way to create backups. It actually uses file and directory hard links (the latter are not available on other Unices, since they may cause reference loops) to reference files that haven’t been changed since the last backup, and puts a copy of all modified ones. This virtually creates a fully independent directory structure containing all files for each backup but stores unchanged files on a disk only once; also, deleting any of those backups has no effect on the remaining ones.

Having said that, I’m just as biased on the command-line interface as @Leo is. I started with DOS and Unix 30 years ago, so this has always been the primary way for me to operate a computer. I find it extremely hard to introduce to it to anyone who’s only known different GUIs.