Create sha.sh

This commit is contained in:
Darth Kilroy 2025-08-02 23:03:48 -05:00 committed by GitHub
parent bc45615b9d
commit cd048610de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

15
sha.sh Normal file
View file

@ -0,0 +1,15 @@
#!/bin/bash
# Creates a .sha256 file with the same subfolders and each file (so creates a directory tree identical to the original.
SRC_DIR="/data"
DATE=$(date +%Y%m%d_%H%M%S)
find "$SRC_DIR" -type f | while read -r file; do
# Get the directory and filename relative to SRC_DIR
rel_dir=$(dirname "${file#$SRC_DIR/}")
filename=$(basename "$file")
# Create a log directory for this file
log_dir="/tmp/$rel_dir/$filename"
mkdir -p "$log_dir"
# Generate sha256 and save to $DATE.sha256 inside the log directory
sha256sum "$file" > "$log_dir/$DATE.sha256"
done