awkfindcommandprintffilemtime

calculate in TB total used disk space by files newer than X days using find


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


Solution

  • 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:

    Have fun, and cool name BTW :)