md5 all files in a directory tree

前端 未结 6 1660
庸人自扰
庸人自扰 2021-02-07 04:43

I have a a directory with a structure like so:

.
├── Test.txt
├── Test1
│   ├── Test1.txt
│   ├── Test1_copy.txt
│   └── Test1a
│       ├── Test1a.txt
│       └─         


        
6条回答
  •  逝去的感伤
    2021-02-07 05:40

    #!/bin/bash
    shopt -s globstar
    md5sum "$1"/** > "${1}__checksums.md5"
    

    Explanation: shopt -s globstar(manual) enables ** recursive glob wildcard. It will mean that "$1"/** will expand to list of all the files recursively under the directory given as parameter $1. Then the script simply calls md5sum with this file list as parameter and > "${1}__checksums.md5" redirects the output to the file.

提交回复
热议问题