Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deleting all the file of certain size

Tags:

python

shell

perl

i have bunch of log files and I have to delete the files of some small sizes, which were erroneous files that got created. ( 63bytes ). I have to copy only those files which have data in it .

like image 766
AlgoMan Avatar asked Nov 27 '22 03:11

AlgoMan


2 Answers

Shell (linux);

find . -type f -size 63c -delete

Will traverse subdirectories (unless you tell it otherwise)

like image 138
Wrikken Avatar answered Dec 10 '22 14:12

Wrikken


Since you tagged your question with "python" here is how you could do this in that language:

target_size = 63
import os
for dirpath, dirs, files in os.walk('.'):
    for file in files: 
        path = os.path.join(dirpath, file)
        if os.stat(path).st_size == target_size:
            os.remove(path)
like image 42
zifot Avatar answered Dec 10 '22 16:12

zifot