Sometimes for whatever reason we need to shut down or reboot our computer via terminal. For this, we have the shutdown command, which is simple to use and will help us with the task. So, in this post, you will learn how to use it with some practical examples.
The shutdown command in Linux
The shutdown command is a Unix system utility that allows us to shut down and restart a computer by using the terminal.
This command is used by many sysadmin in scripts where automatic reboots are required, or especially useful if in enterprise environments you want to shut down the computer remotely.
Another aspect of the shutdown command is that it is available for all existing Linux distributions. So, like many other commands, we don’t have to install or configure anything extra.
It is basic to explain but let’s take a look at it, so you can master it without any problems.
Using the shutdown command in Linux
The basic syntax of the shutdown command is as follows
shutdown [OPTIONS] [TIME] [WALL]
TIME
refers to the time we want to shut down the computer. This can be specified in several ways, and WALL
is a message that serves to notify the users that the computer will be shutdown.
To use this command, it is necessary to have root permissions. So, a regular system user will not be able to use it.
So let’s go for it.
Using the shutdown command to shut down the computer
If you use the shutdown
command just like this without any argument
shutdown
It will start a timer and the system will shut down in 1 minute.
This is sometimes not ideal, if you want the system to shut down immediately, then you can use now
.
shutdown now
This will immediately shut down the computer.
You can also define an exact time at which the computer will shut down. For example,
shutdown hh:mm
Following the 24-hour format, you can set a time.
shutdown 23:50
This way when it is 23:50 the shutdown command will shut down the computer.
Or you can also define how many minutes after the command is executed. For example,
shutdown +m
Replace m
with the minutes you want.
shutdown +30
I.e., the shutdown
command will shut down the system after 30 minutes.
You can also specify a message to warn other users. For example,
shutdown +30 "The system will shut down in 30 minutes. Please take precautions."
This will take the time and a warning message.
The shutdown command is also used to reboot the computer. This is done by adding the -r
option.
shutdown -r
As with the system shutdown, this command will not immediately restart the system but will set a 1-minute timer.
To restart the system immediately run
shutdown -r now
Or add a timer
shutdown -r +25
In this case, it will restart the computer in 25 minutes.
As soon as you execute these commands they will be stored in memory, therefore, to cancel them, you have to run
shutdown -c
This will cancel all executions of shutdown
.
Conclusion
This command is an easy-to-use command that allows us to quickly reboot or shutdown the system. As with many commands, this can be useful in scripting or remote work situations.
Help us grow and share this post.