Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

The fastest way is just to compare hash code of files having same size.
This is the idea of of this answer on SOanswer on SO (see the second command line and its explanations).

There is no security issue while detecting duplicated files, therefore I would recommend a fast hashing code. For instance the project ccache uses MD4:

ccache uses MD4, a very fast cryptographic hash algorithm, for the hashing. (MD4 is nowadays too weak to be useful in cryptographic contexts, but it should be safe enough to be used to identify recompilations.)

If two files have same size and same hash code, they are probably equal. But there will still be a little chance these two files are different (except if file size is less than hash code size).

As you imply in your question, false positive can happen more frequently as the file size is larger.

There are two options to fix the large files issue:

  1. Use a second hash code for large file (e.g. MD4 and MD5).
  2. Use a dynamic-length hash code

The limit to consider a file as enough large to require a second check depends on how critical is your application.

Finally, the safest way to proceed is:

  1. Detect files having same size
  2. If same size => compare their (already computed) hash codes
  3. If same size and same hash code => compare the full content

The fastest way is just to compare hash code of files having same size.
This is the idea of of this answer on SO (see the second command line and its explanations).

There is no security issue while detecting duplicated files, therefore I would recommend a fast hashing code. For instance the project ccache uses MD4:

ccache uses MD4, a very fast cryptographic hash algorithm, for the hashing. (MD4 is nowadays too weak to be useful in cryptographic contexts, but it should be safe enough to be used to identify recompilations.)

If two files have same size and same hash code, they are probably equal. But there will still be a little chance these two files are different (except if file size is less than hash code size).

As you imply in your question, false positive can happen more frequently as the file size is larger.

There are two options to fix the large files issue:

  1. Use a second hash code for large file (e.g. MD4 and MD5).
  2. Use a dynamic-length hash code

The limit to consider a file as enough large to require a second check depends on how critical is your application.

Finally, the safest way to proceed is:

  1. Detect files having same size
  2. If same size => compare their (already computed) hash codes
  3. If same size and same hash code => compare the full content

The fastest way is just to compare hash code of files having same size.
This is the idea of of this answer on SO (see the second command line and its explanations).

There is no security issue while detecting duplicated files, therefore I would recommend a fast hashing code. For instance the project ccache uses MD4:

ccache uses MD4, a very fast cryptographic hash algorithm, for the hashing. (MD4 is nowadays too weak to be useful in cryptographic contexts, but it should be safe enough to be used to identify recompilations.)

If two files have same size and same hash code, they are probably equal. But there will still be a little chance these two files are different (except if file size is less than hash code size).

As you imply in your question, false positive can happen more frequently as the file size is larger.

There are two options to fix the large files issue:

  1. Use a second hash code for large file (e.g. MD4 and MD5).
  2. Use a dynamic-length hash code

The limit to consider a file as enough large to require a second check depends on how critical is your application.

Finally, the safest way to proceed is:

  1. Detect files having same size
  2. If same size => compare their (already computed) hash codes
  3. If same size and same hash code => compare the full content
larger files
Source Link
oHo
  • 1.2k
  • 1
  • 8
  • 9

The fastest way is just to compare hash code of files having same size.
This is the idea of of this answer on SO (see the second command line and its explanations).

There is no security issue while detecting duplicated files, therefore I would recommandrecommend a fast hashing code. For instance the project ccache uses MD4:

ccache uses MD4, a very fast cryptographic hash algorithm, for the hashing. (MD4 is nowadays too weak to be useful in cryptographic contexts, but it should be safe enough to be used to identify recompilations.)

If two files have same size and same hash code, they are probably equal. But there will still be a little chance these two files are different (except if file size is less than hash code size).

As you imply in your question, false positive can happen more frequently as the file size is larger.

There are two options to fix the large files issue:

  1. Use a second hash code for large file (e.g. MD4 and MD5).
  2. Use a dynamic-length hash code

The limit to consider a file as enough large to require a second check depends on how critical is your application.

Finally, the safest way to proceed is:

  1. Detect files having same size
  2. If same size => compare their (already computed) hash codes
  3. If same size and same hash code => compare the full content

The fastest way is just to compare hash code of files having same size.
This is the idea of of this answer on SO (see the second command line and its explanations).

There is no security issue while detecting duplicated files, therefore I would recommand a fast hashing code. For instance the project ccache uses MD4:

ccache uses MD4, a very fast cryptographic hash algorithm, for the hashing. (MD4 is nowadays too weak to be useful in cryptographic contexts, but it should be safe enough to be used to identify recompilations.)

The fastest way is just to compare hash code of files having same size.
This is the idea of of this answer on SO (see the second command line and its explanations).

There is no security issue while detecting duplicated files, therefore I would recommend a fast hashing code. For instance the project ccache uses MD4:

ccache uses MD4, a very fast cryptographic hash algorithm, for the hashing. (MD4 is nowadays too weak to be useful in cryptographic contexts, but it should be safe enough to be used to identify recompilations.)

If two files have same size and same hash code, they are probably equal. But there will still be a little chance these two files are different (except if file size is less than hash code size).

As you imply in your question, false positive can happen more frequently as the file size is larger.

There are two options to fix the large files issue:

  1. Use a second hash code for large file (e.g. MD4 and MD5).
  2. Use a dynamic-length hash code

The limit to consider a file as enough large to require a second check depends on how critical is your application.

Finally, the safest way to proceed is:

  1. Detect files having same size
  2. If same size => compare their (already computed) hash codes
  3. If same size and same hash code => compare the full content
Source Link
oHo
  • 1.2k
  • 1
  • 8
  • 9

The fastest way is just to compare hash code of files having same size.
This is the idea of of this answer on SO (see the second command line and its explanations).

There is no security issue while detecting duplicated files, therefore I would recommand a fast hashing code. For instance the project ccache uses MD4:

ccache uses MD4, a very fast cryptographic hash algorithm, for the hashing. (MD4 is nowadays too weak to be useful in cryptographic contexts, but it should be safe enough to be used to identify recompilations.)