Created
September 4, 2024 00:29
-
-
Save naufalso/af01f9ceb227de7c2a16bc7463fe8621 to your computer and use it in GitHub Desktop.
A scripts for computing folder hash. This is usefull for checking to folder is identical.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the correct number of arguments is provided | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <input_directory> <output_file>" | |
exit 1 | |
fi | |
# Assign input arguments to variables | |
input_dir="$1" | |
output_file="$2" | |
# Check if the input directory exists | |
if [ ! -d "$input_dir" ]; then | |
echo "Error: Directory '$input_dir' does not exist." | |
exit 1 | |
fi | |
# Compute the hash | |
hash=$(find "$input_dir" -type f -exec sha256sum {} + | sort | sha256sum | awk '{print $1}') | |
# Print the hash | |
echo "SHA-256 Hash: $hash" | |
# Write the hash to the output file | |
echo "$hash" > "$output_file" | |
echo "Hash has been written to '$output_file'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment