Created
August 11, 2020 18:30
-
-
Save mansurali901/a701b0b13ba0484348cc8d85fcd92f2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import fnmatch | |
from re import search | |
thisdir = '/opt/tomcat/latest/logs/' | |
# r=root, d=directories, f = files | |
list_of_files = [] | |
for r, d, f in os.walk(thisdir): | |
for file in f: | |
ext = [".log", ".txt", ".gz"] | |
for types in ext: | |
if file.endswith(types): | |
string = "2020" | |
if search(string, file): | |
list_of_files.append(os.path.join(r, file)) | |
for file_name in list_of_files: | |
cmd = subprocess.Popen(['rm', file_name ]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment