For a given tree, say /var/ftpd, how do I create a hash file in each folder of that tree with the contents of that folder within a given tree? sha1sum and sha512sum does not have recursion options.
Asked
Active
Viewed 3,500 times
2 Answers
1
FWIW the solution is:
user@host bin]$ cat mkshaindir
#!/bin/dash
cd $1
sha512sum * >.sha512sum
[user@host bin]$ find /var/ftpd -type d -print0 | xargs -0 -i mkshaindir {}
Note that mkshaindir, for my purposes, is a separate component because there may be a need for me to make a hash of files in a new folder, or of one that was recently changed.
The rest is left as an exercise for the reader.
Note: sha512sum will complain to STDERR about non file input (e.g. directories, block files, etc).
Chris
- 101
0
The script should avoid to include the hashfile itself into the calculation, as saving the hashfile invalidates the hash.
Moreover, I suggest to use find -exec to save resources:
find /var/ftpd -type d -print0 ! -name .sha512sum -exec mkshaindir {} \;
user1016274
- 1,619