Friday, March 25, 2011

Find and delete large files

Find files larger than 1GB (display filesize and lsat modified time):

$ find <directory> -type f -size +1G
$ find <directory> -type f -size +1G -exec du -h --time {} \;

Sorted by file size (human readable size):

$ find <directory> -type f -size +1G -exec du --time {} \; | sort -n
$ find <directory> -type f -size +1G -exec du -h --time {} \; | sort -h

Find files that are larger than 1GB and older than 5 days (sorted by time):

$ find <directory> -type f -size +1G -mtime +5
$ find <directory> -type f -size +1G -mtime +5 -exec ls -lht {} +;

Find and delete files older than 5 days and larger than 1GB:

$ find <directory> -type f -size +1G -mtime +5 -exec rm {} \;