Linux was all command-line when it began. Commands are input into Terminal and this was primary means of communicating with the OS to get things done. But, slowly GUI came in and high focus is now applied on developing a user-friendly desktop. Well, that’s a good thing, but if you want to have some fun and get things done quickly, terminal is the way to go.
In the new series of ‘Terminal Tuts’ for beginners of Linux, I will introduce you to new commands which 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 basic 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 warning if any unsaved documents exists in the session and gives 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 straight forward and very hard to remember for beginners especially if never heard of the GNOME environment. How does just ‘logout’ command sound? That 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 just enter logout command to log off PC.
This is very simple and straight forward.
Note that his command doesn’t shutdown the PC immediately. Instead it ticks a timer and gives you one minute time to save all things. If you need immediate shutdown, use this command. Make sure to save all documents before running this command.
sudo shutdown -P now
Some 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 is two ways to restart your PC.
5. Suspend / Sleep