Shell小知识date和seq

2023-06-13,,

shell中seq小知识

默认分隔符为换行符、起始为1

[root@iZ28vzyqqtfZ ~]# seq 3
1
2
3
指定分隔符为空格,起始为10

[root@iZ28vzyqqtfZ ~]# seq -s " " 10 15
10 11 12 13 14 15

更多参数可以查看该命令的帮助help或man。
seq在迭代中的使用:

[root@iZ28vzyqqtfZ ~]# for i in `seq -s " " 10 15`; do echo $i; done
10
11
12
13
14
15

shell中date小知识点:

在控制台经常会和时间、时间戳交互,有时需要当前时间戳,有时需要格式化时间或时间戳,时间、时间戳的相互转化如下(再也不用上网找转换工具了-_-!!!):
date +%s 可以得到UNIX的时间戳

[root@iZ28vzyqqtfZ ~]# date +%s
1449216083

格式化显示时间字符串

[root@iZ28vzyqqtfZ ~]# date "+%Y-%m-%d %H:%M:%S"
2015-12-04 16:02:19

将字符串时间转换成时间戳

[root@iZ28vzyqqtfZ ~]# date -d "2015-12-04 16:02:19" +%s
1449216139

将时间戳转换成字符串时间

[root@iZ28vzyqqtfZ ~]# date -d @1449216139 "+%Y-%m-%d %H:%M:%S"
2015-12-04 16:02:19

《Shell小知识date和seq.doc》

下载本文的Word格式文档,以方便收藏与打印。