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 du -sh {} ;
but the above is quiet evidently giving me disk space used by every file that is found. I want only the total added disk space used by the files. Can this be done using find
and exec
command ?
Please note I simply don’t want to use a script for this, it will be great if there could be a one liner for this. Any help is highly appreciated.
Advertisement
Answer
@PeterT is right. Almost all these answers invoke a command (du) for each file, which is very resource intensive and slow and unnecessary. The simplest and fastest way is this:
find . -type f -mtime +356 -printf '%sn' | awk '{total=total+$1}END{print total/1024}'