How to reboot, shutdown, log off PC from Terminal by command-line in Ubuntu and Linux Mint

Linux was all command-line when it began. Commands are input into Terminal, and this was the primary means of communicating with the OS to get things done. Eventually, the community desired to apply an easy-to-use user interface so that newbies to Linux won’t shy away from Linux.

That’s a good thing, but if you want to have some fun and get things done quickly, the terminal is the way to go.

In the new series of ‘Terminal Tuts’ for beginners of Linux, I will introduce you to new commands that will one day make you fall in love with commands!

Log off, Shutdown, and Restart PC Commands in Ubuntu, Linux Mint, and derivatives

Let’s start with a primary task such as how to log off, Shutdown, and Restart your PC from the Terminal by command-line way.


1. Log Off: 

Launch ‘Terminal’ and type following command:

gnome-session-quit

This command will show a warning if any unsaved documents exist in the session and give you a chance to save them.

Alternatively, you can also use ‘force logout’ parameter which kills all the running programs and even unsaved documents without warning. Therefore use it cautiously!

gnome-session-save --force-logout 

Tip! As you see, the logout command is not straightforward and very hard to remember for beginners especially for those who never heard of the GNOME environment. Maybe merely a ‘logout’ command. It would make a perfect sense, but it is not a standard command. You can add custom alias using gedit command. I will Launch ‘Terminal’ and type this command:

gedit ~/.bash_aliases
alias logout="gnome-session-quit"

What you did is assigned a new alias logout which Ubuntu reads as gnome-session-quit and initiates logout command. Now you need to enter logout command to log off PC.

logout

2. Shutdown

It is straightforward.

shutdown

Note that this command doesn’t shut down the PC immediately. Instead, it ticks a timer and gives you one little time to save all things. If you need an immediate shutdown, use this command. Make sure to keep all documents before running this command.

sudo shutdown -P now

Few more Shutdown options:

shutdown +t "your message"

This command line shuts down the PC after the specified time ‘t’ in minutes and shows the message in quotes along with the standard shutdown dialog. Here is an example of the command:

shutdown +30 "Leave to pickup friend!"

3. Restart

There are two ways to restart your PC. Using any one the following commands:

sudo reboot
sudo shutdown -r

In the shutdown command above, notice the –rswitch at the end. It indicates that you want the computer to restart. sudo implies run the command as an administrator.

You also ask your computer to reboot after the time you mentioned. For example, in order to tell your computer to reboot in 30 minutes, use the command:

sudo shutdown -r +30

Want to reboot your computer at a specified time? You can do that too. For example, the below command will make your system to reboot at 3:00 PM.

sudo shutdown -r 15:00

4. Hibernate

Hibernate doesn’t work well in Linux. Most of the computer’s hardware is not capable of Hibernation. You can enter the pm-hibernate command and check. But if you are trying this out the first time, I advise you to save all the documents and close everything except your current browser and the Terminal. Because, if the Hibernate was not successful, all the session’s unsaved data will be lost.

sudo pm-hibernate

OR

systemctl hibernate

After entering the above command, the system will turn off. Press the power button and turn on the system. After you log in, if you see all the session intact, it implies your system is capable of Hibernating.


5. Suspend / Sleep

If Hibernation was out of luck for you, the best option to use is Suspend or Sleep. During suspend most hardware are shutdown, and system state is saved in RAM instead of the hard disk in Hibernation mode. Therefore, the system still requires power in this state.

sudo pm-suspend

OR

systemctl suspend

In order to put the computer to sleep after a certain amount of time, use the command:

echo 'pm-suspend' | at now + 15 minutes

OR

echo 'systemctl suspend' | at now + 15 minutes
Kiran Kumar
Hi there! I'm Kiran Kumar, founder of FOSSLinux.com. I'm an avid Linux lover and enjoy hands-on with new promising distros. Currently, I'm using Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities, especially during Winter ;). When I'm not writing for FOSSLinux, I'm seen biking and hiking on scenic trails. I hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more and spread Linux love!. If you find a time, drop me an email or feedback from the 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!

4 COMMENTS

  1. Kali 2020.1 doesn’t shut down fully for me. Stays on “dragon” icon. I’ve tried multiple flash dries (I use USB boot). I cannot edit the grub files (“permission denied”) . Any suggestions?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,437FansLike
375FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

How to change Hostname on Ubuntu

Generally, a hostname is just an assigned name to a computer, laptop, or any other connected device to a network. You can say a hostname is a computer's nickname, and it is used to identify the machine over the network uniquely.

Manjaro vs. Ubuntu – which is better for you?

If you are a person associated with Computer technology and spend most of the time in the open-source arena, you must have heard or worked with some of the popular Linux distributions we have in the market. Some of the names that you will never miss are; Ubuntu, Arch Linux, Debian, and Mint.

9 Useful Tips Working with Operating System using Python

There are several situations when we want to work with the operating system using python. We may want to see the user details or want to do some tasks with the files and directories. If you are a system administrator, you will find it useful to work with Operating System as one can easily automate some repeating tasks of the Operating System using python.

System76 Lemur Pro Review

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.

Top 10 New Features in Linux Kernel 5.8

Linus Torvalds recently announced the release of Linux Kernel 5.8, and he seems delighted with it. He has pointed it out as the most significant release of all time. To developers, this new kernel comes with an addition of 800,000 new code lines and more than 14,000 changed files. To the average user, you might not see many eye-candy changes, as seen in the earlier releases.

How to install Flutter on Linux

Do you want to install Flutter and start creating awesome Android and iOS applications? Then you have come to the right place. Here is a comprehensive tutorial on how to install Flutter on Linux. If you are new to Flutter, don't worry, we got that covered too as we shall go in-depth understanding of Flutter and what it brings to the table.

MUST READ

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

10+ Best Python IDEs for Linux

Python programming language is applied in so many areas of computer technology, i.e., Scripting, GUI development, Website development, Artificial Intelligence (AI), Machine Learning, Data Science, Computer Networking, and Network Automation, and Cyber Security.

What is FOSS, and how does it differ from Freeware

The rise of the Linux operating system, in all its various distributions, over the past few decades has catapulted the popularity of Free or Open Source Software (FOSS). Let's guide you in understanding what is FOSS, how it differs from freeware and is Linux a FOSS.

7 Best Ways to Kill Unresponsive Programs in Linux

For dealing with a frozen app or desktop, you can't use the CTRL+ALT+DEL in Linux system. Instead, there are powerful alternatives that come in handy in frustrating situations. We pick the best methods available for you.

Ubuntu MATE 20.04 LTS Review: Refinement at its Best

Ubuntu MATE 20.04 LTS was released a week ago after two years of development. Official updates and security patches will be provided until April 2025. I have installed it on my test laptop for a spin and here are my observations based on almost a week usage.