Linux PC 的启动/停止时间

Linux PC 的启动/停止时间

我想查看 Linux PC 的启动/停止时间。

我找到了这个命令,但是输出是错误的:

last reboot -F
reboot   system boot  4.15.0-46-generi Thu Mar 14 10:04:27 2019 - Thu Mar 14 15:31:11 2019  (05:26)

不对。现在应该是 09:04,而不是 10:04。

参见相关问题:https://askubuntu.com/questions/854567/last-reboot-is-missing-one-hour/859782

如何查看 Ubuntu 18.04 上正确的启动/停止时间?

答案1

# timestamps corresponds to your current timezone
user@node:~$ journalctl --list-boots
-3 0f2fcb9569384a2aa2d5492505f86cda Tue 2018-11-27 16:45:22 CET—Thu 2018-11-29 10:10:07 CET
-2 646787bd244d4230a5986f00207c1e8c Sun 2019-02-24 19:50:23 CET—Tue 2019-02-26 22:49:29 CET
-1 c922041a9a3847babd51ac79dd06923c Wed 2019-02-27 08:27:28 CET—Sun 2019-03-03 08:52:52 CET
 0 0aa03fbca4bf4976b922f9f77c63f65a Sun 2019-03-03 09:02:47 CET—Mon 2019-03-18 17:10:08 CET

# timestamps corresponds to universal timezone
user@node:~$ journalctl --list-boots --utc
-3 0f2fcb9569384a2aa2d5492505f86cda Tue 2018-11-27 15:45:22 UTC—Thu 2018-11-29 09:10:07 UTC
-2 646787bd244d4230a5986f00207c1e8c Sun 2019-02-24 18:50:23 UTC—Tue 2019-02-26 21:49:29 UTC
-1 c922041a9a3847babd51ac79dd06923c Wed 2019-02-27 07:27:28 UTC—Sun 2019-03-03 07:52:52 UTC
 0 0aa03fbca4bf4976b922f9f77c63f65a Sun 2019-03-03 08:02:47 UTC—Mon 2019-03-18 16:10:08 UTC

UTC 时区是普遍的这就是为什么它对于避免任何夏令时误解问题很有用。

来自journalctl手册页:

       --list-boots
           Show a tabular list of boot numbers (relative to the current boot), their IDs, and the timestamps of the first and last message pertaining to the boot.

PS:如果您只返回一行journalctl,只需创建文件夹/var/log/journal以启用多个磁盘日志保留

答案2

从 /var/log/messages 中 grepping rsyslog stsrt/stops 可能会满足您的需要,因为这是关机时首先启动的操作之一,也是最后停止的操作之一。

相关内容