Linux logo

How to Shutdown Linux by Using Commands

In this tutorial, I am going to show you ways of shutting down the Linux system. First, three ways are given to shutdown using the command line and the last method is for GUI based system.

The commands that can be used to shut down the system are:

  • shutdown
  • halt
  • poweroff
  • reboot

The commands are useful especially once you must reboot a remote Linux server, even in which just shell access can be obtained without a GUI.

First way – Using Shutdown Command

The shutdown command brings down the system in a safe way. Each of the logged-in users is advised that the machine is going down, and login operations are obstructed. It’s possible to close down the system immediately, or after a predetermined delay.

Why utilize shutdown?

The shutdown command stops the machine in a safe way. All particular applications in your machine that are intended to take steps when shutting down will be informed and given sufficient time.

You also have choices on whether to close the machine immediately or after a time interval which permits you to schedule future events or notify your users about an approaching reboot/shutdown.

On Linux, such as all jobs, both the shutdown and restart operations may also be performed from the command line.

Servers frequently require a restart when updates are installed or you want to shutdown for additional maintenance tasks.

The commands are offered on any Linux system such as CentOS, Ubuntu, Debian, Fedora, or SUSE and don’t need the installation of some additional packages.

Syntax of using the shutdown commands

The general way of using the shutdown command:

$ shutdown [OPTIONS…] [TIME] [WALL…]

An example of simple shutdown command

It is the most basic and simple use. This will shutdown the system.

$ shutdown
How to shutdown and reboot the Linux system

Use the –r option to shutdown and reboot the system:

$ shutdown -r
How to schedule a shutdown

You may also specify the time to shutdown the system. In this way, an advanced notification can be given to the users. An example command is:

$ shutdown 19:00

This will shutdown the system at 7 PM.

Further Reading:  Ways to Exit Linux/Unix Vim
Using –h option to halt

To halt system using shutdown commands, you may use the –h option as shown in the command below:

$ shutdown -H
Explicitly shutdown and power off

Though this can be by default, it is still possible to use the -P option to explicitly specify which you need shutdown to power off the system.

$ shutdown -P
The way to cancel a pending shutdown?

As shown in the above section, you may schedule a shutdown by specifying the time. Once you have done that, you may also cancel that by using the –c option:

$ shutdown -c
Example of shutdown with a message

You may also schedule a shutdown with a descriptive message to the users. An example:

$ shutdown +45 "Upgrading hardware "

Bring the system down immediately

$ shutdown now

Bring the system down immediately, and reboot it

$ shutdown -r now
Utilizing reboot command to shutdown

The next command to shutdown/reboot the system is the reboot command.

An example of reboot command:

$ reboot

In order to power off, use the –p option:

$ reboot -p

 

Forcibly Reboot Linux machine

The next command will reboot the machine forcibly. This is like pressing the power button at the CPU. No shutdown occurs. The machine will reset immediately.

$ reboot -f
Utilize “poweroff” command to shutdown

This command can also be used to shutdown the system.

$ poweroff
How to Close Down Ubuntu

Ubuntu was originally a terminal-based operating platform, but over the years Linux gradually introduced the GUI in its own operating system. These days, GUI methods are the only method to fix many operating system issues.

Ubuntu, the same as the rest of the operating systems, provides a number of methods to close down, and those include such straightforward approaches as clicking a button along with giving instructions to the machine using a terminal.

Shutdown Ubuntu with System menu

If you’re using an Ubuntu Desktop, then it’s easy to shut down or power off the machine. Ubuntu’s system menu provides the choice of a power-off button at a drop-down menu, either in the upper right corner of the background. By clicking on the power button, a dialog box with 3 choices will appear.

  • Cancel
  • Restart
  • Power off

You’ll have the ability to decide in 60 seconds. After 60 seconds the system will shut down automatically.

Best Practices for Shutting Down Linux Using Commands:

  1. Choose the Right Command:
    • Shutdown: Ideal for a safe and controlled system shutdown, notifying users and allowing scheduled events.
    • Halt: Use for halting the system immediately without rebooting.
    • Poweroff: Explicitly powers off the system after shutdown.
    • Reboot: Initiates a system reboot.
  2. Graceful Shutdown with Shutdown Command:
    • Use shutdown for a graceful shutdown, ensuring applications respond appropriately.
    • Provide a time argument for scheduled shutdowns to notify users in advance.
    • Cancel a pending shutdown with shutdown -c.
  3. Rebooting the System:
    • Utilize the reboot command for a straightforward system reboot.
    • Power off the system after reboot with reboot -p.
    • Forcibly reboot with reboot -f when immediate action is required.
  4. Alternative Shutdown Command – Poweroff:
    • Consider using poweroff as an alternative to shutdown for system shutdown.
  5. Shutdown Ubuntu Desktop:
    • On Ubuntu Desktop, leverage the graphical user interface:
      • Access the system menu in the upper right corner.
      • Choose between Cancel, Restart, or Power Off options.
  6. Scheduled Shutdown with Message:
    • Schedule a shutdown with a message to inform users about the reason.
    • Example: shutdown +45 "Upgrading hardware"
  7. Immediate Shutdown:
    • Execute an immediate shutdown with shutdown now.
    • Reboot the system immediately with shutdown -r now.
  8. Forceful Reboot:
    • When a hard reset is needed, use reboot -f for a forced reboot.
  9. Know Your System:
    • Be aware of the specific commands supported by your Linux distribution.
    • Familiarize yourself with GUI-based shutdown options on desktop environments.
  10. Exercise Caution:
    • Ensure critical tasks are completed before initiating a shutdown.
    • Communicate scheduled shutdowns to users in advance.
    • Double-check commands to prevent accidental system actions.
Further Reading:  Create New Directory in Linux/Unix by mkdir

 

Troubleshooting and FAQs

  1. Shutdown Command Not Working:
    • Ensure you have sufficient privileges to execute shutdown commands.
    • Check for any active processes preventing a graceful shutdown.
  2. Delay in Shutdown:
    • If there’s a delay in the shutdown process, review the scheduled time and cancel any pending shutdowns using shutdown -c.
  3. Halt Option Not Responding:
    • When using the shutdown -H option to halt the system, ensure it is supported on your Linux distribution.
  4. Explicit Power Off with -P Option:
    • If the system doesn’t power off with the -P option, verify system compatibility or use alternative commands like poweroff.
  5. Cancel Pending Shutdown:
    • To cancel a scheduled shutdown, employ shutdown -c and confirm the cancellation.
  6. Message Not Displaying:
    • If a message isn’t displayed during a scheduled shutdown, double-check the syntax and ensure the message is enclosed in quotes.
  7. Immediate Shutdown and Reboot:
    • Execute shutdown now for an immediate shutdown and shutdown -r now for an immediate reboot.
  8. Reboot Command Not Recognized:
    • If the reboot command is not recognized, check system documentation for alternative reboot commands.
  9. Forced Reboot Not Recommended:
    • Be cautious when using reboot -f for a forced reboot, as it doesn’t allow for a graceful shutdown.
  10. GUI Shutdown on Ubuntu:
    • If the GUI shutdown is unresponsive, use the terminal commands for a more direct approach.
  11. Ubuntu System Menu Issues:
    • In case the system menu on Ubuntu doesn’t respond, try executing shutdown commands from the terminal.
  12. Inability to Power Off:
    • If the system fails to power off, check for background processes or hardware-related issues.
  13. Insufficient Privileges on Ubuntu:
    • Ensure your user account has the necessary privileges to execute shutdown commands on Ubuntu.
  14. Timeout Decision on Ubuntu:
    • When using the Ubuntu system menu, make a decision within 60 seconds; otherwise, the system will automatically shut down.
  15. Verify System Compatibility:
    • Confirm that the chosen shutdown command options are supported on your specific Linux distribution.
Further Reading:  Why We Use Top Command in Linux?

 

Conclusion:

In this comprehensive guide on shutting down a Linux system using commands, we explored various methods tailored for both the command line and GUI-based systems. The commands discussed, including shutdown, halt, poweroff, and reboot, offer versatile options for system administrators, particularly in remote server management scenarios where GUI access is unavailable.

The tutorial emphasized the significance of the shutdown command, ensuring a safe and informed system closure. The ability to schedule shutdowns, notify users, and handle immediate or delayed shutdowns provides flexibility and control over system management tasks.

We covered troubleshooting aspects to address common issues, such as command not working, delays, and explicit power-offs. Additionally, the guide delved into Ubuntu-specific shutdown methods, highlighting GUI-based approaches and the 60-second decision window.

By understanding and applying these shutdown commands, users gain the expertise to efficiently manage Linux systems, whether for routine maintenance or critical updates. The commands presented are universally applicable across Linux distributions, including CentOS, Ubuntu, Debian, Fedora, and SUSE, without requiring additional package installations.

In conclusion, mastering these shutdown commands empowers Linux users with essential skills for maintaining system integrity and ensuring a smooth shutdown experience.