Shutdown and Restart Your Computer From The Ubuntu Terminal

With the addition of modifiers a complete set of commands

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 typesudo haltinto the Terminal.

If you would like to ensure that your system halts or poweroffs by default, the following commands do just that.

or

In either instance, the time at the end is necessary.  Typing eithersudo shutdown -Porsudo shutdown -Hwithout 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, thensudo shutdown +30would be the command.

If you want to shutdown your computer at 5:30 PM (as an example), thensudo shutdown 17:30would 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, sosudo shutdown 5:30would 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, typingsudo shutdown -cin 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, typingsudo shutdown -risn’t necessarily intuitive, so thankfully we can simply typesudo rebootinto 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.

Typingsudo pm-suspendwill suspend your computer.

Similarly,sudo pm-hibernateis 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.

Founder of Help Desk Geek and managing editor. He began blogging in 2007 and quit his job in 2010 to blog full-time. He has over 15 years of industry experience in IT and holds several technical certifications.Read Aseem’s Full Bio

Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.

HomeAbout UsEditorial StandardsContact UsTerms of Use

Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved