md5 all files in a directory tree

前端 未结 6 1723
庸人自扰
庸人自扰 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:26

    How about:

    find /path/you/need -type f -exec md5sum {} \; > checksums.md5

    Update#1: Improved the command based on @twalberg's recommendation to handle white spaces in file names.

    Update#2: Improved based on @jil's suggestion, to remove unnecessary xargs call and use -exec option of find instead.

    Update#3: @Blake a naive implementation of your script would look something like this:

    #!/bin/bash
    # Usage: checksumchecker.sh 
    find "$1" -type f -exec md5sum {} \; > "$1"__checksums.md5
    

提交回复
热议问题