• linux命令系列 stat & touch


    1. stat - display file or file system status

    stat命令主要用于显示文件或文件系统的状态,详细信息

    事实上,stat命令显示的是文件的I节点信息。Linux文件系统以块为单位存储信息,为了找到某个文件所在存储空间的位置,用I节点对每个文件进行索引

    所谓的I节点,是文件系统管理的一个数据结构,是一个64字节长的表,包含了描述文件所必要的全部信息,其中包含了文件的大小,类型,存取权限,文件的所有者

    [root@vnode33 ~]# touch a
    [root@vnode33 ~]# stat a
      File: 'a'
      Size: 0               Blocks: 0          IO Block: 4096   regular empty file
    Device: fd00h/64768d    Inode: 18742283    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2018-11-30 09:05:45.776000000 +0800
    Modify: 2018-11-30 09:05:45.776000000 +0800
    Change: 2018-11-30 09:05:45.776000000 +0800
     Birth: -

    为文件a添加一些内容再次使用stat:

    [root@vnode33 ~]# echo 123 > a
    [root@vnode33 ~]# stat a
      File: 'a'
      Size: 4               Blocks: 8          IO Block: 4096   regular file
    Device: fd00h/64768d    Inode: 18742283    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2018-11-30 09:05:45.776000000 +0800
    Modify: 2018-11-30 09:08:24.531000000 +0800
    Change: 2018-11-30 09:08:24.531000000 +0800
     Birth: -

                   注:access 表示最后一次访问(仅仅是访问,没有改动)文件的时间

                         modify 表示最后一次修改文件的时间

                         change 表示最后一次对文件属性改变的时间,包括权限,大小,属性等等

    stat命令常用的选项:

    -L, --dereference  # 显示符号链接
                  follow links   
    
    -f, --file-system  # 不显示文件本身的信息,显示文件所在文件系统的信息
                  display file system status instead of file status
    
    -t, --terse  # 简洁模式,只显示摘要信息
                  print the information in terse form

    2. touch - change file timestamps

    我们可能知道在linux下运行touch命令可以创建一个空文件,其实你要知道touch命令的主要功能并不是为了创建一个空文件哦。

    什么是touch命令?

    linux系统下每个文件都附有时间戳(timestamp),这个时间戳包括访问时间和修改时间。而touch命令主要就是用来修改文件的访问时间和修改时间。

    最简单的使用touch命令。只需要键入touch filename:

    [root@vnode33 ~]# stat a
      File: 'a'
      Size: 4               Blocks: 8          IO Block: 4096   regular file
    Device: fd00h/64768d    Inode: 18742283    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2018-11-30 09:05:45.776000000 +0800
    Modify: 2018-11-30 09:08:24.531000000 +0800
    Change: 2018-11-30 09:08:24.531000000 +0800
     Birth: -
    [root@vnode33 ~]# touch a 
    [root@vnode33 ~]# stat a
      File: 'a'
      Size: 4               Blocks: 8          IO Block: 4096   regular file
    Device: fd00h/64768d    Inode: 18742283    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2018-11-30 09:53:17.929000000 +0800
    Modify: 2018-11-30 09:53:17.929000000 +0800
    Change: 2018-11-30 09:53:17.929000000 +0800
     Birth: -

    对文件a使用touch命令之后,三个时间戳都修改了

    如果我们要只改变访问时间,我们需要使用-a选项:

    [root@vnode33 ~]# stat a
      File: 'a'
      Size: 4               Blocks: 8          IO Block: 4096   regular file
    Device: fd00h/64768d    Inode: 18742283    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2018-11-30 09:53:17.929000000 +0800
    Modify: 2018-11-30 09:53:17.929000000 +0800
    Change: 2018-11-30 09:53:17.929000000 +0800
     Birth: -
    [root@vnode33 ~]# touch -a  a
    [root@vnode33 ~]# stat a
      File: 'a'
      Size: 4               Blocks: 8          IO Block: 4096   regular file
    Device: fd00h/64768d    Inode: 18742283    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2018-11-30 09:55:35.989000000 +0800
    Modify: 2018-11-30 09:53:17.929000000 +0800
    Change: 2018-11-30 09:55:35.989000000 +0800
     Birth: -

    如果我们只希望修改“Modify”时间戳,可以使用-m选项:

    [root@vnode33 ~]# stat a
      File: 'a'
      Size: 4               Blocks: 8          IO Block: 4096   regular file
    Device: fd00h/64768d    Inode: 18742283    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2018-11-30 09:55:35.989000000 +0800
    Modify: 2018-11-30 09:53:17.929000000 +0800
    Change: 2018-11-30 09:55:35.989000000 +0800
     Birth: -
    [root@vnode33 ~]# touch -m a
    [root@vnode33 ~]# stat a
      File: 'a'
      Size: 4               Blocks: 8          IO Block: 4096   regular file
    Device: fd00h/64768d    Inode: 18742283    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2018-11-30 09:55:35.989000000 +0800
    Modify: 2018-11-30 09:57:45.098000000 +0800
    Change: 2018-11-30 09:57:45.098000000 +0800
     Birth: -

    使用-t选项改为自定义时间戳:

    -t STAMP
                  use [[CC]YY]MMDDhhmm[.ss] instead of current time
    [root@vnode33 ~]# touch -t 201010101010 a
    [root@vnode33 ~]# stat a
      File: 'a'
      Size: 4               Blocks: 8          IO Block: 4096   regular file
    Device: fd00h/64768d    Inode: 18742283    Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2010-10-10 10:10:00.000000000 +0800
    Modify: 2010-10-10 10:10:00.000000000 +0800
    Change: 2018-11-30 10:00:37.039000000 +0800
     Birth: -
  • 相关阅读:
    [转] 你不知道的JavaScript和CSS交互的方法
    threejs学习笔记(9)
    把Mongodb配置成windows服务
    mongodb的一些基本操作
    DuiLib事件分析(一)——鼠标事件响应
    DuiLib学习bug整理——某些png不能显示
    DuiLib学习笔记5——标题栏不能正常隐藏问题
    DuiLib学习笔记4——布局
    DuiLib学习笔记3——颜色探究
    DuiLib学习笔记2——写一个简单的程序
  • 原文地址:https://www.cnblogs.com/z-joshua/p/10042681.html
Copyright © 2020-2023  润新知