In Linux, it is quite easy (as in most operating systems) to restart your computer, log out of your user account, or shut down the system completely. Often, you just have to press the power button on your computer or a button on the toolbar. On Ubuntu, you will see a window like this.
You will be able to immediately shut down your computer (after logging out), restart your computer, log out, etc.
All of this can also be done through the Terminal, which is especially convenient for those Ubuntu users who always open a Terminal session. This method also includes several options, especially for shutting down your system.
Shut down Ubuntu from Terminal
First, we’ll open a terminal.
Before we get to the commands, please note that many of our actions will immediately end your current session, so it is recommended that you save everything while you browse this tutorial so that if – by accident – you turn off your computer by mistake, you will not lose anything.
Nevertheless, let’s go.
The first thing we’ll talk about is shutting down your computer. We will do this using the shutdown command. In the simplest case, we can shutdown the computer by entering the following into Terminal:
sudo shutdown -h now
If you haven’t taken any action recently as an administrator, you will be prompted for a password. After you successfully enter it, your computer will immediately start shutdown procedure.
Using this command basically gives your computer the ability to either stop or shutdown, and then does so immediately. Stopping simply stops all running processes, making it safe to shut down the computer, and the poweroff command does both.
Note: if you want to stop, you can also type sudo halt in Terminal.
If you want to make sure your system shuts down or shuts down by default, the following commands do just that.
sudo shutdown -P HH: MM
sudo shutdown -H HH: MM
In any case, time at the end is necessary. If you enter sudo shutdown -P or sudo shutdown -H without a timeout, a message appears stating that time is needed.
What if you need a little more control? The shutdown command has many parameters. For example, if you want to shutdown your computer after 30 minutes, then use the command sudo shutdown +30.
If you want to shutdown your computer at 5:30 pm (for example), use the sudo shutdown command at 5:30 pm.
Note: all commands that require 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 time-bound examples and realize that you want to continue using your computer, typing sudo shutdown -c in another 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 at the end it adds a parameter that tells your system to reboot after a successful shutdown.
Of course, typing sudo shutdown -r isn’t necessarily intuitive, so luckily we can just type sudo reboot into Terminal to do the same.
Finally, on some systems, the standard logout screen has hibernation or suspend options. The suspend setting saves your current state, then “almost” turns off so you can quickly return to your current state. While suspended, your computer is still using power (which is important when using a laptop). Hibernation is similar to suspending, except that your current state is saved to disk and the computer is turned off. You will need to reboot the system, but you can return to your current state after restarting. To perform any of these actions from the command line, use the Power Manager command.
Typing sudo pm-suspend will suspend your computer.
Likewise, sudo pm-hibernate is the command that puts it into hibernation.
And it’s all. The basic shutdown and reboot commands can be very simple, but with the addition of the mentioned modifiers (in addition to the hibernation and suspend commands) you have a very complete set of commands for managing your session, all from a basic Terminal session.