md5 all files in a directory tree

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

    Updated Answer

    If you like the answer below, or any of the others, you can make a function that does the command for you. So, to test it, type the following into Terminal to declare a function:

    function sumthem(){ find "$1" -type f -print0 | parallel -0 -X md5 > checksums.md5; }
    

    Then you can just use:

    sumthem /Users/somebody/somewhere
    

    If that works how you like, you can add that line to the end of your "bash profile" and the function will be declared and available whenever you are logged in. Your "bash profile" is probably in $HOME/.profile

    Original Answer

    Why not get all your CPU cores working in parallel for you?

    find . -type f -print0 | parallel -0 -X md5sum
    

    This finds all the files (-type f) in the current directory (.) and prints them with a null byte at the end. These are then passed passed into GNU Parallel, which is told that the filenames end with a null byte (-0) and that it should do as many files as possible at a time (-X) to save creating a new process for each file and it should md5sum the files.

    This approach will pay the largest bonus, in terms off speed, with big images like Photoshop files.

提交回复
热议问题