在Linux中检测移动或重命名文件的最佳方法? [英] Best approach to detecting a move or rename to a file in Linux?

查看:101
本文介绍了在Linux中检测移动或重命名文件的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些解决方案可能适用于Windows,但是我对Windows操作系统并不熟悉,因此将重点关注Linux.

Some solution could probably be applicable to Windows, however I am not familiar with the Windows OS, so this will be Linux focused.

据我了解,Unix文件系统都具有inode的概念,即文件系统元数据和文件"的存储位置.因此,我想知道是否可以将inode编号与一些其他信息一起使用来跟踪被重命名或移动的文件?

As far as I understand, Unix file system all have the concept of inodes, which is where the file system metadata and the "file" is stored. Thus I am wondering if it is possible to use the inode number with some additional information to track files that are renamed or moved around?

我打算做的是进行一个初始扫描,该扫描将创建一个文件名/路径,位于其上的磁盘/驱动器,其inode编号以及最后某种校验和(sha-1)的数据库.

What I was proposing to do was have an initial scan that would create a database of filename/path, their disk/drive that it is located on, their inode number, and finally some sort of checksum (sha-1).

这将使系统能够使用inode编号快速检测文件是否被移动或重命名,然后跟着校验和检查其是否实际上是同一文件.

This would enable the system to be able to use the inode number to quickly detect if a file got moved or renamed, then it would follow up with the checksum to check to see if its actually the same file.

我可以看到此方案可能存在的问题:

I can see some possible problems with this scheme:

  1. 可以修改文件然后将其移动/重命名,由于校验和不匹配,因此无法检测到文件.
  2. 某些(最多?)应用程序在修改文件时会创建一个新的临时文件,然后将其与当前文件切换,因此即使文件最后未经修改,inode也不会匹配.
  3. 由于每个文件系统上的inode对该文件系统都是唯一的,因此需要存储它所在的设备/文件系统.
  4. 需要处理硬链接

我想知道是否在这里忘记了其他陷阱?我希望能够使用inode来快速跟踪哪些文件被移动或重命名,然后再进行校验和以确认它实际上是同一文件.

I am wondering if there is any other gotchas that I am forgetting about here? I was hoping to be able to use the inodes to quickly track down which files got moved or renamed, then follow up with a checksum to confirm that it is actually the same file.

推荐答案

查看inotify,当任何人对指定文件系统或目录中的文件进行任何操作时,该呼叫都将允许您拨打电话.

Look into inotify which allows you to get a call when anybody does anything to files in a specified file system or directory.

这篇关于在Linux中检测移动或重命名文件的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆