Search code examples
filedebiansambasmb

Is there a unique id for files?


I have the question How do you track files in SMB with an application? open and I was woundering whether maybe there are unique id's for files so that I can track when a file/folder is moved. Is there something like this? It can be very debian specific


Solution

  • The answer is as always 'it depends'. What do you mean with 'unique id'? Would this id change if the contents of the file is changed, or would you consider that as the same file? In Unix, the inode together with the device defines the 'unique id', but this is retained even if the content changes.

    If you want to now what touches a file, you can use inotify on the same machine to find out what happens to files (or its precursor: dnotify).

    If you need to have it accross machines, then I assume samba would use inotify to get notified and convert that to SMB/CIFS events, but I'm not familiar with that.

    If you want a content-based id and therefore use hashes, you need to go to userspace. For example, this is just exactly what Git (the version control system) does: it tracks the hashes of the contents to have a 'unique id'.