当前位置: 首页 > 编程文章 >

Linux reboot命令详解与参数用法

Linux reboot命令详解与参数用法

作者:江舟时间:2025-07-30 10:46:15浏览:595

reboot命令用于重启Linux系统,功能相当于Windows中的restart。该命令支持-n、-w、-d、-f、-i等多个参数以控制重启行为,如强制重启、关闭网络或仅写入日志。通过man reboot可查看详细帮助信息,管理员可根据需求选择是否同步数据或调用shutdown指令,确保系统安全重启。

本文目录展开

reboot命令简介与基本语法

命令简介:

此命令旨在执行Linux系统的重启操作,其作用等同于Windows系统中的restart功能。

命令语法:

/sbin/reboot [-n] [-w] [-d] [-f] [-i]

或

reboot [-n] [-w] [-d] [-f] [-i]

命令参数:

参数

长参数

描叙

-d

重新启动时不把数据写入记录文件/var/tmp/wtmp

-f

强制重新开机,不调用shutdown指令的功能。

-h

在系统关机或poweroff之前,将所有的硬盘处于待机模式

-i

关闭网络设置之后再重新启动系统

-n

保存数据后再重新启动系统

-p

When halting the system, do a poweroff. This is the default when halt is called as poweroff

-w

仅做测试,并不真的将系统重新开机,只会把重开机的数据写入/var/log目录下的wtmp记录文件

--help

显示命令在线帮助

使用示例:

1: 查看reboot命令的帮助信息


[root@DB-Server ~]# reboot --help
usage: reboot [-n] [-w] [-d] [-f] [-h] [-i]
    -n: don't sync before halting the system
    -w: only write a wtmp reboot record and exit.
    -d: don't write a wtmp record.
    -f: force halt/reboot, don't call shutdown.
    -h: put harddisks in standby mode.
    -i: shut down all network interfaces.

[root@DB-Server ~]# man reboot


[root@DB-Server ~]# man reboot
HALT(8)        Linux System Administrator鈥檚 Manual       HALT(8)
 
NAME
    halt, reboot, poweroff - stop the system.
 
SYNOPSIS
    /sbin/halt [-n] [-w] [-d] [-f] [-i] [-p] [-h]
    /sbin/reboot [-n] [-w] [-d] [-f] [-i]
    /sbin/poweroff [-n] [-w] [-d] [-f] [-i] [-h]
 
DESCRIPTION
    Halt notes that the system is being brought down in the file /var/log/wtmp, and then either tells the kernel to halt, reboot or poweroff the system.
 
    If halt or reboot is called when the system is not in runlevel 0 or 6, in other words when it鈥檚 running normally, shutdown will be invoked instead (with
    the -h or -r flag). For more info see the shutdown(8) manpage.
 
    The rest of this manpage describes the behaviour in runlevels 0 and 6, that is when the systems shutdown scripts are being run.
 
OPTIONS
    -n   Don鈥檛 sync before reboot or halt. Note that the kernel and storage drivers may still sync.
 
    -w   Don鈥檛 actually reboot or halt but only write the wtmp record (in the /var/log/wtmp file).
 
    -d   Don鈥檛 write the wtmp record. The -n flag implies -d.
 
    -f   Force halt or reboot, don鈥檛 call shutdown(8).
 
    -i   Shut down all network interfaces just before halt or reboot.
 
    -h   Put all harddrives on the system in standby mode just before halt or poweroff.
 
    -p   When halting the system, do a poweroff. This is the default when halt is called as poweroff.
 
DIAGNOSTICS
    If you鈥檙e not the superuser, you will get the message 鈥榤ust be superuser鈥? Users logged in locally on the console can call halt, reboot, and poweroff
    without supplying the root password, due to pam_console (8).
 
NOTES
    Under older sysvinit releases , reboot and halt should never be called directly. From release 2.74 on halt and reboot invoke shutdown(8) if the system is
    not in runlevel 0 or 6. This means that if halt or reboot cannot find out the current runlevel (for example, when /var/run/utmp hasn鈥檛 been initialized
    correctly) shutdown will be called, which might not be what you want. Use the -f flag if you want to do a hard halt or reboot.
 
    The -h flag puts all harddisks in standby mode just before halt or poweroff. Right now this is only implemented for IDE drives. A side effect of putting
    the drive in standby mode is that the write cache on the disk is flushed. This is important for IDE drives, since the kernel doesn鈥檛 flush the write-cache
    itself before poweroff.
 
    The halt program uses /proc/ide/hd* to find all IDE disk devices, which means that /proc needs to be mounted when halt or poweroff is called or the -h
    switch will do nothing.
 
AUTHOR
    Miquel van Smoorenburg, miquels@cistron.nl
 
SEE ALSO
    shutdown(8), init(8), pam_console(8)
 
                 Nov 6, 2001             HALT(8)
(END)

2:强制重新开机,不调用shutdown指令的功能


 [root@DB-Server ~]# reboot -f

3:关闭网络设置之后再重新启动系统


[root@DB-Server ~]# reboot -i
 
Broadcast message from root (pts/1) (Mon Jul 28 11:31:28 2014):
 
The system is going down for reboot NOW!

4:保存数据后再重新启动系统


[root@DB-Server ~]# reboot -n
 
Broadcast message from root (pts/1) (Mon Jul 28 11:33:57 2014):
 
The system is going down for reboot NOW!

5:重新启动时不把数据写入记录文件/var/tmp/wtmp


[root@DB-Server ~]# reboot -d
 
Broadcast message from root (pts/2) (Mon Jul 28 11:23:26 2014):
 
The system is going down for reboot NOW!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持本站。

上一篇
Linux中文件描述符fd与文件指针FILE*互相转换实例解析

在Linux系统编程中,文件描述符fd与C标准库文件指针FILE*的相互转换是常见需求。glibc提供了fdopen和fileno两个函数实现这一功能,二者均不创建新的文件描述符,而是建立关联或提取引用。实验表明,通过fdopen创建的FILE对象关闭时会自动释放底层fd,若重复调用close会导致“Bad file descriptor”错误。此外,fdopen的模式参数需与fd的打开模式兼容,但"w"和"w+"不会触发截断操作。

下一篇
Linux虚拟机NAT模式下ifconfig无法查看IP的解决方法

在Linux虚拟机中,若使用ifconfig或ip addr命令无法获取IP地址,通常是因为网卡未自动启动。本文介绍通过修改/etc/sysconfig/network-scripts/ifcfg-ens33配置文件,将ONBOOT参数设为yes,并重启网络服务来恢复网络连接的具体步骤。

相关文章

更多
Linux命令last详解:查看用户登录记录与参数用法

Linux系统中的last命令用于读取/var/log/wtmp等日志文件,列出当前及过去登录系统的用户信息。该命令通过解析utmp、wtmp和btmp文件,展示用户名、终端类型、IP地址、登录起止时间及持续时长等关键数据。掌握last命令及其-a、-R、-f、-t等参数,可有效监控系统访问历史、排查异常登录行为并辅助安全审计工作。

2025.01.25 481
LINUX下PHP程序实现WORD文件转化为PDF文件的方法

本文介绍在LINUX环境下通过PHP程序将Word文件转换为PDF文件的具体实现方法。文中提供了相关的代码示例及参考链接,旨在帮助开发者解决文件格式转换需求,提升文档处理效率。

2026.11.12 1,000
Linux主机AMH管理面板安装与建站指南

AMH是一款独立的LNMP/Nginx虚拟主机管理面板,支持Centos、Debian和Ubuntu系统。本文介绍如何在纯净Linux系统中通过脚本安装AMH 4.2版本,包括设置MySQL和管理员密码。安装完成后,通过Web端配置虚拟主机、绑定域名、创建FTP账号及数据库,即可快速搭建网站。

2026.11.13 999
Linux内核container_of宏原理与实现解析

Linux内核中container_of宏用于通过结构体成员地址反推结构体首地址。其核心依赖于offsetof宏计算成员偏移量,利用( char *)ptr减去偏移量并强转为目标类型指针实现定位。该宏还包含类型检查机制以增强代码安全性。

2026.06.01 995
Linux、Windows 及源码安装 Git 完整指南

本文介绍在 Linux、Windows 系统及从源代码三个环境下安装 Git 的具体方法。Linux 用户可通过 yum 或 apt-get 使用包管理器快速部署;Windows 用户可选择官方 Git for Windows 安装包或 GitHub for Windows,后者提供图形界面与 PowerShell 支持;此外,文章还详细说明了通过编译源码获取最新版本的依赖库准备、下载及构建流程。

2026.06.03 993
Linux useradd 命令详解:群组与家目录配置实战

在 Linux 系统中,useradd 是用于创建或更新用户信息的底层命令。由于直接使用较为复杂,Debian 系发行版提供了 adduser 脚本作为简化封装。本文基于 Ubuntu14.04 环境,深入解析 useradd 在处理初始群组(-g/-G/-N)和家目录(-m/-d)时的具体行为差异,并通过多个实例展示如何精确控制用户登录 Shell、群组归属及目录结构。

2025.06.14 992

专题推荐

更多
PHP 类与对象定义及继承

先看类声明、对象实例与属性访问。理解对象的创建和销毁后,再读继承、方法重载和关键字对照。已有代码遇到继承行为差异时,可进一步查看 final 方法与反射实例。

PHP 定时任务配置与运行

先确定任务运行间隔以及是否允许重叠。固定时间触发先看 Cron 案例,框架内和常驻服务再读对应示例。

Yii2 队列配置与常驻运行

先用一个最小任务跑通入队和消费,再检查 Web 与 Console 是否加载了相同的队列配置。确认命令能手动运行后再配置 Supervisor,最后验证进程重启时的处理情况。

PHP Session 过期时间设置方法

浏览器关闭、服务端回收和业务规定的闲置超时,可能在不同时间发生。对照配置项与应用层时间戳的做法,检查会话何时仍可读、何时应要求重新登录。

PHP URL 编码和解码方法

URL 路径片段和查询参数对空格的处理方式不同。先比较 urlencode 与 rawurlencode,再沿解码过程核对中文、加号和百分号,检查地址是否被重复编码或提前解码。

在线工具箱

更多
键码查询
键码查询

按下键盘按键时查看浏览器记录的键名和事件信息。

.env 配置检查
.env 配置检查

本地检查 .env 键值语法、引号、重复键及空值,预览解析结果,辅助排查 PHP 和 Laravel 环境配置。

进制转换
进制转换

转换二进制、十进制、十六进制等数值表示,辅助程序调试与进制学习。

HTML 标签安全清理
HTML 标签安全清理

清理 HTML 片段中的标签或危险内容,辅助整理待展示的文本。

文件 Base64 转换
文件 Base64 转换

把文件转为 Base64 文本,也可将编码内容还原为文件,方便接口传输与调试。