I am new to Linux and I have installed some Linux distributions. I try to learn bash commands. I can shutdown my computer from Desktop manager easily. But How can I shutdown system from bash without a GUI.
There are different ways to shutdown Linux system. Following commands will work most of the distributions like Ubuntu, Debian, Mint, Kali, CentOS, RedHat, Fedora.
We can shutdown a Linux system with
poweroff command. If we want to force the shutdown we can use
Reboot After Shutdown with Poweroff Command
poweroff command provides the
--reboot option which will start the Linux system after a shutdown.
$ poweroff --reboot
halt command change system run level by using systems service manager like systemd or service.
reboot command actually a synonym of the
poweroff command with
--reboot option. We can use
--halt option in order to halt and do not restart the system like below.
$ reboot --halt
- To shutdown system –halt parameter should be provided.
The most popular and well known command is
shutdown command. This command automatically shutdown the current system.
Shutdown System After Given Time
We can set timer to shutdown system. In this example we will shutdown the system after 5 minutes the command issued.
$ shutdown -h +5
Send Message To The System Users Before Shutdown
We can send message to the system users with shutdown command. This is useful is we give some time and send message to provide this information to the system users. In this example we will send the message
System will be shutdown after 5 minutes
$ shutdown -h +5 "System will be shutdown after 5 minutes"