Skip to content

Instantly share code, notes, and snippets.

@r-walloner
Created July 12, 2023 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-walloner/0e42c501906124a1edff0472ebaa09f2 to your computer and use it in GitHub Desktop.
Save r-walloner/0e42c501906124a1edff0472ebaa09f2 to your computer and use it in GitHub Desktop.
analyze.sh
#!/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