bashmd5sha256md5sum

Is there a way of making an md5sum of all files in subfolders?


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


Solution

  • 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.