2

I need to send someone a 10GB file that has inside several thousands of files. I know that in Ubuntu you can use the next command in the terminal: md5sum <directory_name> and this returns a hash.

I am using Windows 11 and I have tried several things:

  • First I tried calculating the hash of just one file: CertUtil -hashfile .\file.png MD5 and this returned me a hash value.
  • Then I tried the same but with all the directory containing al the files: CertUtil -hashfile "path_to_directory\*" MD5 but I get an error.

Error:

CertUtil: -hashfile error del comando: 0x80070002 (WIN32: 2 ERROR_FILE_NOT_FOUND)
CertUtil: El sistema no puede encontrar el archivo especificado.

What should I do?

Destroy666
  • 5,299
  • 7
  • 16
  • 35
Linux
  • 35
  • 4
  • @MikeNakis Sorry I forgot posting the error message, I edited the question –  May 02 '23 at 09:23
  • Do you want a hash for every file or one hash for all of them? – gronostaj May 02 '23 at 09:45
  • @gronostaj one hash for all of them – Linux May 02 '23 at 09:56
  • 1
    Hello, why not just zip the folder then and calculate the hash for the zip? I'm not quite following this question and why are you doing what you're doing. – Destroy666 May 02 '23 at 10:47
  • @Destroy666 if i zip the file i can get the hash with no problem, but once its zipped some information could have been lost so that is why I want the hash without ziping the file, so my teammate can unzip it and check that everything is okay – Linux May 02 '23 at 10:55
  • 3
    I see, zipping is lossless though, so not sure where the worry is coming from. – Destroy666 May 02 '23 at 11:07
  • If you're concerned about reliability of unzipping, then are you already using a checksumming filesystem and ECC memory? – gronostaj May 02 '23 at 11:39
  • "I know that in ubuntu you can use the next command in the terminal: `md5sum ` and this returns a hash." – Either it's a relatively new feature or [you are wrong](https://unix.stackexchange.com/q/35832/108618). – Kamil Maciorowski May 02 '23 at 12:06
  • How do you define "the hash value of a directory"? Is it the hash value of the directory entry itself? If yes, how are you encoding the directory entry? Is it the hash value of the concatenation of all files in the directory? If yes, what order are the files concatenated in? Do you want to include any metadata? If yes, how is the metadata encoded? – Jörg W Mittag May 02 '23 at 15:47

1 Answers1

0

You can do it with PowerShell, for instance:

$hashString = (Get-ChildItem C:\Somedir -Recurse -File | Get-FileHash -Algorithm MD5).Hash | Out-String
(Get-FileHash -Algorithm MD5 -InputStream ([IO.MemoryStream]::new([char[]]$hashString))).Hash

Source, I modified it slightly to only get hash from files (otherwise a bunch of errors for subdirs appear) and just return the hash.

This basically gets all file hashes recursively, prints them to one string, then creates a temporary stream from that string and calculates its hash.

Alternatively, output the hashes string to a file with > operator ($hashString > file.txt) and then compare files.

Destroy666
  • 5,299
  • 7
  • 16
  • 35