今天测试了下从终端获取本地文件的修改时间,顺便记录一下。

  • atime The time file was last accessed

      date -r $(stat -f "%a" $FILE) +"%FT%T%z"
    
  • mtime The time file was last modified

      date -r $(stat -f "%m" $FILE) +"%FT%T%z"
    
  • ctime The time inode was last changed

      date -r $(stat -f "%c" $FILE) +"%FT%T%z"
    
  • create time The time inode was created

      date -r $(stat -f "%B" $FILE) +"%FT%T%z"
    

总结: stat 是个非常有用的命令。