欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 金融 > 查看linux系统重启的日志

查看linux系统重启的日志

2025/3/13 14:23:43 来源:https://blog.csdn.net/Fireworkit/article/details/146195772  浏览:    关键词:查看linux系统重启的日志

文章目录

    • 方法 1:使用 last 命令
    • 方法 2:使用 journalctl 命令(适用于 systemd 系统)
    • 方法 3:查看 /var/log/wtmp 文件
    • 方法 4:查看 /var/log/messages 或 /var/log/syslog
    • 方法 5:查看 /var/log/boot.log
    • 方法 6:使用 uptime 命令

在 Linux 系统中,系统重启的日志通常记录在系统日志文件中。你可以通过以下几种方式查看系统重启的日志,以确定系统何时重启。
● last reboot:查看系统重启记录。
● journalctl:适用于 systemd 系统,查看详细的启动日志。
● /var/log/wtmp:记录系统登录、注销和重启事件。
● /var/log/messages 或 /var/log/syslog:查找系统日志中的重启记录。
● /var/log/boot.log:查看系统启动时的日志。
● uptime:查看系统上次启动的时间。

方法 1:使用 last 命令

last 命令可以显示系统的重启和关机记录。

  1. 运行以下命令:
    last reboot
  2. 输出示例:
    reboot system boot 5.4.0-42-generic Tue Oct 10 14:30:01 2023 - Tue Oct 10 15:00:01 2023 (00:30)
    reboot system boot 5.4.0-42-generic Mon Oct 9 09:15:01 2023 - Mon Oct 9 10:00:01 2023 (00:45)
    ○ 每一行表示一次重启事件。
    ○ 时间格式为 月 日 时:分:秒 年。

方法 2:使用 journalctl 命令(适用于 systemd 系统)

journalctl 是 systemd 系统的日志管理工具,可以查看系统日志,包括重启记录。

  1. 运行以下命令查看重启日志:
    sudo journalctl -b
    ○ -b 选项表示查看当前启动的日志。
    ○ 如果要查看上一次启动的日志,可以使用:
    sudo journalctl -b -1
    ○ 如果要查看所有启动的日志,可以使用:
    sudo journalctl --list-boots
    输出示例:
    0 abc1234 Tue 2023-10-10 14:30:01 - Tue 2023-10-10 15:00:01 (30min)
    -1 xyz5678 Mon 2023-10-09 09:15:01 - Mon 2023-10-09 10:00:01 (45min)
  2. 如果要查看特定时间段的日志,可以使用时间过滤器。例如:
    sudo journalctl --since “2023-10-10 00:00:00” --until “2023-10-10 23:59:59”

方法 3:查看 /var/log/wtmp 文件

/var/log/wtmp 文件记录了系统的登录、注销和重启事件。可以使用 last 命令解析该文件。

  1. 运行以下命令:
    last -f /var/log/wtmp
  2. 输出示例:
    reboot system boot 5.4.0-42-generic Tue Oct 10 14:30:01 2023 - Tue Oct 10 15:00:01 2023 (00:30)
    reboot system boot 5.4.0-42-generic Mon Oct 9 09:15:01 2023 - Mon Oct 9 10:00:01 2023 (00:45)

方法 4:查看 /var/log/messages 或 /var/log/syslog

在某些 Linux 发行版中,系统日志会记录在 /var/log/messages 或 /var/log/syslog 文件中。

  1. 使用 grep 命令查找重启相关的日志:
    grep “systemd: Started” /var/log/messages
    或:
    grep “systemd: Started” /var/log/syslog
  2. 输出示例:
    Oct 10 14:30:01 hostname systemd: Started User Manager for UID 1000.
    Oct 10 14:30:01 hostname systemd: Started Session 1 of user root.

方法 5:查看 /var/log/boot.log

/var/log/boot.log 文件记录了系统启动时的日志。

  1. 使用以下命令查看:
    cat /var/log/boot.log
  2. 输出示例:
    [ OK ] Started User Manager for UID 1000.
    [ OK ] Started Session 1 of user root.

方法 6:使用 uptime 命令

uptime 命令可以显示系统已经运行了多长时间,从而推断出上次重启的时间。

  1. 运行以下命令:
    uptime -s
  2. 输出示例:
    2023-10-10 14:30:01
    ○ 这表示系统上次启动的时间是 2023-10-10 14:30:01。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词