date、openssl命令的深入理解

一、date 命令时间戳

常用参数

date - 打印或设置系统日期和时间 

根据指定格式显示当前时间或设置系统时间.

-d, --date=STRING
    显示由 STRING 指定的时间, 而不是当前时间 
-f, --file=DATEFILE
    显示 DATEFILE 中每一行指定的时间, 如同将 DATEFILE 中的每行作为 --date 的参数一样 

    -I, --iso-8601[=TIMESPEC] 按照 ISO-8601 的日期/时间格式输出时间. 

    TIMESPEC=`date' (或者不指定时)仅输出日期,等于 `hours', `minutes', 或`seconds' 时按照指定精度输出日期及时间. 

-r, --reference=FILE
    显示 FILE 的最后修改时间 
-R, --rfc-822
    根据 RFC-822 指定格式输出日期 
-s, --set=STRING
    根据 STRING 设置时间 
-u, --utc, --universal
    显示或设置全球时间(格林威治时间) 
  实用1:时间戳:  
[root@localhost ~]# date    #获取当前时间
Sat Jan 18 10:18:19 CST 2020
##把当前时间转时间戳
[root@localhost ~]# date -d "Sat Jan 18 10:18:19 CST 2020" '+%s'
1579313899
[root@localhost ~]# date -d '1970-01-01 UTC 1579313899 seconds'    #时间戳转时间
Sat Jan 18 10:18:19 CST 2020
#时间戳转时间
[root@localhost ~]# date -d @1579313899
Sat Jan 18 10:18:19 CST 2020

根据要求,精确指定精度输出:

# date -I   #按照 ISO-8601 的日期/时间格式输出时间
[root@localhost ~]# date -I
2020-01-18
# date -Ihours 
[root@localhost ~]# date -Ihours  #按小时精度输出
2020-01-18T10+0800   

# date -Iminutes  #按分钟精度输出
[root@localhost ~]# date -Iminutes
2020-01-18T10:30+0800

# date -Iseconds   #按秒精度输出
[root@localhost ~]# date -Iseconds
2020-01-18T10:31:07+0800

根据要求做时间调整:

[root@localhost ~]# date -d "1 day ago"  #一天前
Fri Jan 17 10:32:50 CST 2020
[root@localhost ~]# date -d "1 hour ago" 一个小时前
Sat Jan 18 09:33:01 CST 2020
[root@localhost ~]# date -d "1 minute ago" #一分钟前
Sat Jan 18 10:32:10 CST 2020
[root@localhost ~]# date -d "-1 minute" #一分钟前
Sat Jan 18 10:32:56 CST 2020
[root@localhost ~]# date -d "+1 minute"  #一分钟后
Sat Jan 18 10:35:04 CST 2020
[root@localhost ~]# date -d "+1 month" #一个月后
Tue Feb 18 10:34:16 CST 2020
[root@localhost ~]# date -d "+1 year" #一年后的
Mon Jan 18 10:34:27 CST 2021
[root@localhost ~]# date -d "+1 year" +%F_%T #格式化输出
2021-01-18_10:37:06

二、Openssl 查看证书常用命令:

[root@localhost ~]# openssl crl -in file -inform der -noout ?
unknown option ?
usage: crl args
					#输入格式
 -inform arg     - input format - default PEM (DER or PEM)
                    #输出格式
 -outform arg    - output format - default PEM
 #输出加密内容
 -text           - print out a text format version
 #输入文件
 -in arg         - input file - default stdin
 输出到指定文件或输出到屏幕
 -out arg        - output file - default stdout
 输出hash值
 -hash           - print hash value
 输出指纹
 -fingerprint    - print the crl fingerprint
 输出DN
 -issuer         - print issuer DN
 输出上次生效时间
 -lastupdate     - lastUpdate field
 输出失效时间
 -nextupdate     - nextUpdate field
 输出CRL编号
 -crlnumber      - print CRL number
 -noout          - no CRL output
 -CAfile  name   - verify CRL using certificates in file "name"
 -CApath  dir    - verify CRL using certificates in "dir"
 -nameopt arg    - various certificate name options
发布了48 篇原创文章 · 获赞 18 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/AMimiDou_212/article/details/104027529
今日推荐