Are there any general solutions to check if a file is corrupt or not? For example, whether a video file is bad, or a compressed file is corrupt, etc.
|
No, there aren't any general solutions. The only way to check if a file is corrupt is to try and read it; only software which knows how to read that particular format can do that. What you could do is use
But you'd have a lot of work to do to fill out the case statement. It's possible that someone has already written such a script (or program), but i don't know of any. |
|||||||||||
|
|
If you know at some point in time the file is good, you can make a checksum of it and use it to compare later to make sure it's still whole. This is useful before transferring files between mediums or across networks. If you don't know about the good state of a file, no there is no universal way or checking for corruption. Only the specific file format in each case determines what is corrupt or not corrupt data. |
|||
|
|
|
If you happen to use ZFS, either you can read the file and it is guaranteed not being corrupted or you got a read error and it is. Edit After the wise comments, here is a clarification of my answer: ZFS can protect and detect against silent data corruption. eg: http://www.zdnet.com/blog/storage/data-corruption-is-worse-than-you-know/191 Of course if the file is already corrupted at the time it is initially written, there is nothing the file system can do. To protect against corruption that would happen during the transmission of the file, the usual general purpose techniques are md5sum or similar hashes. |
|||||||||||||
|
echo "P = NP" >is-this-corrupt.txt:) – Tom Anderson Jun 20 '11 at 10:57