When you are finished working on your personal laptop, you simply close the lid. However, when you are managing a physical Linux server in a data center or operating a virtual machine in the cloud, shutting the system down is a highly delicate procedure. You cannot simply reach over and rip the physical power cord out of the wall. If you cut the power instantly, the server will not have time to save data in its RAM, which will corrupt the file system and destroy any active databases (like MySQL or PostgreSQL) that are currently writing to the hard drive. You must instruct the Linux kernel to gracefully terminate all running daemons and flush its memory using the shutdown command.
The Immediate Shutdown
If you need to power off the machine right this second, you must use the sudo command to prove you have administrative privileges, followed by the shutdown command and the word “now.”
sudo shutdown now
The moment you press Enter, the terminal will disconnect. The Linux kernel will broadcast a warning signal (SIGTERM) to all running programs, asking them to save their data and close gracefully. After a few seconds, it will cut power to the motherboard.
Scheduling a Future Shutdown
If you are managing a server that multiple people are using, pulling the plug immediately is incredibly rude. The shutdown command allows you to schedule the power-off sequence, giving other users time to finish their work.
To shut down the server in exactly 15 minutes, type:
sudo shutdown +15
The terminal will broadcast a text message to all logged-in users, warning them that the system is going down in 15 minutes.
You can also specify an exact time on the 24-hour clock. For example, if you want the server to turn off at 10:00 PM tonight, you would type:
sudo shutdown 22:00
If you make a mistake and need to cancel a scheduled shutdown, simply type sudo shutdown -c, and the timer will be aborted.