daknetworks.com

You are here: Blog Linux Delete All Files Greater than a Certain Size

Linux Delete All Files Greater than a Certain Size

Lets say you have a directory of photos. The directory is about 1TB and the hard drive is packed full. How do you delete files that are larger than a certain size?

Here's how:

cd /path/to/dir
find . -name "*.jpg" -size +1000k -delete

K is for KB.
Miss off the "-delete" if you want to run a test without deleting the files.
Adjust accordingly.

Or if you need to delete base on date (files older than 30 days):
find ./path/to/dir/ -type f -mtime +30 -delete

Find files larger than 1MB:
find ./directory-name-here -type f -size +1M

Find files older than 180 days:
find ./directory-name-here -type f -mtime +180 -exec rm -f {} \;

Contact Dak Networks

We are not taking on new clients at this time.