问题描述
我想索引文件在本地数据库,但我不明白我怎么能识别每个单独的文件。例如,如果我将文件路径存储在数据库中,那么如果文件被移动或删除,条目将不再有效。我想有一种方法可以唯一地识别文件,不管发生在他们身上的事情发生了什么,但是我对Google没有任何成就。这将用于* nix / Linux和ext4所以请特别注意windows或ntfs或类似的东西。
可能会考虑使用文件的inode number属性,在shell中可以看到 ls -i
。 使用索引.php在我的一个箱子里:
$ b $ p $ l $ c $ ls -i
产生
196237 index.php
mv index.php index1.php 重命名文件,之后相同的
ls -i
: 196237 index1.php
inode号码是相同的)
I'd like to index files in a local database but I do not understand how I can identified each individual file. For example if I store the file path in the database then the entry will no longer be valid if the file is moved or deleted. I imagine there is some way of uniquely identifying files no matter what happens to them but I have had no success with Google.
This will be for *nix/Linux and ext4 in particular, so please nothing specific to windows or ntfs or anything like that.
In addition to the excellent suggestion above, you might consider using the inode number property of the files, viewable in a shell with ls -i
.
Using index.php on one of my boxes:
ls -i
yields
196237 index.php
I then rename the file using mv index.php index1.php
, after which the same ls -i
yields:
196237 index1.php
(Note the inode number is the same)
这篇关于唯一标识文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!