calculate total used disk space by files older than 180 days using find

前端 未结 5 1693
自闭症患者
自闭症患者 2020-12-25 12:21

I am trying to find the total disk space used by files older than 180 days in a particular directory. This is what I\'m using:

    find . -mtime +180 -exec d         


        
5条回答
  •  北海茫月
    2020-12-25 13:16

    You can print file size with find using the -printf option, but you still need awk to sum.

    For example, total size of all files older than 365 days:

    find . -type f -mtime +356 -printf '%s\n' \
         | awk '{a+=$1;} END {printf "%.1f GB\n", a/2**30;}'
    

提交回复
热议问题