You can use the shutdown
command in Linux to shut down the system from the terminal. Here are a few examples of how to use the shutdown
command:
- To shut down the system immediately:
# shutdown now
This will immediately shut down the system, without giving any warning or giving any chance for running processes to save their state.
- To shut down the system after a specified time:
# shutdown +30
This will shut down the system in 30 minutes. You can specify any number of minutes you want.
- To reboot the system:
# shutdown -r now
This will immediately reboot the system.
Note that only root or a user with superuser privileges can execute the shutdown
command. To shut down or reboot the system as a regular user, you need to use the sudo
command, for example:
$ sudo shutdown now
It’s also a good practice to log out of the system or to send a message to all logged-in users before shutting down the system, so that they have time to save their work. You can use the wall
command to broadcast a message to all logged-in users:
# wall "The system is going down for maintenance in 5 minutes!"
After running the wall
command, you can then shut down the system using the shutdown
command.