mac os系统下 stat命令
$ stat filenam
Stat的输出大致如下:
Device ID
Inode number
Permissions (mode)
Hard link count (usually 1)
File userid (owner)
File groupid
Device ID
Size in bytes
Last access time
Last (contents) modification time
Last permissions change time
Create time
Ideal block size for file
512-byte-size blocks allocated for file
Flags set on file (see chflags(2))
四个时间的定义如下:
st_atime Time when file data last accessed. 读取时间。
st_mtime Time when file data last modified. 内容修改时间
st_ctime Time when file status was last changed (inode data modification).
Inode修改时间
st_birthtime Time of file creation. 创建时间
此四个时间也可以通过 ls 命令获得:
ls -la : 获得atime
ls -lu : 获得mtime
ls -lc : 获得ctime
ls -lU : 获得birthtime
-F : 可以为不同类型文件,显示特殊标志。
目录文件: /
可执行文件: *
软链接文件: @
socket : =
FIFO(命名管道): |
管道读写数据的原理是先进先出(First In First Out) 所以叫做FIFO
-x : 用类似linux的形式显示信息,可读性好些。但只显示三个相关时间
好用的-f参数:
stat -f Format filename
Formate以%开头,后跟参数。如果%后立即接n,t,%或@,则分别打印出换行、制表、百分号和当前文件号:
%stat -f %@___%N *
1___10_30.pl
2___10_exercise.pl
3___10_exercise_c.pl
4___10_file.pl
...
列几个有用参数(其它查man stat):
-N : The name of the file.
-a,m,c,B: The access, modify,ctime and creation time. With S, convert the time to the more readable sequence. 访问、修改、inode 以及创建时间。 使用S,切换成易读的年月日时分秒形式,否则,是1970以来的秒数字符串。 MaxOS里有创建时间,与linux不同。
E.g.: -f "%SA"
$ stat -f "Name: %N%n%tAccess_time:%Sa%n%tModify_time:%Sm%n%tCtime:%Sc%n%tCreation_Time:%SB" Perl_Note.txt
Name: Perl_Note.txt
Access_time:Oct 23 10:20:53 2021
Modify_time:Oct 23 10:20:52 2021
Ctime:Oct 23 10:20:52 2021
Creation_Time:Aug 15 11:47:51 2021
Otherwise, the time would be a long sequence such as :Creation_Time:1565840871
用 S可以将时间转化为易读的形式,否则,会使自epoch以来的秒数。
此处,注意:
stat -f %SB -t %Y file only prints the creation year. 只打印出年
But stat -f %SB file prints the creation date and time. 年月是和时间都打印出来
stat -f %SB -t %Y Perl_Note.txt
2021
获得最新修改的三个文件:
stat -f "%m%t%Sm %N" * | sort -rn | head -3 | cut -f2-
Oct 23 11:07:53 2021 Shell_Note
Aug 12 11:35:50 2021 The_Usage_of_vi.rtf
Feb 28 19:01:40 2021 ts_xml.sh
### stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2-
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)