How to Shutdown Linux? [Fixed “Shutdown Command Not Found”]

Shutting down a Linux System implies stopping or powering off the system in a controlled way. There are a few ways to turn off a Linux system such as using GUI interface, command line, or keyboard shortcuts. Following the correct shutdown procedures helps preserve data integrity, conserve power, reduce data loss, and prevent system instability.

In this article, I’ll discuss how to shut down a Linux system as well as the solution for the “bash: shutdown command not found” error.

What is the “shutdown” Command in Linux?

The shutdown command is a system utility that is used to safely shut down, reboot, or schedule a shutdown employing the 24-hour format of a Linux system. Generally, the users with administrative privileges (the root user or the users having sudo privileges) can execute the “shutdown” command. The basic syntax of the Bash “shutdown” command is:

shutdown [OPTIONS] [TIME] [MESSAGE]
EXPLANATION
  • [OPTIONS]: Specifies additional options like the following table:

Options

Function

-r (- -reboot) Reboots the system.
-H (- -halt) Halts the system.
-P (- -poweroff) Powers off the machine.
-h Halts (power off) the machine after shutdown.
-k Sends a message without performing shutdown, reboot or halt.
-c Cancels a pending shutdown.
  • [TIME]: Specifies various time formats of when to shut down the machine such as now (immediately), +M (after M minutes), hh:mm (at a specific time) etc.
  • [MESSAGE]: Specifies a custom message that will appear to users before shutdown.

Uses of the “shutdown” Command in Linux

The shutdown can be accomplished in different ways such as immediately, in a scheduled manner, with a custom message, and interactively. Also, the essential “shutdown” command offers various options for halting, rebooting the system, or canceling the pending shutdown.

In the following section, I’ll demonstrate every different aspect of shutting down a Linux machine:

1. Immediate Shutdown

To shutdown the Linux system immediately without any delay, run any of the following commands in the terminal:

shutdown -h now

Or,

shutdown now

Or,

shutdown +0

Or,

poweroff

Note: It is recommended to use sudo before the “shutdown” command. For example: sudo shutdown -h now or sudo shutdown +0.

2. Scheduled Shutdown

You can shut down your system after a specified delay or at a specific time by setting a scheduled time with the “shutdown” command.

A. Shutdown After a Specific Delay

To shutdown the system gracefully after M minutes, use shutdown +M syntax. For example, to shutdown after 10 minutes, use:

shutdown +10

Once you have run the command, you will see a line like the following image:Notifying that the shutdown will occur after 10minutes

The image states that the shutdown will occur after 10 minutes from the current running time.

B. Shutdown at a Specific Time

To shut down the machine at a specific time, use shutdown hh:mm syntax. For example, to shutdown at 6.00 PM, run:

shutdown 18:00

3. Rebooting System

To reboot a system immediately, execute the command below:

shutdown -r now
EXPLANATION
  • shutdown -r now: Here, -r is used to indicate reboot and now implies the current time.

To reboot after a delay, use shutdown -r +M syntax. For example, to reboot after 20 minutes, use:

shutdown -r +20

4. Halting System

Halting a system refers to stopping all CPUs and disconnecting the main power. To halt a Linux system, run the command below:

shutdown -H

5. Shutdown with a Custom Message

To initiate a system shutdown with a custom message, check out the following script:

shutdown -h +10 "System shutdown will occur"
EXPLANATION
  • shutdown -h +10 “System shutdown will occur”: Here, -h is used to halt the system and +10 indicates the time after 10 minutes.

6. Interactive Shutdown

An interactive shutdown script generally provides a user with additional information and choices before shutting down the system.

The following is an Bash script that will ask users to confirm before starting the system shutdown:

#!/bin/bash

read -p "Do you want to shut down your system? (y/n): " select

if [ "$select" = "y" ]; then
    shutdown +3
else
    echo "Abort shutdown"
fi
EXPLANATION

Here, read -p "Do you want to shut down your system? (y/n): " select prompts the user with a confirmation message, reads the inserted input, and stores it in the variable ‘select’. Then, if [ "$select" = "y" ]; then checks if the value stored in $select is equal to y. If the condition is true, then the script schedules a shutdown to occur after 3 minutes using shutdown +3. If the condition is false, the script displays the message ‘Abort shutdown’.

Interactive shutdown using the "shutdown" command

From the image, you can see that when I entered y (yes), the system was scheduled for a shutdown after 3 minutes from the current runtime and when I entered n (no), the system displayed a shutdown abortion message.

7. Cancelling a Pending Shutdown

To cancel any pending or scheduled shutdown, run the following command:

shutdown -c

How to Solve “bash: shutdown command not found” Error?

The “bash: shutdown command not found” error occurs if the “shutdown” command is missing from the base installation or is removed by mistake or intentionally. This error can also occur if the “shutdown” command is not in the PATH environment variable of the system. However, to solve the “bash: shutdown command not found” error, check out the following 2 methods:

1. Install Systemd

The “shutdown” command is usually installed on Ubuntu and most Linux distributions by default. However, if you encounter a situation when the “shutdown” command is not preinstalled, you can use a package manager according to your distribution to install it.

To install the “shutdown” command on a Ubuntu-based system, run the command below:

sudo apt install systemd

This command will install the systemd package which includes the “shutdown” command.

Note: For other Linux distributions, use the corresponding package manager that includes the “shutdown” command.

2. Set PATH Variable for the “shutdown” Command

If you have the “shutdown” command installed but still encounter the “bash: shutdown command not found” error, it means that the command doesn’t exist in any of the directories listed in your system’s PATH environment variable. To set the PATH variable for the “shutdown” command, follow the steps below:

  1. Open your Ubuntu terminal and execute the following command to check whether the “shutdown” command exists or not on the system.

    which shutdown

    Displaying the system PATH of the "shutdown" command

  2. Now, to modify the PATH variable, open the .bashrc file using the nano command and write the following command:

    nano ~/.bashrc
  3. Then, scroll down the file and include the correct path /usr/sbin/shutdown of the “shutdown” command at the bottom of the .bashrc file using the export command like the following:

    export PATH=$PATH:/usr/sbin/shutdown

    Setting PATH variable for the 'shutdown' command using the "export" command

  4. Click on CTRL+S to save the file and CTRL+X to exit.
  5. Afterward, to apply the changes write the following shorthand notation:
    . ~/.bashrc
  6. Finally, verify the PATH variable by running the echo command:
    echo $PATH

    Verifying PATH variable using the "echo" command

    The image states that the path has been added and you can use the “shutdown” command without facing the error now.

Conclusion

To conclude, shutting down a Linux system is a straightforward process utilized by the “shutdown” command. By understanding the proper use of this command, users can manage their system operations elevating data integrity and system stability. However, if you ever face the “bash: shutdown command not found” error, you must verify its installation or set its PATH variable to resolve it.

People Also Ask

How can I specify the timing for shutdown in Linux?

To specify the timing for shutdown in Linux, use the ‘shutdown’ command followed by a time argument. The time argument can be used in different formats to set the time for the shutdown in Linux to happen immediately or after a specified delay. For example, to shutdown a system after 5 minutes, use shutdown +5 or to shutdown a system at 9 PM, use shutdown 21:00.

Can I include a custom message with the shutdown command?

Yes, you can include a custom message with the ‘shutdown’ command using the syntax shutdown [OPTIONS] [TIME] [MESSAGE]. For example, shutdown -h +3 "Shutdown will occur". Users on the system will be notified with this custom message before the shutdown occurs.

Do I need special permissions to use the shutdown command?

Yes, you need to be a privileged user such as a root user or a user with sudo privileges to use the ‘shutdown’ command.

How can I cancel a pending shutdown?

To cancel a pending shutdown, use the ‘shutdown’ command with the option -c i.e. shutdown -c. This command will stop the countdown timer and cancel any scheduled shutdown.

How can I check if the shutdown command is in my system’s PATH?

To check if the shutdown command is in the PATH of your system, type the command echo $PATH in the command prompt. If you see a path like /sbin/shutdown or /usr/sbin/shutdown in the output, then the ‘shutdown’ command is on your system’s PATH.

How do I install the shutdown command if it’s not available?

If the ‘shutdown’ command is not available, use your system’s package manager to install it. The installation process may vary based on your Linux distribution. For instance, for a Ubuntu-based system, you can run the command sudo apt install systemd.

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Nadiba Rahman

Hello, This is Nadiba Rahman, currently working as a Linux Content Developer Executive at SOFTEKO. I have completed my graduation with a bachelor’s degree in Electronics & Telecommunication Engineering from Rajshahi University of Engineering & Technology (RUET).I am quite passionate about crafting. I really adore exploring and learning new things which always helps me to think transparently. And this curiosity led me to pursue knowledge about Linux. My goal is to portray Linux-based practical problems and share them with you. Read Full Bio

Leave a Comment