Created
July 12, 2023 19:50
-
-
Save r-walloner/0e42c501906124a1edff0472ebaa09f2 to your computer and use it in GitHub Desktop.
analyze.sh
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 | |
# Directory to analyze | |
directory="/path/to/directory" | |
# Initialize an associative array to store the storage per year | |
declare -A storage_per_year | |
# Loop through all files in the directory | |
find "$directory" -type f -exec stat --format "%Y %s" {} \; | while read -r timestamp size; do | |
# Convert the timestamp to a year | |
year=$(date -d @"$timestamp" +%Y) | |
# Add the file size to the corresponding year in the associative array | |
((storage_per_year[$year] += size)) | |
done | |
# Print the storage per year | |
for year in "${!storage_per_year[@]}"; do | |
echo "Year $year: ${storage_per_year[$year]} bytes" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment