linux 文件日期转时间戳

1、获取文件的修改日期

[root@auc-test2 eccs]# stat eccs.log.232
  File: "eccs.log.232"
  Size: 10485847        Blocks: 20488      IO Block: 4096   普通文件
Device: fd02h/64770d    Inode: 1833867     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-11-30 11:24:57.585461975 +0800
Modify: 2014-11-30 11:24:57.598461975 +0800
Change: 2014-12-18 12:08:00.020797988 +0800

[root@auc-test2 eccs]# stat eccs.log.232 | grep Modify
Modify: 2014-11-30 11:24:57.598461975 +0800

[root@auc-test2 eccs]# stat eccs.log.232 | grep Modify |awk '{print $2}'
2014-11-30

[root@auc-test2 eccs]# date +%s -d  `stat eccs.log.232 | grep Modify |awk '{print $2}'`
1417276800

2、被比较的日期

[root@auc-test2 eccs]# date +%s -d 2019-1-1
1546272000

3、数字大小比较

# 命令中输入if
# if command; then
# commands
# fi
[root@auc-test2 eccs]# if((1546272000>1417276800));then echo "file modify date is earlier 2019-1-1" ; fi
file modify date is earlier 2019-1-1

 # 备注:if (); if条件后面有分号.

猜你喜欢

转载自hbiao68.iteye.com/blog/2168378