linuxclock命令介绍和使用案例

韵味老鸟 2024-09-08 16:46:46

linux clock 命令介绍和使用案例

clock 命令在 Linux 中并不是一个标准的命令,通常在 Linux 系统中与时间和日期相关的命令主要是 date、hwclock 和 timedatectl

1. date 命令

date 命令用于显示和设置系统的日期和时间

使用案例:显示当前日期和时间:输出示例:root@meng:~# dateMon Sep 2 11:00:26 CST 2024设置系统时间(需要 root 权限):root@meng:~# sudo date -s "2024-09-02 11:01:00"Mon Sep 2 11:01:00 CST 2024root@meng:~# dateMon Sep 2 11:01:02 CST 20242. hwclock 命令

hwclock 命令用于访问硬件时钟(RTC),可以用来显示、设置和同步系统时间

root@meng:~# hwclock

2024-09-02 11:01:47.995908+08:00

root@meng:~# which hwclock

/usr/sbin/hwclock

root@meng:~# hwclock --help

Usage:

hwclock [function] [option...]

Time clocks utility.

Functions:

-r, --show display the RTC time

--get display drift corrected RTC time

--set set the RTC according to --date

-s, --hctosys set the system time from the RTC

-w, --systohc set the RTC from the system time

--systz send timescale configurations to the kernel

-a, --adjust adjust the RTC to account for systematic drift

--predict predict the drifted RTC time according to --date

Options:

-u, --utc the RTC timescale is UTC

-l, --localtime the RTC timescale is Local

-f, --rtc <file> use an alternate file to /dev/rtc0

--directisa use the ISA bus instead of /dev/rtc0 access

--date <time> date/time input for --set and --predict

--delay <sec> delay used when set new RTC time

--update-drift update the RTC drift factor

--noadjfile do not use /etc/adjtime

--adjfile <file> use an alternate file to /etc/adjtime

--test dry run; implies --verbose

-v, --verbose display more details

-h, --help display this help

-V, --version display version

For more details see hwclock(8).

3. timedatectl 命令

timedatectl 是 systemd 的一部分,用于查询和更改系统时钟及其设置

root@meng:~# timedatectl

Local time: Mon 2024-09-02 11:02:38 CST

Universal time: Mon 2024-09-02 03:02:38 UTC

RTC time: Mon 2024-09-02 03:02:36

Time zone: Asia/Shanghai (CST, +0800)

System clock synchronized: no

NTP service: active

RTC in local TZ: no

root@meng:~# which timedatectl

/usr/bin/timedatectl

root@meng:~# timedatectl --help

timedatectl [OPTIONS...] COMMAND ...

Query or change system time and date settings.

Commands:

status Show current time settings

show Show properties of systemd-timedated

set-time TIME Set system time

set-timezone ZONE Set system time zone

list-timezones Show known time zones

set-local-rtc BOOL Control whether RTC is in local time

set-ntp BOOL Enable or disable network time synchronization

systemd-timesyncd Commands:

timesync-status Show status of systemd-timesyncd

show-timesync Show properties of systemd-timesyncd

Options:

-h --help Show this help message

--version Show package version

--no-pager Do not pipe output into a pager

--no-ask-password Do not prompt for password

-H --host=[USER@]HOST Operate on remote host

-M --machine=CONTAINER Operate on local container

--adjust-system-clock Adjust system clock when changing local RTC mode

--monitor Monitor status of systemd-timesyncd

-p --property=NAME Show only properties by this name

-a --all Show all properties, including empty ones

--value When showing properties, only print the value

See the timedatectl(1) man page for details.

0 阅读:1

韵味老鸟

简介:感谢大家的关注