Occasionally you need to shut down or reboot your Linux servers. The Linux operating system comes with the built-in shutdown
command. This command allows you to power off or reboot a computer.
This tutorial shows you how to shut down or reboot a Linux machine.
Ubuntu/Debian Series Overview
- Fix “sudo command not found”
- Install a Specific Version with apt-get on Ubuntu/Debian
- Fix Ubuntu/Debian apt-get “KEYEXPIRED: The following signatures were invalid”
- How to Test a Cron Job
- How to Unzip Into a Folder
- How to Show Your Elasticsearch Version on Ubuntu/Debian
- Use “which” in Linux to find the Location of an Exetable
- Sort “ls” by Last Changed Date
- How to Shutdown a Machine
Shutdown Your Ubuntu/Debian Server
At first: you either need to be the root user or your logged-in user needs root privileges (sudo) to run the shutdown
command.
You may power off a Linux server using the shutdown
command. By default, this schedules the shut down of your machine in one minute:
# This shuts the computer down in 1 minute
sudo shutdown
Shutdown Immediately
You may shut down a Linux machine immediately using the -h now
flag. The -h
flag needs to stop the system at a specific time and now
tells Linux to shut down the machine immediately:
# This shuts down the computer immediately
sudo shutdown -h now
Shutdown in X Minutes
In situations where you want to shut down the computer at a later point in time, you can use the -h +<number>
format. This tells Linux to shut down the computer in <number>
minutes.
# This shuts down the computer in 2 minutes
sudo shutdown -h +2
Shutdown in X Seconds
The shutdown
command doesn’t support the granularity of shutting the machine down in X seconds.
Reboot Your Ubuntu/Debian Server
The shutdown
command also allows you to reboot a server using the -r
flag. Using -r
to reboot supports the same time arguments as a shutdown. For example, you may reboot a system immediately like this:
# This reboots the computer immediately
sudo shutdown -r now
You can also schedule to reboot the machine in three minutes:
# This reboots the computer in 3 minutes
sudo shutdown -r +3
Enjoy rebooting and shutting your computer down!