日期相关的命令(date,clock)

本文介绍Linux系统中关于日期和时间管理的基本命令,包括date、clock和cal的使用方法及其参数选项,帮助用户掌握如何查看和调整系统时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux日期相关的命令

一丶date系统时间

1、了解date
[root@centos7 ~]# type date     
    type查看date命令类型。
date is hashed (/usr/bin/date)
[root@centos7 ~]# whatis date   
    whatis显示手册页描述。

    whatis命令依赖于数据库刚装的系统或许数据库并未创建
    手动创建数据的命令
        centos6:makewhatis
        centos7:mandb

date (1)             - print or set the system date and time
date (1p)            - write the date and time
[root@centos7 ~]# whereis date  
    whereis定位一个命令的二进制文件,源文件,帮助手册。
date: /usr/bin/date /usr/share/man/man1/date.1.gz /usr/share/man/man1p/date.1p.gz
[root@centos7 ~]# which date
    which显示命令的完整路径。
/usr/bin/date

2、获取date的用法
[root@centos7 ~]# date --help
    date外部命令,获取date命令帮助。

3、date用法及描述:
Usage: date [OPTION]... [+FORMAT]
  or:  date [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.
    用给定的格式显示当前时间或者设置系统时间。

4、date常用选项:
-d, --date=STRING display time described by STRING, not 'now'
    -d 显示用字符串描述的时间。
    eg:[root@centos7 ~]# date -d '-5 day'
    Tue Jul 16 15:57:28 CST 2019

-s, --set=STRING  set time described by STRING
    -s 将字符串描述的时间设置为当前的系统时间。
    eg:[root@centos7 ~]# date -s "2019-8-20 13:20:20"
        Tue Aug 20 13:20:20 CST 2019

5、date显示时间的格式
FORMAT controls the output.  Interpreted sequences are:
格式可以控制date的输出,解释序列是:(只列出常用的)

%A   locale's full weekday name (e.g., Sunday)
%d   day of month (e.g., 01)
%F   full date; same as %Y-%m-%d 
%H   hour (00..23)
%m   month (01..12)
%M   minute (00..59)
%R   24-hour hour and minute; same as %H:%M
%s   seconds since 1970-01-01 00:00:00 UTC
%S   second (00..60)
%T   time; same as %H:%M:%S
%u   day of week (1..7); 1 is Monday
    eg:[root@centos7 ~]# date +%F
        2019-07-21
        [root@centos7 ~]# date +%T
        16:07:29
        [root@centos7 ~]# date +"%F %T"
        2019-07-21 16:07:40
        [root@centos7 ~]# 

6、date设置系统时间
    ①date [MMDDhhmm[[CC]YY][.ss]] | date 月日时分年.秒
    ②date -s "STRING"
        eg: ~]#date -s "2019-08-07 06:05:10"
            ~]#date 0807060519.10

二、clock硬件时间clock=hwclock

[root@centos7 ~]# type clock
clock is hashed (/usr/sbin/clock)
[root@centos7 ~]# whatis clock
clock (8)            - query or set the hardware clock (RTC)
clock (3)            - determine processor time
clock (3p)           - report CPU time used
[root@centos7 ~]# which clock
/usr/sbin/clock
[root@centos7 ~]# whereis clock
clock: /usr/sbin/clock /usr/share/man/man8/clock.8.gz /usr/share/man/man3/clock.3.gz /usr/share/man/man3p/clock.3p.gz

[root@centos7 ~]# clock --help
Usage:  hwclock [function] [option...]
hwclock常用来校正系统时间
Functions:
 -s, --hctosys  set the system time from the hardware clock
    以硬件时间为基准来更新系统时间
 -w, --systohc  set the hardware clock from the current 
    以系统时间为基准来更新硬件时间
[root@centos7 ~]#

三丶cal显示日历

[root@centos7 ~]# type cal
cal is /usr/bin/cal
[root@centos7 ~]# whatis cal
cal (1)              - display a calendar
cal (1p)             - print a calendar
[root@centos7 ~]# whereis cal
cal: /usr/bin/cal /usr/share/man/man1/cal.1.gz /usr/share/man/man1p/cal.1p.gz
[root@centos7 ~]# which cal
/usr/bin/cal


[root@centos7 ~]# cal --h
Usage:
 cal [options] [[[day] month] year]

Options:
 -1, --one        show only current month (default)
 -3, --three      show previous, current and next month
 -s, --sunday     Sunday as first day of week
 -m, --monday     Monday as first day of week
 -y, --year       show whole current year
[root@centos7 ~]# cal 12 2002
    December 2002   
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值