Linux Shell编程(22)——时间/日期 命令
来源:互联网 发布:淘宝店怎么转让 编辑:程序博客网 时间:2024/06/05 08:17
date
直接调用, date 就会打印日期和时间到 stdout 上. 这个命令有趣的地方在于它的格式化和分析选项上.
time
输出统计出来的命令执行的时间.
touch
这是一个用来更新文件被存取或修改的时间的工具,这个时间可以是当前系统的时间,也可以是指定的时间, 这个命令也用来产生一个新文件.
Example:使用 date 命令
-u 选项将给出 UTC 时间(Universal Coordinated Time).
date 命令有许多的输出选项. 比如 %N 将以10亿分之一为单位表示当前时间. 这个选项的一个有趣的用法就是用来产生一个6位的随机数.
date +%j
# 显示今天是本年度的第几天(从1月1日开始计算).
date +%k%M
# 显示当前小时数和分钟数.
# 'TZ' 参数允许改变当前的默认时区.
date
TZ=EST date
SixDaysAgo=$(date --date='6 days ago')
OneMonthAgo=$(date --date='1 month ago') # 4周前(不是一个月).
OneYearAgo=$(date --date='1 year ago')
直接调用, date 就会打印日期和时间到 stdout 上. 这个命令有趣的地方在于它的格式化和分析选项上.
time
输出统计出来的命令执行的时间.
touch
这是一个用来更新文件被存取或修改的时间的工具,这个时间可以是当前系统的时间,也可以是指定的时间, 这个命令也用来产生一个新文件.
Example:使用 date 命令
#!/bin/bash# 练习 'date' 命令echo "The number of days since the year's beginning is `date +%j`."# 需要在调用格式的前边加上一个 '+' 号.# %j 给出今天是本年度的第几天.echo "The number of seconds elapsed since 01/01/1970 is `date +%s`."# %s 将产生从 "UNIX 元年" 到现在为止的秒数,yields number of seconds since "UNIX epoch" began,prefix=tempsuffix=$(date +%s) # 'date'命令的 "+%s" 选项是 GNU-特性.filename=$prefix.$suffixecho $filenameexit 0
-u 选项将给出 UTC 时间(Universal Coordinated Time).
date 命令有许多的输出选项. 比如 %N 将以10亿分之一为单位表示当前时间. 这个选项的一个有趣的用法就是用来产生一个6位的随机数.
date +%j
# 显示今天是本年度的第几天(从1月1日开始计算).
date +%k%M
# 显示当前小时数和分钟数.
# 'TZ' 参数允许改变当前的默认时区.
date
TZ=EST date
SixDaysAgo=$(date --date='6 days ago')
OneMonthAgo=$(date --date='1 month ago') # 4周前(不是一个月).
OneYearAgo=$(date --date='1 year ago')
0 0
- Linux Shell编程(22)——时间/日期 命令
- Shell命令——时间日期
- Linux shell 日期,时间相关的命令
- linux-shell命令之date【显示/设置系统日期/时间】
- Shell日期时间命令date
- linux -日期时间命令
- Linux Shell编程(20)——基本命令
- Linux Shell编程(21)——复杂命令
- Linux Shell编程(23)——文本处理命令
- Linux Shell编程(24)——命令替换
- linux下的时间和日期命令——date
- Linux系统编程(时间和日期)
- Linux命令,Shell编程
- shell 日期时间转换秒数 命令
- linux 常用日期时间命令
- Linux下Shell编程——sed命令基本用法
- Linux下Shell编程——sed命令基本用法
- Linux下Shell编程——sed命令基本用法
- Linux Shell编程(18)—— 循环控制
- 行为设计模式---模板方法模式(Template Method)
- Linux Shell编程(19)——测试与分支
- Linux Shell编程(20)——基本命令
- Linux Shell编程(21)——复杂命令
- Linux Shell编程(22)——时间/日期 命令
- 水一水
- 二叉搜索树转换成双向链表
- Linux Shell编程(23)——文本处理命令
- Linux Shell编程(24)——命令替换
- C++静态库与动态库
- Linux Shell编程(25)——I/O 重定向
- 数据库入门速成---ORACLE (02) 关联查询与分类汇总查询
- Linux Shell编程(26)——代码块重定向