Soroush Rabiei
Soroush Rabiei

Reputation: 10868

Recursively scan directories in bash

I need to write a bash script that scans directories in current directory and generate md5 checksum values for each file in directory tree. It also should keep relative path to file and print checksums in a file.

For example if directory tree looks like this:

.
├── d
│   ├── file1.c
│   └── file2.c
├── e
│   └── file3.c
└── f
    └── file4.cpp

The output should be something like this:

d8e8fca2dc0f896fd7cb4cb0031ba249  d/file1.c
d8e8fca2dc0f896fd7cb4cb0031ba249  d/file2.c
d8e8fca2dc0f896fd7cb4cb0031ba249  e/file3.c
d8e8fca2dc0f896fd7cb4cb0031ba249  f/file4.cpp

But I can't find a way to keep path to file when cd to them...

Upvotes: 1

Views: 2257

Answers (1)

David Ehrmann
David Ehrmann

Reputation: 7576

find . -type f -exec md5sum {} \;

or...

find . -type f | xargs -n 1 -d "\n" md5sum

Upvotes: 6

Related Questions