To shut down a Linux system at a specified time of the day, you can use the shutdown
Linux command followed by the -h
flag (the -h
flag refers to halting the system at a specified time of the day) followed by the time to halt in 24-hour format.
TL;DR
# shutdown the system at 13:00 (1 pm) time
sudo shutdown -h 13:00
For example, let's say we have to shut down or stop the system at 1 pm the afternoon. To do we can use the shutdown
Linux command followed by the -h
flag (halt flag) followed by the time to stop the system in 24-hour format. In our case, we can write 13:00
since it is the 24-hour format of 1 pm
.
NOTE: To convert 12 hr format time to 24-hour format, add 12
to the 12-hour format time. Eg: 1 pm is 1 + 12 = 13
in 24-hour format.
The command looks like this,
# shutdown the system at 13:00 (1 pm) time
shutdown -h 13:00
If you are not a super user of the system, you cannot execute the above command.
To execute the above command as a super user, you can add the sudo
command before the shutdown
command like this
# shutdown the system at 13:00 (1 pm) time
sudo shutdown -h 13:00
After executing the above command, you will see an output similar to below,
As you can see from the above screenshot that we have successfully scheduled the shut down time for the system.
Show a message to the user while shutting down the system
To show a message to the user while shutting down the system you can add the message to the end of the shutdown
command inside the double quotes symbol (""
).
For example, if we want to show a message to the user like The system will shut down at 13:00 time
.
We can do it like this,
# shutdown the system at 13:00 (1 pm) time with a custom message
sudo shutdown -h 13:00 "The system will shut down at 13:00 time"
Stop all scheduled shutdown processes
To stop all the scheduled shutdown processes, you can use the killall
Linux command followed by the shutdown
command like this,
# Stop all the scheduled shutdown processes
sudo killall shutdown
Stop a specific scheduled shutdown process
To stop only a specific scheduled shutdown process, you can use the kill
Linux command followed by the -9
flag and the process id or the PID
of the shutdown
process which you have scheduled.
If the PID
of the shutdown process is 978
, the command will look like this,
# Stop a specific scheduled shutdown process
sudo kill -9 978
That's all 😃.