Skip to content

Instantly share code, notes, and snippets.

@mansurali901
Created August 11, 2020 18:30
Show Gist options
  • Save mansurali901/a701b0b13ba0484348cc8d85fcd92f2f to your computer and use it in GitHub Desktop.
Save mansurali901/a701b0b13ba0484348cc8d85fcd92f2f to your computer and use it in GitHub Desktop.
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