Created
January 23, 2018 14:09
-
-
Save mbolli/8ba3def57706c654187379796af735a6 to your computer and use it in GitHub Desktop.
Gets the size of the current folder's contents, as long as they're older than the year specified. Useful for scanning through a big directory, if you want to archive stuff older than x years. Ignores Thumbs.db and .DS_Store files.
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 | |
# sizeolderthan.sh | |
# Usage: | |
# To get total size of files older than 2013 | |
# > sizeolderthan.sh 2013 | |
# To get total size overall just take "du -h"... | |
# | |
maxyear=$1 | |
if [ "$maxyear" == "" ]; then | |
echo "No year provided." | |
exit | |
fi | |
echo "Looking for folders older than ${maxyear}..." | |
total=0 | |
while IFS= read -r -d $'\0' line; do | |
newest=`find "${line}" -type f ! -name "Thumbs.db" ! -name ".DS_Store" -printf "%TY\n" | sort -nr | head -n 1` | |
size=0 | |
if (( newest < maxyear && newest > 0 )); then | |
# $line is a folder older than $maxyear | |
size=`du -s "${line}" | awk '{ print $1 }'` | |
total=$((total+size)) | |
echo -e "Total:\t${total}\t Size:\t${size}\t${line}" | |
fi | |
done < <(find . -maxdepth 1 -type d -print0) | |
echo -e "================\nTotal:\t" `echo $total | awk '{ print $1/1000000, "GB" }'` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment