Sunday, August 18, 2024

finding old files and disk space used - with Linux command line

 Following 

https://askubuntu.com/questions/413529/delete-files-older-than-one-year-on-linux

 and 

https://stackoverflow.com/questions/17419337/calculate-total-used-disk-space-by-files-older-than-180-days-using-find

 sudo su -

cd /the/relevant/directory

 find . -type f  -printf '%s\n' | wc -l  # for just the total number of files

find . -type f -mtime +365 -printf '%s\n' | wc -l  # for the number of files older than a year

find . -type f -mtime +365 -printf '%s\n' | awk '{total=total+$1}END{print total/(1024*1024*1024)}' # total disk space used by files older than 365 days, in GB

No comments:

Post a Comment