0

According to Apple's File System Programming Guide, macOS includes so-called UNIX-specific directories:

The directories in this category are inherited from traditional UNIX installations. They are an important part of the system’s BSD layer but are more useful to software developers than end users.

These are hidden to the user, and include /bin, /tmp, /dev, /usr, and more.

My question is: how can I identify these directories?

I notice that chflags has a UF_HIDDEN flag, which I thought might help, however while UF_HIDDEN is set on /bin and /dev, it is not set on /tmp (so it must not be set for all UNIX-specific directories). I was also wondering if mdls could help, as I notice the following:

kMDItemSupportFileType = (
    MDSystemFile
)

However, this value (MDSystemFile) is present on /bin/bash as well as many other files that are not UNIX-specific directories (as they are files). I thought it might be possible that the file is a UNIX-specific directory if the kMDItemSupportFileType contains MDSystemFile, and the file is a directory, however this theory also fell apart as MDSystemFile is not present for /tmp.

How can these UNIX-specific directories be identified?

9
  • 4
    What does „unix-specific“ mean, what is an example for a non-unix-specific directory? And what do you intend to do with the information once you can distinguish them?
    – nohillside
    Commented Sep 26, 2022 at 5:47
  • 1
    Also, the linked page seems to list them already, what more do you need to know?
    – nohillside
    Commented Sep 26, 2022 at 5:49
  • 1
    @nohillside The page states "Some of the more important directories that are hidden include," which implies that the listing is incomplete. Also on the page, "UNIX-specific" directories is defined by Apple: "UNIX-specific directories. The directories in this category are inherited from traditional UNIX installations. They are an important part of the system’s BSD layer." Once I have distinguished them, I will know that the directory is hidden from the user because it is a system directory. Commented Sep 26, 2022 at 8:45
  • 3
    Which practical problem are you trying to solve with this?
    – nohillside
    Commented Sep 26, 2022 at 9:38
  • 1
    @nohillside programmatically determine whether a file or directory is hidden in macOS. Commented Sep 26, 2022 at 11:58

2 Answers 2

2

To programmatically determine whether a file or directory is hidden in macOS, use the NSFileManager. This can be done via AppleScript, Objective-C, or Swift.

NSURLIsHiddenKey

Check if a file or directory has the NSURLIsHiddenKey attribute associated and that it is set to true:

Key for determining whether the resource is normally not displayed to users, returned as a Boolean NSNumber object (read-write).

Note that file and directory names beginning with a period (.) are hidden, regardless of this attribute.

Use a function such as NSFileManager's enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: to enumerate the file system and query the desired attributes.

Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified URL.

1

There's no technical distinction as such in play here. The term "UNIX-specific directory" is not a "thing" in terms of the macOS operating system.

The name only comes into play for Apple to explain what types of files and folders are hidden from view by the Finder program. So the actual definition of what it is, is simply how Finder works.

The best way to find the full list of files and folders hidden by Finder is to reverse engineer the Finder.app program.

0

You must log in to answer this question.

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