I have a folder with thousands of large files and I would like to find the total used disk space that was created in the last X days.
I've tried this command:
find . -type f -mtime -30 -printf '%s\n' | awk '{total=total+$1}END{print total/1024}'
As mentioned here by @k-h
calculate total used disk space by files older than 180 days using find
The output of the command is 9.84347e+09 and I'm not sure how to change the output to TB disk size.
Please advise.
Thanks,
Yaron
Well not quite the same logic but I'm here to explain:
{ echo -n \(; find -type f -mtime -30 -printf "%s+"; echo 0\)/1024/1024/1024/1024; } | bc
Let's break this down:
echo -n \(
- prints (
without a line break.find …
- that same ol' command you used with the +
sign for calculation.echo 0\)/1024…
- we're printing 0
so the expression won't end with a +
sign, print the closing parentheses and then dividing by 1024 four times to get to the relevant result.| bc
- this is the calculation tool, you can simply pipe the formula to this tool, try running echo 1+2 | bc
and play with it to understand its concept.Have fun, and cool name BTW :)