Linux基础命令:stat

stat [OPTION]... FILE...

  • Display file or file system status 显示文件的系统属性相关

  • 常用选项

    -f:display file system status instead of file status 查看系统inode相关参数
    
  • 查看文件的属性

    [xzt7566@centos7-test Downloads]$ stat hosts
      File: ‘hosts’ -> ‘/etc/hosts’
      Size: 10            Blocks: 0          IO Block: 4096   symbolic link
    Device: fd00h/64768d  Inode: 51753441    Links: 1
    Access: (0777/lrwxrwxrwx)  Uid: ( 1000/ xzt7566)   Gid: ( 1000/ xzt7566)
    Context: unconfined_u:object_r:user_home_t:s0
    Access: 2019-05-04 16:13:22.423273050 +0800
    Modify: 2019-05-04 16:13:20.542088369 +0800
    Change: 2019-05-04 16:13:20.543088467 +0800
     Birth: -
    
  • Linux中文件没有创建时间的概念

  • access time,文件数据最近的一次访问时间

  • modify time,文件数据改变的时间(data).mtime发生变化,ctime一定变化

  • change time,文件状态变更的时间.及包含数据改变(mtime)以及metadata(权限,属主,属组...)

  • 硬链接文件完全一致,其中一个更改,另外的完全同步.

  • 软链接文件,为两个不同的文件.互不影响.

  • 查看系统状态 可配合df -i查询

    [xzt7566@centos7-test Downloads]$ ls
    hosts
    [xzt7566@centos7-test Downloads]$ stat -f hosts
      File: "hosts"
        ID: fd0000000000 Namelen: 255     Type: xfs
    Block size: 4096       Fundamental block size: 4096
    Blocks: Total: 5632321    Free: 4487482    Available: 4487482
    Inodes: Total: 11270144   Free: 11129711
    
    [xzt7566@centos7-test Downloads]$ df -i
    Filesystem                Inodes  IUsed    IFree IUse% Mounted on
    /dev/mapper/centos-root 11270144 140433 11129711    2% /
    devtmpfs                  478462    376   478086    1% /dev
    tmpfs                     482688      1   482687    1% /dev/shm
    tmpfs                     482688   1428   481260    1% /run
    tmpfs                     482688     16   482672    1% /sys/fs/cgroup
    /dev/sda1                 524288    355   523933    1% /boot
    tmpfs                     482688     17   482671    1% /run/user/1000
    
  • stat -c '%A %n' * 类似 ls 的效果

  • 例:

    • cat file,head file ... 后atime变化、其他不变
    • cat >> file,echo "xxx" >> file ... 后 mtime 和 ctime 变化
    • chmod 777 file,chown xxx file ...后ctime变化、其他不变
    • vim file只要存档,所有属性均变化
    • vim file不存档离开,atime变化,其他不变

你可能感兴趣的:(Linux基础命令:stat)