python 删除2天前后缀为.log的文件】的更多相关文章

python脚本 删除2天前后缀为.log的文件 #!/usr/local/python/bin/python #-*-coding=utf8 -*- import time import os,sys N = 2 #设置删除多少天前的文件 def deletefile(path): for eachfile in os.listdir(path): filename = os.path.join(path,eachfile) if os.path.isfile(filename): lastm…
python版本为:2.7 import os import sys import time # Sets how many days old files are deleted DAYS_N = 7 # To delete the path and the following subfiles PATH = r'C:\inetpub\logs\LogFiles' def deletefile(PATH): for eachfile in os.listdir(PATH): filename =…
#获取所有文件def file(): for cur_dir, dirs, files in os.walk(r'/学习/接口自动化/BestTest/作业/logs'): # cur_dir(当前路径),dirs(目录),files(文件)中所有的 for file in files: abs_path = os.path.join(cur_dir, file) # 获取绝对路径 if int(timestamp_to_str(abs_path.split("_")[1].split…
#!/usr/bin/env python # -*- coding:utf-8 -*- import os, time, sys, shutil def delFiles(beforeSec, dirpath): for i in os.listdir(dirpath): filepath = "%s%s%s" %(dirpath, os.sep, i) if os.path.getmtime(filepath) < beforeSec: try: if os.path.isf…
import os import time import datetime def should_remove(path, pattern, days): if not path.endswith(pattern): return False mtime = os.path.getmtime(path) now = time.time() result = now - mtime > days * 24 * 3600 print "\n>>>>>>>…
#!/bin/bash#delete the file of 7 days agofind /data/mysqlbackup/ -mtime +7 -name "*.sql" -exec rm -f {} \;…
# encoding: utf-8 import sys import getopt import os import glob import time import datetime def removefile(keep=7): for file in glob.glob('/app/*/logs/*/*.log'): # 获取当前时间 today = datetime.datetime.now() # 计算偏移量,前k天 offset = datetime.timedelta(minute…
删除目录 find /your_dir/ -maxdepth -type d -mtime + -exec rm -rf {} \; 删除文件 find /目录/ -mtime + -name "*.log" -exec rm -rf {} \;…
shell程序如下所示: # cat xarg.txt #! /usr/bin/ksh for logfile in `find . -name "*.log*"` do echo "$logfile:" sed -n '/error/=' $logfile done files=($(find . -name "*log*")) echo "The length is ${#files[@]}" for file in ${…
1. #/bin/bash # filename: del_log.sh find / -name "*.log" -mtime 3 | xargs rm -rf 2. #/bin/bash # filename: del_log.sh find / -name "*.log" -mtime 3 -exec rm -rf {} \; 3. #/bin/bash # filename: del_log.sh find / -name "*.log"…