2
$\begingroup$

The MacOS uses unique numbers (Catalog Node IDs, aka CNIDs) to identify files and directories. Is there any way to obtain (read) CNIDs from within Mathematica?

$\endgroup$
0

1 Answer 1

3
$\begingroup$

FileInformation["pathToFile"] returns an "Inode" ->nnn among other things, which is the old Unix name for the file id number. I guess it's the same thing. I get the same number that is listed with ls -i in a Unix shell.

FileInformation[] appears to be undocumented. The data returned includes everything given by fstat().

$\endgroup$
2
  • $\begingroup$ Excellent, thank you. Here's the "other half" of the question: GIven an Inode, is there a way to (a) obtain the file's pathname, or (b) open the file (assuming permissions allow)? If FindFile would accept integers in addition to strings, that would be ideal (but it doesn't). $\endgroup$ Commented Dec 1 at 23:28
  • 1
    $\begingroup$ @JamesStein A file is linked to an inode through an entry in a directory, from which the pathname is derived. More than one file can be linked to the same inode. There is no reverse index. You can search an entire filesystem, but that probably takes too long to be practical. If you know it's contained in a directory or its subdirectories, then Run["find <dir> -inum <inode> -print > /tmp/out.txt"]; filename=First@Import["/tmp/out.txt", "Lines"], where <dir> is the pathname of the directory and <inode> is the id number, should find it. find is a Unix command you can test in a terminal. $\endgroup$
    – Michael E2
    Commented Dec 2 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.