In most Ubuntu and similar Linux distributions, the systemctl tool has replaced power management commands that were used in previous releases. The following commands for instance have been replaced by systemctl as shown below :
halt → systemctl halt
poweroff → systemctl poweroff
reboot → systemctl reboot
For compatibility reasons however, the old commands are still available in the system, but it is recommended to rely on systemctl.
Using ‘systemctl’ command
The systemctl tool allows users to shut down the system either immediately or at a scheduled time via a time argument. This comes in handy for scheduled maintenance for instance when users are warned that a system shutdown has been programmed. Canceling the shutdown option of systemctl might also have some advantages.
In order to shut down the system, .i.e. power off the computer, type in the following command in your terminal as root:
systemctl poweroff [linux shutdown command line]
Make sure to save your work and back-up your changed documents since this command does not prompt you to proceed.
To shut down without powering off the machine, .i.e halt the system, execute the following command as root otherwise it will ask you for the password:
Note that running either of the commands above, by default, will cause the systemd utility to send an information message to all currently logged-in users into the system. In order to avoid the sending of this message by systemd, execute the command with the –no-wall switch as follows :
systemctl –no-wall poweroff
Read: How to list, start and stop services at boot time in Linux Ubuntu/Debian
Using ‘shutdown’ command
The shutdown command has the following syntax :
shutdown [OPTIONS] [TIME] [MESSAGE]
- Options – Shutdown options like power-off (default), halt or reboot the system.
- Time – The time argument indicates when the shutdown process will occur.
- Message – This specifies the message which will be sent to all logged-in users.
In order to power off the machine and therefore shut down the system at a specific time, run the command below as root:
shutdown –poweroff hh:mm
Where hh:mm is a placeholder for the time (in 24 hour format) at which you would want to shut down the system. See example in the snapshot below :
The file /run/nologin is created by systemd few minutes before the shutdown event in order to prevent other users from logging in.
In order to halt or shut down the system after a specific delay, run the following command as root:
shutdown –halt +m
Where +m designate the delay time in minutes. An example of a scheduled shutdown is shown below :
You could set the +m to the ‘now’ keyword which means an immediate shutdown will be performed as shown below :
I had to press Cancel on the authentication window in order not to shut down.
In order to cancel a pending shutdown , run the command below as root:
It is not possible to specify a time argument when canceling a scheduled shutdown. It is however possible to still send a message to all logged-in users by invoking the command :
sudo shutdown -c “system back to normal – canceling the reboot”
You could also perform a scheduled shutdown using the -h option as follows :
shutdown -h 60
This will shutdown the system after 60 minutes.
Read: How to fix Ubuntu boot issues
Restarting the System
Using ‘systemctl’ command
Restarting the system is achieved by the following Ubuntu restart command :
systemctl reboot [restart ubuntu command line]
This command, by default, causes the systemd tool to send a friendly message to all currently logged in users into the system. In order to prevent the broadcasting of this message, invoke the command with the –no-wall switch as follows:
systemctl –no-wall reboot
Using ‘shutdown’ command
Using the shutdown command, rebooting can be achieved via the following command :
It is also possible to specify a time argument as well as a custom message like the following command shows:
shutdown -r +20 “Garbage collection”
This will cause the system to be rebooted after 20 minutes and also broadcast the informative message “Garbage collection” .
Suspending the System
In order to suspend the system, type in the command below as root:
systemctl suspend [linux suspend]
The suspension command, will enable the current system state (complete context) to be saved on the RAM. The RAM, will not be powered off unlike most of the devices in the computer. Once the machine is turned on, the state saved on the RAM will be restored automatically. This operation is much faster than restoring the state from hibernation since the system state was not saved on the hard disk. A suspended system is prone to power outages however since the system state is on the RAM.
Read: How to fix high memory usage in Linux
Hibernating the System
Hibernating the system can be carried out using the following command :
systemctl hibernate [linux hibernate]
Contrary to the suspension operation, the command above will save the system state on the hard disk and not on the RAM, before powering off the computer.
The system will be restored to its previous state once the machine is turned back on.
Since the system state is not saved on the RAM, but rather on the hard disk, a power outage will not have any consequences on the data availability, i.e. data loss will not occur unless the hard disk is damaged. If the hard disk is not an SSD, the drawback would be a slow data restoration operation.
In order to both hibernate and also suspend the system, execute the following command as root:
The ‘systemctl’ and the ‘shutdown’ commands allow you to power-off, halt, reboot, suspend and hibernate your Linux system. To learn more about these commands, feel free to visit their respective ‘man’ pages.
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.