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

前端 未结 5 1712
自闭症患者
自闭症患者 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:24

    du wouldn't summarize if you pass a list of files to it.

    Instead, pipe the output to cut and let awk sum it up. So you can say:

    find . -mtime +180 -exec du -ks {} \; | cut -f1 | awk '{total=total+$1}END{print total/1024}'
    

    Note that the option -h to display the result in human-readable format has been replaced by -k which is equivalent to block size of 1K. The result is presented in MB (see total/1024 above).

提交回复
热议问题