简体   繁体   English

怎么知道文件在linux被修改了

[英]How to know the file is modifed in linux

I want to know what system call is used in linux C programming is used to know whether a file is modified.我想知道linux用什么系统调用 C编程是用来知道一个文件是否被修改的。 I know that make utility compiles the file using the modification dates only.我知道 make 实用程序仅使用修改日期编译文件。 I want know how to find whether the file is modified or not.我想知道如何查找文件是否被修改。

Thanks in advance提前致谢

Using md5sum or sha1sum will hash the contents of the file, which should give you a better indication of actual changes than modification dates.使用md5sumsha1sum将 hash 文件的内容,这应该比修改日期更好地指示实际更改。

stat(2) gives you file times and more.stat(2)为您提供文件时间等等。

Edit 0:编辑0:

You can look into fcntl(2) and F_NOTIFY flag - you'd have to open the directory, not the file itself though.您可以查看fcntl(2)F_NOTIFY标志 - 您必须打开目录,而不是文件本身。 Or the newer Linuxinotify(7) facility.或者更新的 Linuxinotify(7)工具。

You can use ls and various flags on it, like -l or -t and pipe to grep or something.您可以在其上使用ls和各种标志,例如 -l 或 -t 和 pipe 到grep或其他东西。 That will tell you when the last file was modified.这将告诉您最后一个文件何时被修改。 But it doesn't really tell you if the file was modified.但它并没有真正告诉文件是否被修改。 I think the only real way you can know that is if you are keeping track of when the last time it was modified in general (like checking from backups or something).我认为你能知道的唯一真正的方法是你是否在跟踪上次修改它的时间(比如检查备份或其他东西)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM