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?
1 Answer
$\begingroup$
$\endgroup$
2
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()
.
-
$\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$ Commented Dec 2 at 2:11