How to Shutdown Linux Using Command Line and GUI

For a fairly new Linux user, things can be a bit overwhelming in the beginning. While the robustness and unlimited customizability options are attractive, performing basic tasks can be daunting, especially if you are unaware of the proper commands to use. For instance, you need to shut down your system, but as a new user, you are struggling to figure out the right commands to turn off your Linux computer. Though shutting down may seem like an easy task, if done incorrectly, can result in loss of data or worse – could end up corrupting your system. So, if you are a novice Linux user looking to avoid any mishaps, follow this guide to learn the safest methods to shutdown a Linux system, both through the command line and the graphical user interface (GUI).

How to Shutdown Linux Using Command Line

The command line method to turn off a Linux system is preferred by seasoned users as it is fast and provides more options to play around with. This method is especially useful for shutting down Linux servers. Also, this is the most secure way as all the users currently logged in can be notified of the shutdown process so that they can save their work. There are multiple Linux commands you can use to shut down the system.

Use Shutdown Command to Turn Off Linux

The shutdown command is the most common one you can use to power off your Linux system safely. It offers a lot of flexibility since you can use the shutdown command to turn off, halt, or even reboot your PC. When you execute the shutdown command, all the current users are notified of the shutdown process. The basic syntax for shutdown command in Linux is:

sudo shutdown <options> <scheduled_time> <message>

In the above shutdown command syntax, you need to know the following things:

<scheduled_time> is used to specify the time at which the system will shutdown

<message> is used to specify the broadcast message each user will receive on their Linux shell before shutdown

<options> contains various options you can pair with the shutdown command including:

OptionDescription
-HWrites the final changes to data and then stops the processor from further processing tasks, but the system still stays on with minimal power consumption
-PWorks the same as -H, except it cuts off the power to the system
-rWrites the final changes to the disk and then reboots the system
-kUsed to send a warning message for shutdown
-cCancels the pending shutdown

If you use the shutdown command with no parameters, the system will shutdown after one minute.

Shutdown the System at Specific a Time

As you saw above, with the <time> parameter you can set the time interval after which you want the system to shutdown. You can either use the absolute time in 24-hour format or use the relative time “+m” where m is the number of minutes from the current time. By default, the <time> parameter is set to 1 minute. The syntax to shutdown the system at a specific time is:

sudo shutdown <time>

For example, if the current system time is 15:30 and you want to shutdown the system in the next 10 minutes, then the command in the absolute time will be:

sudo shutdown 15:40

and in relative time the command will be:

sudo shutdown +10

Shutdown the System Immediately

If you want to shutdown the system immediately, you can either use the ‘+0‘ for the <time> parameter or its alias ‘now‘. It is very dangerous to shutdown immediately in a muti-user Linux system as it can result in loss of unsaved data or worse, completely corrupt the system. The syntax to shutdown immediately is:

sudo shutdown +0

The alternate syntax to shutdown the system immediately is:

sudo shutdown now

Shutdown the System With a Shutdown Message

Say you need to shutdown a Linux server for maintenance, but there may be users who are currently logged into the system who might lose their unsaved work if the server is shutdown without any prior notification. With the shutdown command, you can schedule a system shutdown and inform the users of the scheduled downtime so that they can save their work. To shutdown the system with a broadcast message, use this syntax:

sudo shutdown <time> "<message>"

For example in the above scenario, you can use the command as follows:

sudo shutdown 16:30 "System shutdown scheduled at 16:30. Please do save your work. Thank You."

Once you execute the above command, all the currently logged-in users will see this broadcast message on their wall:

Broadcast message from root@localtarget on pts/1 (Tue 2023-03-21 06:35:46 UTC):

System shutdown scheduled at 16:30. Please do save your work. Thank You.
The system is going down for poweroff at Tue 2023-03-21 06:45:46 UTC!

Shutdown Linux System Using Halt Command

There is a common misconception among many Linux users is that both halt and shutdown processes are the same as they both seem to result in the same output. However, the halt command is generally used to send the system to the halt condition, where any further data processing by the CPU is stopped while keeping the system power intact. The shutdown command in Linux, on the other hand, stops the CPU processing along with cutting off the system power. To shutdown your Linux system with halt in the command line, use the syntax below:

sudo halt -p

Turn Off Linux System Using Poweroff Command

Both the poweroff command and the shutdown command sound very similar, but they have their differences. The poweroff command has a more “aggressive” approach and directly cuts off the power of the system immediately. If used unintentionally, the command can lead to the loss of user data. Whereas, the shutdown command has a more graceful approach, where it first writes the saved work on the disk, stops various CPU processes, and finally cuts off the power to the system. To power down the system with the poweroff command, use this syntax:

sudo poweroff

Shutdown Linux PC Using the init Command

The init command is used to modify the runlevels or the operating state of a process. In Linux and other Unix-like operating systems, “runlevels” are pre-defined states of the system that determine which system services are running. Each runlevel has a specific set of services and daemons that are started or stopped, and the runlevels can be modified to change the state of the system. There are 6 different types of runlevels that can be designated for different situations:

RunlevelDescription
0Shuts down the system via normal procedure.
1set single user-mode
2set multi-user mode without networking
3set multi-user mode with networking
4used by the user for their specific needs
5used to set multi-user mode with networking and GUI
6used to reboot the system

With the init command, you can shutdown a Linux system using the following syntax:

sudo init 0

When you select the runlevel 0, the init command takes the more graceful approach of the shutdown command of first writing the changes made to the disk, stopping the CPU processing, and then finally cutting off the system power.

How to Shutdown Linux Using GUI Method

The GUI method to shutdown a system can only work on Linux desktop installations. This method is more common among beginners and probably the easiest of all to work with. Here we have covered how to shutdown Gnome, KDE, and Mate-based Linux systems. But, be assured, you need to follow similar steps on most other Linux Distributions.

Turn Off Gnome-Based System

1. First, head over to the top right-hand corner and click there.

2. From the drop-down menu, click on the ⏻ Power Off/Logout option. Then, select the “Power Off…” option.

3. It will open a new dialogue box. Now click on the Power Off button to finally shutdown your system. At this stage, if you do not select any option, the system will automatically shutdown in the next 60 seconds.

Shut Down KDE-Based System

1. Open the applications tray from the bottom or press the “Super key” on the keyboard. On most keyboards, the super key is labeled as the “Windows Icon”.

2. Select the “ Quit” option at the bottom of the tray.

3. This will option a new dialogue box with the buttons named Suspend, Restart, and Shutdown. Click on the Shutdown button to finally shutdown the Linux system. If you do not select any option, the system will automatically shutdown in the next 60 seconds.

Shut Down Mate-Based System

1. Head over to the “System” menu in the top bar and select the “Shut Down” option from the drop-down menu.

2. Alternatively, click on the “⁝⁝⁝ Menu” button at the bottom or press the “Super key” on the keyboard. On most keyboards, the super key is labeled as the “Windows Icon”. Click on the ⏻ icon at the bottom.

3. This will open a new dialogue box with the buttons named Suspend, Restart, and Shutdown. Click on the Shutdown button to finally shutdown your system.

Although the GUI method is very easy to use, it does not offer a ton of options to play with. It can only work on the Desktop Linux versions. In this article, we have shown some very easy methods for both command line and GUI users to shutdown their Linux systems. Personally, I feel the command line method works the best for all sorts of use cases and it is much faster than the GUI method. Meanwhile, check out our list of 50+ Essential Linux Commands to help you work more efficiently in the Linux command line. Do let us know in the comments if you faced any issues.

Comments 1
  • Zaheer M K says:

    Additionally, if you could include/add a second part to the article, how to enable shutdown (and maybe even startup) of a laptop by closing (or opening for startup) its lid, it could be a delight to new users.

Leave a Reply