The Linux terminal is a rather powerful utility. You can do just about anything using it, including, of course, shutting down your computer.
In this article, we’re going to take a look at how you can use the Linux terminal to shutdown or reboot your system.
How to shut down Linux using the terminal?
To shut down your Linux machine, you’re going to have to use the shutdown command. The basic syntax is as follows.
shutdown [flags] [time] [message if any]
- Flags: These are the options you can specify while shutting your PC down. They can be anything from halting, power off (default) to simply rebooting the system.
- Time: This argument specifies the time of the shutdown.
- Message: Broadcasts a message to all users before shutting the machine down.
In a lot of recent Linux distros, the shutdown command is simply an alias to the systemctl command and hence is available in the system only for compatibility reasons.
If used with no arguments, the system will simply schedule a shutdown a minute later you type the command.
sudo shutdown
Also read: How to remove a Directory in Linux?
How to schedule shut down in Linux?
If you’d like to schedule a shutdown for your Linux machine, use the shutdown command followed by the time.
sudo shutdown 10:00
The aforementioned example will shut the machine down at 10 AM.
sudo shutdown +10
When used in this manner, the system will schedule a shut down ten minutes from when you’ve executed the command.
In order to shut the system down immediately, use the following command.
sudo shutdown now
Also read: How to use SCP command to transfer files in Linux?
How to broadcast a custom message during shutdown?
If you’re looking to broadcast a message to all users before shutting the system down, use the aforementioned message flag followed by the time.
sudo shutdown +5 "System shutdown"
The above command will shut the machine down five minutes after executing itself and will broadcast a custom message to all users. Note that if you’re using a custom message, using the time flag is a requirement.
Also read: How to rename a file in Linux?
How to reboot the system using Shutdown command?
To reboot the system using the shutdown command, we’re going to have to use the -r flag.
sudo shutdown -r
You can schedule a time and message as well.
sudo shutdown -r +5 "System shutdown"
Also read: How to check the list of users in Linux?
How to cancel a scheduled shutdown?
In order to cancel an already scheduled shutdown, you’re going to have to use the -c flag.
sudo shutdown -c
You cannot specify a time argument when using the -c flag but there’s an option for mentioning a custom message.
sudo shutdown -c "Shutdown cancelled"
Also read: How to change password in Linux?