It's easy to shutdown your Linux system when you are physically touch your machine. When everything is not going well (like hang), you can press and hold the power button to force your computer to off. Different story applies when you are working with a server via SSH or other remote access methods. All you have is terminal, so you have to work with command lines.
In case you want to shutdown your Linux system, there are at least four commands you can make use of. The vast majority of Linux users who want to shutdown their Linux system via terminal will probably use the
shutdown command. Apparently, it is not the only command you can use to shutdown Linux. You can even use the
reboot command, which originally used to reboot system instead of shutdown.
Following are are four commands you can use to shutdown your Linux system.
1. shutdown
The first command you can use to shutdown your Linux system is
shutdown. This is the standard command used by the vast majority of Linux users. While the major use of this command is to turn your computer off, you can also use it to reboot the system.
shutdown features several parameters. If you want to shutdown your machine right away, you can use the
shutdown command followed by
nowoption.
shutdown -h now
In general, following is the syntax of the
shutdown command.
shutdown [OPTION] [TIME] [MESSAGE]
Following is the example.
shutdown -h +10 "Attention!, system is going down for upgrade. Please save your work."
The command above will turn the system off after 10 minutes, while the message between the quote sign will be diffused to the all logged in users after you hit the enter button. You can also use
shutdown to reboot the system by using the parameter of
-r. You can type
shutdown --helpto see all parameters provided by
shutdown.
2. halt
The second command you can use to shutdown your Linux system is
halt. In some distros, you need a root access to run this command. Unlike
shutdown, this command has no option to delay the shutdown process. Thus, you need to make sure you really want to turn your system off right away if you opt to use this tool. You can also type
halt --help to see all parameters offered by
halt.
3. poweroff
Next, there is also the
poweroff command you can use to shutdown your Linux system. This command is exactly the same as the
halt command. When you type
poweroff --helpon the terminal, you will see the exactly same output as
halt.
4. reboot
As the name suggests, this tool is natively used to reboot the Linux system instead of shutdown. However,
reboot also comes with a parameter which you can use to turn the system off. The parameter is
-p. To see all parameters provided by this command you can also type
reboot --help on the terminal.