date和stat

linux系统中的两个命令,今天写了个脚本,比较当前时间和文件中最后修改时间,用到了两个命令,mark一下。

两个命令中都有一系列format选项,date用的较多,使用“+”接format选项即可,在脚本中使用date +%s获取当前时间(1970年到现在的秒数)。stat命令用的较少,man了一下,又baidu了一番,最后细看了有看,试了又试,才发现stat有个开关“-c  --format=FORMAT   use the specified FORMAT instead of the default”。脚本中使用该开关得到文件的最后修改时间,命令为“stat -c %Y ${filename}”。

在linux这种开放的系统中,命令行参数是有很多风格的,使用时要抛开惯性,细看手册。

PS:stat --help,结果如下:

Usage: stat [OPTION] FILE...
Display file or filesystem status.

  -f, --filesystem      display filesystem status instead of file status
  -c  --format=FORMAT   use the specified FORMAT instead of the default
  -L, --dereference     follow links
  -t, --terse           print the information in terse form
      --help     display this help and exit
      --version  output version information and exit

The valid format sequences for files (without --filesystem):

  %A - Access rights in human readable form
  %a - Access rights in octal
  %b - Number of blocks allocated
  %D - Device number in hex
  %d - Device number in decimal
  %F - File type
  %f - raw mode in hex
  %G - Group name of owner
  %g - Group ID of owner
  %h - Number of hard links
  %i - Inode number
  %N - Quoted File name with dereference if symbolic link
  %n - File name
  %o - IO block size
  %s - Total size, in bytes
  %T - Minor device type in hex
  %t - Major device type in hex
  %U - User name of owner
  %u - User ID of owner
  %X - Time of last access as seconds since Epoch
  %x - Time of last access
  %Y - Time of last modification as seconds since Epoch
  %y - Time of last modification
  %Z - Time of last change as seconds since Epoch
  %z - Time of last change

Valid format sequences for file systems:

  %a - Free blocks available to non-superuser
  %b - Total data blocks in file system
  %c - Total file nodes in file system
  %d - Free file nodes in file system
  %f - Free blocks in file system
  %i - File System id in hex
  %l - Maximum length of filenames
  %n - File name
  %s - Optimal transfer block size
  %T - Type in human readable form
  %t - Type in hex

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值