Linux common commands: shutdown command

 shutdown shuts down the system in a safe manner.

1. Command format:

  shutdown [parameter] [time] 

2. Command function:

    Function:  System shutdown command, the shutdown command can close all programs, and restart or shut down according to the user's needs, all logged in users can see the shutdown information prompt.

    Rationale:   shutdown is implemented by notifying the init process and asking it to change runlevels. Runlevel 0 is used to shut down the system, runlevel 6 is used to restart the system, and runlevel 1 is used to put the system into the state of executing system management tasks. If the -h or -r flag is not given, this is the default working state of the shutdown command. .

3. Option parameters:

1) -h shuts down the system

2) -r restart after shutdown

3) -k just sends the message to all users, but does not actually shut down

4) -f Skip disk check on reboot

5) -F Force disk detection on reboot.

6) -c Cancels a running shutdown process. It is not possible to specify the time parameter for this option, but you can enter an explain message on the command line to explain to all users.

     (The general shutdown command can be interrupted by pressing the "+" sign) 

 

4. Example of use:

  1) Execute the shutdown command at a specific time:

shutdown -h now          // shutdown immediately
shutdown -h 12:00 // shutdown at 12:00 

  2) Shut down after specified 5 minutes, and send a warning message to the logged-in user at the same time

copy code
root@Unbuntu:/home/sunjimeng# shutdown +5 "This System will be shutdown in 5 minute!"
 Broadcast message from sunjimeng@Unbuntu (/dev/pts/ 6) at 10:38 ... The system is going down for maintenance in 5 minutes! //System reminder This System will be shutdown in 5 minutes! //User-defined reminder
copy code

      3) Cancel the shutdown command

shutdown -c

      4) Execute the shutdown restart command at a specific time, and cancel

copy code
[xiong@localhost ~ ]$ su root //Must be root user
password:
[root@localhost xiong]# shutdown -r + 3 " shutdown restart after 3 minutes " Shutdown scheduled for 3 2016-06-29 19:47:26 PDT , use ' shutdown -c ' to cancel. [root@localhost xiong] # Broadcast message from [email protected] (Wed 2016- 06- 29 19: 44: 26 PDT): The system is going down for reboot at Wed 2016- 06- 29 19: 47: 26 PDT! [root@localhost xiong]# shutdown - c Broadcast messagefrom [email protected] (Wed 2016-06-29 19:44:50 PDT): The system shutdown has been cancelled at Wed 2016-06-29 19:45:50 PDT!
copy code

     5) shutdown -k does not really shut down, it just sends a reminder to each logged in user

copy code
[root@localhost xiong]# shutdown -k "Warning:Maybe the system will be shutdown." Failed to parse time specification: Warning:Maybe the system will be shutdown. [root@localhost xiong]# shutdown -k 5 "Warning:Maybe the system will be shutdown." Shutdown scheduled for 三 2016-06-29 19:53:56 PDT, use 'shutdown -c' to cancel. [root@localhost xiong]# Broadcast message from [email protected] (Wed 2016-06-29 19:48:56 PDT): Warning:Maybe the system will be shutdown. The system is going down for power-off at Wed 2016-06-29 19:53:56 PDT!
copy code

      6) Fast or slow reboot (Unbuntu has -f or -F parameter, CentOS does not)

shutdown -f [time]          // Fast restart, ignore disk check
shutdown -F [time]          // Force disk check

 5. Others:

      1) Permanently change the system time:

// The date command can only temporarily change the system time, and the time will return to before after the shutdown and restart, so the time needs to be written to the bios
[root@localhost xiong]# date -s " 2016-06-30 11:05:10 " Thursday , June 30 , 2016 11:04:30 PDT [root@localhost xiong]# clock -w

     2) Display the processor architecture of the machine:

[root@localhost xiong]# arch
x86_64

      3) Other shutdown commands:

init 0              // shutdown
init 6 // shutdown and restart reboot // shutdown and restart

      4) clock and date commands:

copy code
// Only the superuser can set the hardware clock.
[xiong@localhost ~]$ su root                                  
password:
[root@localhost xiong]# clock -- set --date= " 05/04/2013 14:30:01 " //Set the hardware time to 2013 [root@localhost xiong]# clock Saturday, May 04, 2013 14:30:12 - 0.388214 seconds[root@localhost xiong]# date //The hardware time is 2013 and the system time is 2016 Wednesday, June 29, 2016 20:20:36 PDT [root @ localhost xiong]# clock - s //set the system time according to the hardware time [root@localhost xiong]# date 2013-05-04 Saturday 14:31:04 PDT [root@localhost xiong]# clock 2013-05-04 Saturday 14:31 Minutes 09 seconds - 0.101952 seconds // Both system time and hardware time are in 2013 [root@localhost xiong]# date -s " 2016-06-30 11:22:10" //Set the system time to 2016 , Thursday , June 30, 2016, 11:22:10 PDT [root@localhost xiong]# clock //The system time is 2016, and the hardware time is 2013 Saturday, May 4, 2013 14 Hour 32 minutes 13 seconds - 0.559223 seconds [root@localhost xiong]# clock - w //Set the hardware time according to the system time [root@localhost xiong]# date Thursday , June 30, 2016 11:22:51 PDT [root@ localhost xiong]# clock Thu Jun 30 2016 11:22:56 - 0.968643 sec
copy code

     5) Display the information of the native shell, you can also change the shell

copy code
[xiong@localhost ~]$ chsh -l
/bin/sh
/bin/bash
/sbin/nologin /usr/bin/sh /usr/bin/bash /usr/sbin/nologin /bin/tcsh /bin/csh [xiong@localhost ~]$ chsh -v chsh,来自 util-linux 2.23.2
copy code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326135579&siteId=291194637