bash - 获取文件的最后修改日期
问题描述
我正在编写一个 bash 程序来按修改日期的顺序对来自不同文件夹的照片进行排序。我知道如何列出所有文件的名称,但我怎样才能获得它们的修改日期呢?
Matthews-MacBook-Air-3:Q3 Matthew$ find . -name '*.jpg'
./MontrealTest/daves_images/mtl10.jpg
./MontrealTest/daves_images/mtl7.jpg
./MontrealTest/gregs_photos/mtl1.jpg
./MontrealTest/photos_by_harth/mtl11.jpg
./MontrealTest/photos_by_harth/mtl5.jpg
./MontrealTest/photos_by_harth/mtl9.jpg
./MontrealTest/sandeeps_collection/mtl4.jpg
./MontrealTest/sandeeps_collection/mtl8.jpg
./MontrealTest.jpg
./SimpleTest/dir1/fee.jpg
./SimpleTest/dir2/fum.jpg
./SimpleTest/dir3/foo.jpg
./SimpleTest/dir4/foe.jpg
Matthews-MacBook-Air-3:Q3 Matthew$
解决方案
这取决于find
您拥有的版本(通常取决于您使用的操作系统)。如果find
支持-printf
原语,您可以执行以下操作(但请参阅man find
更多格式选项):
find . -name '*.jpg' -printf '%t %p\n'
如果您find
不支持-printf
,您可以让它执行stat
以执行相同的操作(同样,请参阅man stat
更多格式选项):
find . -name '*.jpg' -exec stat -f '%Sm %N' {} +
推荐阅读
- string - 按位置将字符串拆分为元胞数组
- java - 使用java配置将sql/hql注入spring bean
- javascript - 如何修复 Slimmenu 多级子项目走出屏幕
- r - 如何在 2 个级别上聚合,首先是计数,其次是函数 f(count)?
- angular - 在javascript中将json对象转换为日期
- atg - 为什么 REST 模块没有返回会话确认号?
- r - str_extract 无法识别俄语模式
- java - 使用 JUnit 在标准输出上测试一些复杂的字符串?
- codeigniter - 在 Codeigniter 中获取相同的分页数据
- python - 将数据帧切片成新的数据帧