skip to Main Content

I have several exports of telegram data and I would like to calculate the md5 and sha256 hash of all files but it only calculates those in the root directory

$ md5sum `ls` > hash.md5

md5sum: chats: Is a directory
md5sum: css: Is a directory
md5sum: images: Is a directory
md5sum: js: Is a directory
md5sum: lists: Is a directory
md5sum: profile_pictures: Is a directory

This is in the output file

7e315ce28aa2f6474e69a7b7da2b5886  export_results.html
66281ec07a2c942f50938f93b47ad404  hash.md5
da5e2fde21c3e7bbbdb08a4686c3d936  ID.txt

There is a way to get something like this out?

5750125fe13943f6b265505b25828400  js/script.js

Sorry for my english

3

Answers


  1. With bash:

    shopt -s globstar
    md5sum ** >/tmp/hash.md5
    

    Ignore errors of the kind: md5sum: foobar: Is a directory

    From man bash:

    globstar: If set, the pattern ** used in a pathname expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a /, only directories and subdirectories match.

    Login or Signup to reply.
  2. Alternatively, you can use find with -exec option:

    find topdir -type f -exec md5sum {} + > MD5SUMS
    

    Replace the topdir with the actual directory name, or drop it if you want to work on the current directory (and its subdirectories, if any). This will only compute the checksums of regular files (so, no "md5sum: something: Is a directory" errors), and won’t suffer from the "argument list too long" problem.

    Login or Signup to reply.
  3. A tool which helps, but might not be installed by default, is hashdeep.
    hashdeep does it directly and has some more advantages, e.g. binary is available for Windows, too.

    Your question would be answered using hashdeep with this command:

    hashdeep -c md5,sha256 -r -o f -l . > hash.md5
    

    This calculates md5 and sha256 of all files in all subdirs with one command.

    Creating md5 and sha256 together might be faster due to caching effects of the files. Additionally the command has an option to use multiple threads, which could fasten up the task with multi-core CPUs and fast disks.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search