这是我参与11月更文挑战的第11天,活动详情查看:2021最后一次更文挑战
Linux 小知识 丨who、时区命令
Who 命令
who - [husfV] [user] 显示当前登录系统的用户
[root@VM-8-10-centos ~]# who
root pts/0 2021-11-04 14:22 (124.128.97.210)
[root@VM-8-10-centos ~]# who --help
Usage: who [OPTION]... [ FILE | ARG1 ARG2 ]
Print information about users who are currently logged in.
-a, --all same as -b -d --login -p -r -t -T -u
-b, --boot time of last system boot
-d, --dead print dead processes
-H, --heading print line of column headings # 显示标题信息
-l, --login print system login processes
--lookup attempt to canonicalize hostnames via DNS
-m only hostname and user associated with stdin
-p, --process print active processes spawned by init
-q, --count all login names and number of users logged on # 只显示登入系统的账号名称和总人数
-r, --runlevel print current runlevel
-s, --short print only name, line, and time (default) # 此参数将忽略不予处理,仅负责解决who指令其版本的兼容性问题
-w # 显示用户的信息状态栏
-t, --time print last system clock change
-T, -w, --mesg add user's message status as +, - or ?
-u, --users list users logged in # 显示闲置时间,如果一份之后有操作,则显示点,如果超过24小时误操作,则显示old字符串
--message same as -T
--writable same as -T
--help display this help and exit
--version output version information and exi
[root@VM-8-10-centos ~]# who -w # 显示用户的信息状态栏
root + pts/0 2021-11-04 14:22 (124.128.97.210)
[root@VM-8-10-centos ~]# who -H # 显示明细(标题)信息
NAME LINE TIME COMMENT
root pts/0 2021-11-04 14:22 (124.128.97.210
timedatectl 命令
校正服务器时间、时区
[root@VM-8-10-centos ~]# timedatectl --help
timedatectl [OPTIONS...] COMMAND ...
Query or change system time and date settings.
-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
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
与 ntp时间服务器 同步
timedatectl set-ntp true
[root@VM-8-10-centos ~]# timedatectl || timedatectl status
Local time: 四 2021-11-04 15:46:12 CST #本地时间, 操作系统时间 背景时间
Universal time: 四 2021-11-04 07:46:12 UTC #世界标准时间UTF 8小时时差
RTC time: 四 2021-11-04 07:46:11 #主板时间
Time zone: Asia/Shanghai (CST, +0800) # 时区
System clock synchronized: yes # ntp 开启同步
NTP service: active
RTC in local TZ: no
查看可选择的时区
timedatectl list-timezones
timedatectl set-timezone "Asia/Shanghai" #设置时区
timedatectl set-ntp true #开启ntp
timedatectl set-ntp false #禁用ntp
timedatectl set-time "2030-01-01 00:00:00" #禁用ntp后可以设置时间
clear 命令
清除屏幕