According to the manual page, shutting down a system means bringing the system down in a secure way or gracefully.
The simplest Linux terminal command to power down a system is 'shutdown' command and it should work on Ubuntu and Centos/RHEL machines. After the shutdown command is issued, the system will send a notification to all logged-in users and process indicating that the machine is going down.
Now let us discuss different commands available in Linux to shutdown with some practical examples.
1) Linux Shutdown Command
The syntax for shutdown command and its options is below
shutdown [OPTION]... TIME [MESSAGE]
By default, machine will go down in 1 minute and you can cancel the schedule by issuing
shutdown -c. The time can be given in 24 hour format HH:MM or +m, where m is the number of minutes to wait before shutting down the system.
• The system can be shut down immediately by providing "now" in place of time. For example
$ sudo shutdown -h now
will bring down the system immediately.
• To shutdown the machine after given number of minutes or set a delay, for example
$ sudo shutdown -h +3 Broadcast message from root (pts/0) (Tue Nov 6 00:23:48 2012): The system is going DOWN for system halt in 3 minutes!
• In 24 hour format
$ sudo shutdown -h 00:45 Broadcast message from root (pts/0) (Tue Nov 6 00:30:54 2012): The system is going DOWN for system halt in 15 minutes!
• A custom message can also be provided
$ sudo shutdown -h +5 "Save your work." Broadcast message from root (pts/0) (Tue Nov 6 00:43:48 2012): Save your work. The system is going DOWN for system halt in 5 minutes!
• This command waits for command completion before giving back the prompt. So it can be cancelled with ctrl+c. Shutdown can also be cancelled with the -c option.
$ sudo shutdown -c
2) Poweroff Command
Another command that can be used for bringing down the system is poweroff command.
$ sudo poweroff Broadcast message from root (pts/0) (Tue Nov 6 09:39:17 2012): The system is going down for system halt NOW!
3) Halt Command
The halt command will also shut down the system.
$ sudo halt Broadcast message from root (pts/0) (Tue Nov 6 09:42:43 2012): The system is going down for system halt NOW!
4) Init Command
The init command is used to change the runlevel of the Unix/Linux system. These system runlevels are 0-6. The runlevel 0 is used for system halt.
$ sudo init 0 INIT: Switching to runlevel: 0 INIT: Sending processes the TERM signal
Unlike other commands we have seen so far, the init command will not broadcast any message about system halt.
5) Systemctl Commands
Now, let's check how to use systemctl command to shutdown a system.
The following command will shutdown system and poweroff the machine and will send a notification to all logined users.
$sudo systemctl poweroff
The following command will shutdown the system but won't poweroff the machine. This will send a notification to all logined users.
$sudo systemctl halt
Poweroff the machine but won't send any notification to all logined users.
$sudo systemctl --no-wall poweroff
To display shutdown details run below command.
$sudo journalctl -u systemd-shutdownd