In Linux, it’s pretty simple (as it is in most operating systems), to restart your computer, logout of your user account, or completely shutdown your system. Often, it’s as simple as hitting the power button on your computer, or clicking a button on the toolbar. In Ubuntu, you’ll see a window like this appear.
You’ll have the option to immediately turn off your computer (after shutting down your session), rebooting, logging out, and more.
All of this can be done via the Terminal as well, which is especially handy for those Ubuntu users who always keep a Terminal session open. This method also includes a few options, especially for shutting down your system.
Shutdown Ubuntu from Terminal
First, we’ll open a Terminal.
Before we get to the commands, take note that many of the things we’ll do will immediately end your current session, so it’s a good idea to have everything saved while browsing this tutorial, so if – by chance – you mistakenly turn off your computer, you won’t lose anything.
That said, here we go.
The first thing we’ll talk about is shutting down your computer. We’ll do this using the shutdown command. At its most basic, we can shutdown our computer by typing the following into Terminal:
Unless you’ve recently performed an action as the administrator, you’ll be asked for your password. Once you successfully enter it, your computer will immediately start the shutdown procedure.
Using this command basically gives your computer the option to either halt or poweroff, then does that immediately. Halting simply stops all running processes, making it safe to turn off your computer, while the poweroff command does both.
Note: if you want to halt, you can also type sudo halt into the Terminal.
If you would like to ensure that your system halts or poweroffs by default, the following commands do just that.
In either instance, the time at the end is necessary. Typing either sudo shutdown -P or sudo shutdown -H without the time will bring up a message informing you that the time is necessary.
What if you want a bit more control? The shutdown command has many options. For instance, if you want to shutdown your computer in 30 minutes, then sudo shutdown +30 would be the command.
If you want to shutdown your computer at 5:30 PM (as an example), then sudo shutdown 17:30 would be the command to use.
Note: all commands which demand a time use 24-hour time, even if your clock is set to 12-hour time, so sudo shutdown 5:30 would be 5:30 AM.
Finally, if you’ve used one of these examples with a time attached, and realize you want to keep using your computer, typing sudo shutdown -c in a different Terminal session will cancel the scheduled shutdown.
If you want to restart your computer, you have two options. The first still uses the shutdown command, but adds an option at the end that tells your system to restart once the shutdown has completed successfully.
Of course, typing sudo shutdown -r isn’t necessarily intuitive, so thankfully we can simply type sudo reboot into the Terminal to accomplish the same thing.
Finally, some systems have hibernate or suspend options on their standard logout screen. The suspend option saves your current state, then “almost” shuts down so that you can quickly return to your current state. While suspended, your computer still uses power (important if running a laptop). Hibernate is the same as suspend, except your current state is saved to disk and the computer turned off. You’ll need to restart your system, but can return to your current state once restarted. To do either of these from the command line, a power manager command is used.
Typing sudo pm-suspend will suspend your computer.
Similarly, sudo pm-hibernate is the command to place it in hibernate mode.
And that’s it. The basic shutdown and reboot commands can be very basic, but with the addition of the modifiers mentioned (in addition to the hibernate and suspend commands), you have a very complete set of commands for session management, all from a basic Terminal session.