@ChennyStar mentions ZFS, but there are other, possibly better, or easier options (ZFS can be a heavy lift to use correctly)
Btrfs and ZFS do this, plus maybe otherss
- BtrFS supports a number of hashing functions for data integrity, some of which like SHA256, can also be used for data deduplication. Great filesystem, but less mature than something like Ext4 for production systems.
- XFS supports crc32 checksums of metadata ONLY
- Ext4 supports crc32 checksums of metadata ONLY, but requires enabling it Ext4 Metadata Checksums
- ZFS supports a few different hash algorithms, supports deduplication, and many modes of data redundancy, including single disks, multiple disks. It has a somewhat steep learning curve though, but it very mature.
DIY, simpler perhaps
You might also consider writing your own cron job etc to sha256 all your files, and keep track of their state, and alert you to issues. You could even pigeon-hole bolt this onto something like Ext4 by using extended attributes like this: setfattr -n user.checksum -v "3baf9ebce4c664ca8d9e5f6314fb47fb" file.txt - OR simple save it in a txt file somewhere. This way you fully control which files are checked, and the behavior. You can test this mechanism by taking a file and copy it, then corrupt one bit and see what happens. To corrupt one bit (which is surprisingly hard to do from CLI):
a=$(xxd -b -l 1 -seek 3 -p <original_important_file>);b=1;echo -e "\x$((${a}^${b}))" | dd of=<corrupted_important_file> bs=1 seek=3 count=1 conv=notrunc
I sourced and tweaked this script from @Kantium's answer