linux找到目录中最新修改的文件
时间:2024年02月03日
/来源:网络
/编辑:佚名
怎么找到目录中最新修改的文件。
How To Find Last Modified File In A Directory?
Bash:
find ~/Work -type f -printf ‘%T+ %f\n' | sort | tail -1
Python:
Method:1 Using Max functionfrom datetime import datetimefrom pathlib import Path
dpath = Path( " /home/mana/work")
files = {i.name: i.stat().st_mtime for i in dpath.iterdir()
if i.is_file()}
print(max(files.items(),key = lambda x: x[1]))
Method:2 Using Sorted function
from datetime import datetimefrom pathlib import Path
dpath = Path( "/home/mana/Work")
files = {i.name: i.stat().st_mtime for i in dpath.iterdir()
if i.is_file()}
sorted(files.items(),key = lambda x: x[1],reverse=True)[o]2
output
( 'fruit1.txt',1587979664.4237294)
How To Find Last Modified File In A Directory?
Bash:
find ~/Work -type f -printf ‘%T+ %f\n' | sort | tail -1
Python:
Method:1 Using Max functionfrom datetime import datetimefrom pathlib import Path
dpath = Path( " /home/mana/work")
files = {i.name: i.stat().st_mtime for i in dpath.iterdir()
if i.is_file()}
print(max(files.items(),key = lambda x: x[1]))
Method:2 Using Sorted function
from datetime import datetimefrom pathlib import Path
dpath = Path( "/home/mana/Work")
files = {i.name: i.stat().st_mtime for i in dpath.iterdir()
if i.is_file()}
sorted(files.items(),key = lambda x: x[1],reverse=True)[o]2
output
( 'fruit1.txt',1587979664.4237294)
新闻资讯 更多
- 【建站知识】查询nginx日志状态码大于400的请求并打印整行04-03
- 【建站知识】Python中的logger和handler到底是个什么?04-03
- 【建站知识】python3拉勾网爬虫之(您操作太频繁,请稍后访问)04-03
- 【建站知识】xpath 获取meta里的keywords及description的方法04-03
- 【建站知识】python向上取整以50为界04-03
- 【建站知识】scrapy xpath遇见乱码解决04-03
- 【建站知识】scrapy爬取后中文乱码,解决word转为html 时cp1252编码问题04-03
- 【建站知识】scrapy采集—爬取中文乱码,gb2312转为utf-804-03