Properly managing your Linux system's power state is a fundamental skill. While you can use a graphical interface, the command line provides powerful and flexible options for shutting down or restarting your machine. These processes are tied to the system's initialization system, such as init or systemd, which manages different operational states, including startup and shutdown.
Shutting Down the System
The primary command for managing power states is shutdown. To power off your Linux system immediately, you can use the shutdown command with the -h (halt) flag and the time argument now. Administrative privileges are required, so you'll need to use sudo.
sudo shutdown -h now
The -h flag instructs the system to halt after shutting down services. On most modern hardware, this will fully power off the machine. You can also schedule a shutdown for a future time. To power off the system in a specific number of minutes, use the +m format:
sudo shutdown -h +2
This command will shut down your system in two minutes, which is useful for giving other users a warning or allowing background processes to finish gracefully.
Restarting the System
To restart your Linux system, you can use the shutdown command with the -r (reboot) flag.
sudo shutdown -r now
A more direct and commonly used alternative is the reboot command, which achieves the same goal of safely restarting the system.
sudo reboot
Alternative Power Commands
For more direct control, you might also encounter the halt and poweroff commands. In many modern Linux distributions, these are essentially shortcuts that call the shutdown command. For example, running poweroff is often equivalent to running shutdown -h now.