在 Linux 系统中,每个文件都存储有三种时间戳(timestamps),可以通过 stat 命令或 ls 命令查看:
stat 命令(推荐)stat 文件名
输出示例:
File: 文件名
Size: 1024 Blocks: 8 IO Block: 4096 regular file
Access: 2023-10-25 09:00:00.000000000 +0800
Modify: 2023-10-25 08:30:00.000000000 +0800
Change: 2023-10-25 08:45:00.000000000 +0800
Birth: 2023-10-25 08:20:00.000000000 +0800
ls 命令查看修改时间 (mtime)(默认显示):
ls -l 文件名
输出示例:
-rw-r--r-- 1 user group 1024 Oct 25 08:30 文件名
查看访问时间 (atime):
ls -lu 文件名
查看变更时间 (ctime):
ls -lc 文件名
YYYY-MM-DD HH:MM:SS + 时区。--time-style 自定义显示格式(仅限 ls):
bash
ls -l --time-style="+%Y-%m-%d %H:%M:%S" 文件名relatime 挂载选项优化性能)。date 命令检查当前时区。| 时间类型 | 命令选项 | 描述 |
|---|---|---|
| mtime | ls -l 或 stat |
文件内容修改时间 |
| atime | ls -lu 或 stat |
文件访问时间 |
| ctime | ls -lc 或 stat |
元数据(如权限)修改时间 |
| btime | stat |
文件创建时间(可能不可用) |
如果需要进一步处理时间戳(如脚本中提取),可以结合 date 或 awk 工具格式化输出。