Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the shutdown and restart commands in Linux

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

What are the shutdown and restart commands in Linux? I believe many inexperienced people are at a loss about this. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Sync command

The sync command is used to write the data stored in the system to disk in a timely manner. It is recommended to execute the sync command manually before shutdown and restart. The main reason is that when the program is executed, the operation speed of cpu is much faster than that of disk io, so a lot of data is cached to memory and then written to disk. Manual execution of sync command can prevent data loss.

Command path: / bin/sync, all users have permission to execute sync commands.

Shutdown command

In Linux system, shutdown command can be used to operate shutdown or restart. Shutdown command is more commonly used to perform shutdown operation. Generally, people prefer to use simple reboot command.

In addition to the most basic shutdown and restart functions, the shutdown command also has the following functions:

Before shutting down the computer, you can set the shutdown message to be sent to online users to prevent multiple users from affecting other users online.

Send a warning to online users and prohibit other users from logging in, but it is not really turned off, just to avoid multi-user interference

Command Overview

Format of shutdown command: shutdown [option] [time] [warning]

Command path: / sbin/shutdown, this command requires root permission to execute

Common options:

-h do not restart after shutdown-r restart immediately after shutdown-k does not really shut down but just sends a warning to all users-f skip fsck-n fast shutdown during restart without going through the init program-c cancel an already running shutdown

Example

By default, shutdown will wait one minute before shutting down and broadcast a warning message to online users, as shown below:

[root@localhost ~] # shutdown# prompt will perform shutdown at this time in one minute. You can use shutdown-c to cancel Shutdown scheduled for Fri 2019-09-06 14:29:38 CST, and another online user of use 'shutdown-c' to cancel.# will be able to receive broadcast messages [calmsnow@localhost ~] $# broadcast messages from root The system will shut down Broadcast message from root@localhost.localdomain in a minute (Fri 2019-09-06 14:28:38 CST): The system is going down for power-off at Fri 2019-09-06 14:29:38 CST!

Shutdown-h shuts down after 3 minutes and broadcasts warning messages to online users. Write an integer after-h, indicating how many minutes after the shutdown, as shown below:

[root@localhost ~] # shutdown-h 3Shutdown scheduled for Fri 2019-09-06 14:41:24 CST, use 'shutdown-c' to cancel.# another online user will be able to receive broadcast messages [calmsnow@localhost ~] $Broadcast message from root@localhost.localdomain (Fri 2019-09-06 14:38:24 CST): The system is going down for power-off at Fri 2019-09-06 14:41:24 CST!

Shutdown-h now shuts down immediately and there will be no broadcast messages.

The halt and poweroff commands can also achieve a similar immediate shutdown effect of shutdown-h now, but it is said that both halt and poweroff commands are not very secure (the so-called insecurity means that the data cannot be saved correctly when shutting down the system process), so shutdown-h now is commonly used for shutdown.

By default, shutdown-r waits for one minute before restarting and broadcasts a warning message to online users, as shown below:

[root@localhost ~] # shutdown-rShutdown scheduled for Fri 2019-09-06 14:53:26 CST, use 'shutdown-c' to cancel.# another online user will be able to receive broadcast messages [calmsnow@localhost ~] $Broadcast message from root@localhost.localdomain (Fri 2019-09-06 14:52:26 CST): The system is going down for reboot at Fri 2019-09-06 14:53:26 CST!

Shutdown-r restarts after 3 3 minutes and broadcasts warning messages to online users. Write an integer after-r, which indicates how many minutes it takes to restart:

[root@localhost ~] # shutdown-r 3Shutdown scheduled for Fri 2019-09-06 15:00:15 CST, use 'shutdown-c' to cancel.# another online user will be able to receive broadcast messages [calmsnow@localhost ~] $Broadcast message from root@localhost.localdomain (Fri 2019-09-06 14:57:15 CST): The system is going down for reboot at Fri 2019-09-06 15:00:15 CST!

Shutdown-r now restarts immediately without any broadcast messages

Restart generally people prefer to use a simple reboot command, you can think of the reboot command is almost equivalent to shutdown-r now, are safe commands.

Reboot command

The reboot command can be thought of as almost equivalent to shutdown-r now, used to restart the Linux system, and is also a secure command.

After reading the above, have you mastered what the shutdown and restart commands are in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report