Search code examples
bashlast-modifieddata-integrity

Finding modified files in a directory through checksum


I have created two files, one with the checksum of all the individual files in the folder, the other with the individual checksum of all the files in the same folder after some modification (addition, deletion, and modification). I need to find out the files that have been modified during the second run of the checksum command.

I have tried using the comm command.

comm -23 firstfile secondfile | awk '{print $2}' |sort > added.txt
comm -23 secondfile firstfile | awk '{print $2}' |sort > deleted.txt

I am trying to find a way I can find the files that have been modified.


Solution

  • md5sum *.txt > sum1
    
    md5sum *.txt > sum2
    
    diff sum1 sum2
    

    Checksums are not a great way to monitor changes because they're limited to the checksum difference.

    If you want to act on file system events, you could use use inotify (http://man7.org/linux/man-pages/man7/inotify.7.html)

    If you just want to watch events, you could use iwatch (http://iwatch.sourceforge.net/documentation.html) in order to detect changes in a directory. An alternative to this is watchman which is developed by fakebook (https://www.tecmint.com/watchman-monitor-file-changes-in-linux/)