1

Some macOS installations include the Unix realpath command and some do not. I haven't been able to discern an accurate pattern of which versions have it.

I'm on an M1 Air with Monterrey 12.6 and Xcode 13.4.1 and I do not have it. (I am also not using Homebrew.) I also don't have access to any other Macs.

I'm trying to find out whether this realpath resolves Apple's new "firmlinks" which are a feature of the APFS filesystem.

An example of a firmlink is /System/Volumes/Data/Applications which links to /Applications

To test your system you can enter these commands in your Terminal:

  • which realpath
  • realpath /System/Volumes/Data/Applications

(Note that the ls command does not report firmlinks no matter what switches you use.)

hippietrail
  • 1,344

1 Answers1

2

No, it doesn't.

imac:barmar $ realpath /Applications
/Applications
imac:barmar $ realpath /System/Volumes/Data/Applications
/System/Volumes/Data/Applications
Barmar
  • 1,557
  • 1
    And I think it would be very surprising if it did. The POSIX/Unix executables distributed with macOS are agnostic about the underlying file system. Firmlinks (and directory hard links), unlike symbolic and file hard links, are apply only to specific Apple file systems. – Gilby Nov 05 '22 at 22:46
  • 1
    I don't think that's entirely true. ls will show a special flag if the file has MacOS attributes, cp has an option to preserve extended attributes and resource forks. – Barmar Nov 06 '22 at 00:43
  • For anyone interested, I got here because I'm learning Swift, Zig, and Rust and wrote some code using the default directory walker of each language's std lib. They behave differently. Swift's doesn't follow firmlinks while Rust's and Zig's do. Rust's uses the system realpath while Zig implements its own realpath which does resolve firmlinks. I'm investigating which ones are doing it right or wrong or lack way to detect firmlinks to avoid duplicate dir traversals like Swift does. – hippietrail Nov 06 '22 at 06:18
  • @Gilby: Are you sure? There is source for some older versions of Mac realpath and they seem pretty involved. I'm not an expert however. – hippietrail Nov 06 '22 at 06:19
  • 1
    @hippietrail I was basing my thoughts on the layering of functionality in all OS - not on any detailed knowledge! The BSD/Posix/Unix layer sits above any specifics of file systems. So is unlikely to know about firmlinks (APFS) or Directory Hardlinks (HFS+). – Gilby Nov 06 '22 at 08:03
  • 1
    @Barmar This is all a bit rubbery/waffly on my part, but I don't think ls may not be a counter example of my argument. xattrs are present on other Unix and linux OSs so I would expect macOS ls to know about them. But this is a side discussion - you have provided the correct answer and now has a tick and 2 votes -presumably hippietrail and me! – Gilby Nov 06 '22 at 08:11
  • @Gilby I don't see the -@ in Linux ls, but it's in the MacOS version. – Barmar Nov 07 '22 at 03:35
  • -alO@ is the most verbose set of switches for the macOS variant of ls as far as I know, and it does not tell us anything about firmlinks. – hippietrail Nov 07 '22 at 14:52
  • @hippietrail I never said it did. It was just an example of Apple customizing standard Unix utilities for Mac-specific features, specifically extended attributes. – Barmar Nov 07 '22 at 15:59
  • @Barmar Sorry didn't mean to imply you did. Just wanted it to be in the thread here. – hippietrail Nov 08 '22 at 12:55