Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Creating Hard Links

Working with OSX Mojave and have done endless searches for information about creating hard links. Everything I can find goes back years, and nothing has worked so far. Has the ability to create hard links (via Terminal) been done away with or is it still viable? Any help would be appreciated. Thank you.

iMac 21.5″ 4K, macOS 10.14

Posted on Jul 19, 2020 9:16 AM

Reply

Similar questions

10 replies

Jul 19, 2020 11:19 AM in response to VikingOSX

ln '/path/to/existing/file'  '/path/to/new/hardlink/filename'


That is lowercase L and lowercase N. Original Bell Labs UNIX developers liked short command names, so we get ls, ln, ed, rm, cp, etc...


If there is white space in the file path, then you will need to quote the path so the white space is protected.


PS. I did not mean to reply to VikingOSX, but I fumble fingered my reply.

Jul 19, 2020 2:07 PM in response to MargeHomer

Any Unix/Linux based information on creating a hardlink will apply to macOS


Also there are symbolic links as well (the ln -s ...)


macOS also has GUI level Aliases, and Catalina introduces a thing called "Synthetic Firmlinks"


Hardlinks, symbolic links, Aliases and Synthetic Firmlinks are all similar and totally different.


Hardlinks are directory entries that point to a file's metadata using file system internal file identifiers (often called an inode). Think of a directory entry as an address book entry pointing to a family member. The address book entry is not your family member, and if other family members have address book entries to the same person, you do not get extra family members. And if someone throws away their address book, your family member is not affected.


A Hardlink is a file system abstraction and can be used by any program, app, process on macOS.


A hard link does not care if you rename the any of the directory entries that point to the same file. That does not affect the file system internal file identifier. In fact the file itself does not know its name. The file itself only knows its file identifier. Names only exist in directories. The file itself does maintain a reference count for the total number of hardlinks that point at it. when a hardlink is deleted, the reference count is decremented. When the reference count goes to zero, the file is deleted (good thing address books do not have reference counts 😀


A symbolic link is a file that contains a file system path to the real file. Like writing down directions to the Taco Stand. If the Taco Stand moves, the symbolic link will not know it moved, and will not find it. In fact, if the Taco Stand changes it name, but is in the same place, the symbolic link will not find it. Symbolic links can contain absolute path information, or they can have relative path information, as in go up 2 directories, then down this subdirectory tree to this file kind of relative paths.


A symbolic link is also a file system abstraction and can be used by any program, app, process on macOS.


A macOS Alias is used by macOS GUI applications that use the file manager GUI framework. An Alias contains the internal file indentifier, but it does not increment the hardlink ref count. An Alias also contains a path to the file. So if the file is moved, the internal file system identifier can still find it. If the file is deleted, and a new file with the same name is put back in its place, the Alias path can find it (this is a common GUI app trick; save the file as a temp file, delete the original, rename the temp file to the original name; this changes the internal file system identifier). An Alias also knows if the file came from a network volume, and will attempt to reconnect to the network attached volume if you access the file via the Alias. An Alias may also have its own Icon (which can make an Alias a very large file).


Because an Alias is a GUI file manager framework abstraction, it is ONLY available to GUI applications, or programs that intentionally like against the file manager framework and use its file system access routines.


Synthetic Firmlinks are new in Catalina, and macOS uses them to glue together the Read-Only "Macintosh HD" volume and the Read/Write "Macintosh HD - data" volume. On a Catalina system "man synthetic.conf". You can also read about firmlinks at

https://derflounder.wordpress.com/2020/01/18/creating-root-level-directories-and-symbolic-links-on-macos-catalina


NOTE: Hardlinks have existed on Unix based file systems since the early Bell Labs UNIX back in the '70's. Symbolic links came our of the UC Berkley (BSD) UNIX implementation. macOS Aliases have been around for awhile, at least since the '90, maybe even the late 80's. macOS Firmlinks are new in Catalina 10.15.

Jul 19, 2020 11:57 AM in response to MargeHomer

You’ll probably not want to try to use file system links with a remote file share, Dropbox or otherwise. Thar’s probably not a place where you’ll want to start your adventure.


The -Ffhinsv stuff is a list of the switches (controls, options, etc) available within the ln tool.


The command man ln will show the details of the ln command.


Other examples:


man man
man ln
man grep
apropos ln
apropos find



Some docs:

https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/CommandLInePrimer/CommandLine.html

https://www.tldp.org/LDP/Bash-Beginners-Guide/html/


Apple’s version of bash is very old, and Apple has switched the default command shell from bash to zsh with Catalina.

https://scriptingosx.com/2019/06/moving-to-zsh/


So... many... Digits... Here... 🤪 Oh, and 1984? That probably makes you the n00b. 😉

Jul 19, 2020 11:40 AM in response to MargeHomer

Thank you to VikingOSX and BobHarris. Looks pretty similar to the Windows cmd: mklink /h "Link" "Target" which I was able to use on my Windows laptop.


Bob, when I did the Terminal help for ln this is what I got back:


Marges-iMac:~ margehomer$ man

What manual page do you want?

Marges-iMac:~ margehomer$ ln

usage: ln [-Ffhinsv] source_file [target_file]

ln [-Ffhinsv] source_file ... target_dir

link source_file target_file


So your explanation helped as I don't have any idea what the "[-Ffhinsv]" is about, although it seems it's not even needed in the Terminal input.


Possibly, I'm having issues because I'm trying to link to a couple of files that are in my Dropbox and I keep getting the response from Terminal that the Dir/File does not exist. Yet, if I copy that same file to my Documents folder and try linking that, it works!


Spending time (retired, sheltering in place and bored to death) playing with both my iMac and Windows laptop. Keeps the brain cells from dying off. Been at this for a while, purchased my first Macintosh (remember those?) way back in 1984!

Creating Hard Links

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.