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:
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!
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:
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.
It is straightforward.
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!"
There are two ways to restart your PC. Using any one the following commands:
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
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.
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.
In order to put the computer to sleep after a certain amount of time, use the command:
echo 'pm-suspend' | at now + 15 minutes
echo 'systemctl suspend' | at now + 15 minutes