查找出含有特定文件并且24小时内有更新的目录:
vi a1.py
#!/usr/bin/python
import os
import datetime
dir="/root/python"
import datetime
now = datetime.datetime.now()
deltaH = datetime.timedelta(seconds=86400)
for root,dirs,files in os.walk(dir):
for f in files:
if f == "aa.txt":
j = datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(root,f))
if j > (now - deltaH):
print os.path.dirname(os.path.join(root,f))
:wq
python a1.py
转载于:https://blog.51cto.com/yangzhiming/2125926