Describe désert/Linux/stat here.

stat 簡介

與 ls 相比,Linux stat 命令可以向您顯示更多詳細信息。使用這個信息豐富且可配置的實用程序,在幕後窺視一下。我們將向您展示如何使用它。

如何查看文件的信息

讓我們創建一個格式字符串並將其傳遞給 stat。將要使用的格式序列是 %n 表示文件名,%s 表示文件大小,%F 表示文件類型。我們將在字符串的末尾添加 \n 轉義序列,以確保每個文件都在新行上處理。我們的格式字符串如下所示:

 $ stat --printf="File %n is %s bytes, and is a %F\n" Horizon7-vSAN6.7.7z 
File Horizon7-vSAN6.7.7z is 40974092 bytes, and is a regular file

$ stat --printf '%n\nmtime: %y\nctime: %z\natime: %x\ncrtime:%w\n' Horizon*
Horizon7-vSAN6.7.7z
mtime: 2021-04-09 15:09:13.668807317 +0800
ctime: 2021-08-25 22:26:52.997093121 +0800
atime: 2021-04-09 15:09:13.362133827 +0800
crtime:2021-04-09 15:09:13.362133827 +0800
Horizon-GroupPolicyAndProfiles.pdf
mtime: 2021-01-25 09:40:08.368308319 +0800
ctime: 2021-08-25 22:26:52.997093121 +0800
atime: 2021-01-25 09:40:08.308306959 +0800
crtime:2021-01-25 09:40:08.308306959 +0800

Several file systems store the file creation time, although there is no standard name for this field:

    ufs2 → st_birthtime
    zfs → crtime
    ext4 → crtime
    btrfs → otime
    jfs → di_otime

尋找對應時間範圍的文件

touch --date "2020-01-01" /tmp/start
touch --date "2021-01-01" /tmp/end
find /data/images -type f -newer /tmp/start -not -newer /tmp/end

désert/Linux/stat (last edited 2021-11-23 06:26:55 by localhost)