Debian 时间戳启用与同步指南
一、系统时间同步 NTP 或 chrony
sudo apt update && sudo apt install ntpsudo systemctl start ntp && sudo systemctl enable ntpsudo systemctl status ntpsudo ntpdate pool.ntp.orgserver 0.debian.pool.ntp.org iburstserver 1.debian.pool.ntp.org iburstserver 2.debian.pool.ntp.org iburstserver 3.debian.pool.ntp.org iburstsudo systemctl restart ntpntpq -psudo chronyc makestepdate 查看系统时间是否已校准二、硬件时钟与系统时钟同步
sudo hwclock --systohcsudo hwclock --hctosys--systohc 将正确时间写回硬件时钟,避免重启后时间漂移。三、命令历史记录时间戳 history
export HISTTIMEFORMAT="%F %T "~/.bashrc,在文件末尾添加:export HISTTIMEFORMAT="%F %T "source ~/.bashrchistory 时,每条命令前会显示 YYYY-MM-DD HH:MM:SS 的时间戳。四、内核日志 dmesg 时间戳
grep CONFIG_PRINTK_TIME /boot/config-$(uname -r)dmesg 默认显示自系统启动以来的 秒.纳秒 时间戳/proc/uptime 进行计算(例如用 awk/bc 做差值换算)