I want to do a /home search and remove for files named error_log that are over 5mb

I use this now but it doesn't factor space:

find /home -type f -name error_log -exec rm -f {} \;

Any idea how to add the 5 mb limit here?

Thanks!

Recommended Answers

All 3 Replies

You could use a python script named lescript

#!/usr/bin/env python3
# -*-coding: utf8-*-
import os
import sys

if __name__ == '__main__':
    size = int(sys.argv[1])
    for filename in sys.argv[2:]:
        if os.stat(filename).st_size > size:
            try:
                os.unlink(filename)
            except:
                print('Ignoring', filename)

Then invoke

find /home -type f -name error_log -exec lescript 5242880 {} +

Awesome, I think I found a way like this:

find /home -size +5m -type f -name error_log -exec rm -f {} \; | sort -u

I'm going to try these too though, thanks again.

use Ccleaner disk analyze option, and when if finish analyzing scroll down until you find 5 mb files and start looking by file name, this is an alternatif way of doing it ..good luck mate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.