3

The readlink utility on recent macos versions (I'm on ventura) support the "-f" switch, but that has not always been the case. I note, for example, that it's NOT present on 11.6. Which was the first version of macOS to support this?

1 Answer 1

8

The earliest version where readlink -f appears in man pages is macOS Monterey 12.3.


The following excerpts were taken from the stat.1 file for macOS 12.2.

SYNOPSIS

readlink [-n] [file ...]

DESCRIPTION

When invoked as readlink, only the target of the symbolic link is printed. If the given argument is not a symbolic link, readlink will print nothing and exit with an error.


The following excerpts were taken from the stat.1 file for macOS 12.3.

SYNOPSIS

readlink [-fn] [file ...]

DESCRIPTION

When invoked as readlink, only the target of the symbolic link is printed. If the given argument is not a symbolic link and the -f option is not specified, readlink will print nothing and exit with an error. If the -f option is specified, the output is canonicalized by following every symlink in every component of the given path recursively. readlink will resolve both absolute and relative paths, and return the absolute pathname corresponding to file. In this case, the argument does not need to be a symbolic link.


How to Verify This Answer

The output below is from macOS Catalina 10.15.7.

  1. Enter to command man -w readlink to determine the file name of the man page to download. The output is shown below.
    /usr/share/man/man1/stat.1
    
  2. Enter the command which readlink to get the full path to the command. The output is below.
    /usr/bin/readlink
    
  3. Use the full path to enter the command what /usr/bin/readlink. The output (shown below) can be adapted to find the appropriate stat.1 file.
    /usr/bin/readlink
        PROGRAM:stat  PROJECT:file_cmds-287.100.2
    
  4. Goto Apple Open Source Releases to download the appropriate stat.1 file for the desired version of macOS.
  5. Enter the command man ~/Downloads/stat.1 to view the formatted version of the stat.1 file.
5
  • If you access the Open Source site anyway, you could as well check the source code directly (the man page can also be wrong).
    – nohillside
    Sep 11, 2023 at 11:06
  • 1
    @nohillside: I suppose if you did not what to trust the man page, you could look at the source code. However, my experience has been source code will often contain so many conditional preprocessor directives that just reading the source code to verify would be difficult. I would instead suggest to actually compile and link to get an executable. Personally, I would verify the man page by downloading the appropriate version of macOS and install in a virtual machine. Of course, being able to create an executable or virtual machine depends on which model/year Macs you have at your disposal. Sep 11, 2023 at 11:38
  • The first build to include -f is file_cmds-353.100.22, better known as macOS 12.3 :-) OTOH, the readlink functionality was present long before there was a man page for it (already in Tiger).
    – nohillside
    Sep 11, 2023 at 17:36
  • @nohillside: I assume you mean readlink. I am not sure if you are saying Tiger has or does not have a man page for readlink. I downloaded stat.1 for OS X Tiger 10.4 and found readlink. So I think there is a man page in Tiger for readlink. Sep 12, 2023 at 1:02
  • I meant readlink. And indeed, while the Tiger source code doesn't have readlink.1 the Makefile creates it out of stat.1.
    – nohillside
    Sep 12, 2023 at 5:39

You must log in to answer this question.

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