How to Shut Down Ubuntu Using Terminal: A Comprehensive Guide

how to shut down ubuntu using terminal

Shutting down your Ubuntu system using the terminal is a straightforward and efficient method that every user should know. This guide will walk you through the necessary steps, explain various shutdown commands, and provide tips for a smooth shutdown process. Whether you’re a beginner or an experienced user, this article has something for you.

Why Use the Terminal to Shut Down Ubuntu?

While graphical interfaces offer user-friendly options for shutting down your system, the terminal provides a faster and more flexible approach. Using the terminal allows you to:

Execute shutdown commands remotely.

Automate shutdown procedures using scripts.

Troubleshoot issues when the graphical interface is unresponsive.

Basic Shutdown Command

Certainly! Here is the paraphrased version of the provided text:

Shutting Down a Linux System

To turn off a Linux system via the command line, follow these steps:

1. Open a terminal application on your Linux system.

2. Enter the command sudo shutdown -h now to initiate the shutdown process.

3. Wait for a moment while the Linux server powers down completely.

4. If your Linux distribution uses systemd, you can use this alternative command: sudo systemctl poweroff

Command Syntax for Shutting Down a Linux System

The general syntax is as follows:

sudo /sbin/shutdown -h time "message"

shutdown -h time "message"

Here’s what each part means:

-h: This option will power off the system.

time: Specifies when to shut down. You can choose to power off immediately or after a specific number of minutes. It can be an absolute time in the format hh:mm, where hh represents the hour (one or two digits) and mm represents the minute (two digits). Alternatively, it can be in the format +m, where m is the number of minutes to wait. The term now is equivalent to +0.

message: A warning message that will be sent to all users.

Steps to Shutdown a Linux Server System

Open a command-line terminal (navigate to Applications > Accessories > Terminal). For a remote system, log in using the ssh command.

Switch to the root user by typing su – or sudo -s and entering the root password when prompted.

To shut down the system immediately as the root user, type the following command:

shutdown -h now

Alternatively, you can use:

shutdown -h +0

You can also use the sudo command:

sudo shutdown -h now

To schedule a shutdown in 10 minutes, use:

sudo shutdown -h +10 &

To shut down at 3:00 PM (using 24-hour clock format), type:

sudo shutdown -h 15:00

For modern Linux distributions with systemd, you can use this command as well:

sudo systemctl poweroff

Shutting Down the Linux Box with a Warning Message

To shut down the system in 10 minutes with a warning message, use the following command:

shutdown -h +10 "Development server is going down for maintenance. Please save your work ASAP."

This is what all users will see on their terminal:

Broadcast message from root@wks01 (pts/0) (Sat Apr 21 02:26:30 2012):

Development server is going down for maintenance. Please save your work ASAP.

The system is going DOWN for system halt in 10 minutes!

Canceling a Pending Shutdown Command

If you need to cancel a scheduled shutdown, pass the -c option from another terminal session. For example:

sudo shutdown -c

Introduction to the Poweroff Command

You can halt the system and switch off the power using the poweroff command. This command will immediately shut down the Linux system, so use it with caution:

poweroff

Customizing the Poweroff Command

The /proc/sys/kernel/poweroff_cmd file in the Linux kernel allows users to override the default poweroff command. To view the current setting, use:

cat /proc/sys/kernel/poweroff_cmd

Expected output:

/sbin/reboot

This prints the default poweroff command path. Users can change this to another command or script. For example:

echo '/usr/local/sbin/poweroff.py' > /proc/sys/kernel/poweroff_cmd

cat /proc/sys/kernel/poweroff_cmd

You can then create a custom command or script at /usr/local/sbin/poweroff.py, such as syncing data or performing backups. This customization allows sysadmins to run specific scripts when the system powers off.

Viewing Linux System Shutdown Logs

To view logs of all reboots and shutdowns since the log file’s creation, use the following commands:

last reboot

or

last shutdown
last -x shutdown

Sample output:

shutdown system down 2.6.32-131.12.1. Sun Jan 1 05:03 - 05:05 (00:02) 
shutdown system down 2.6.32-131.12.1. Sun Aug 28 16:53 - 17:00 (00:06) 
shutdown system down 2.6.32-131.12.1. Sat Aug 27 17:21 - 17:23 (00:02) 
shutdown system down 2.6.32-131.0.15. Sat Aug 27 17:15 - 17:18 (00:02)
wtmp begins Sat Aug 27 17:08:12 2011

Summary

This guide explained how to use the shutdown command on Linux to shut down the server or desktop as needed. For more options provided by these sysadmin commands, use the manual pages:

man 8 shutdown
man 8 last
man 8 systemctl
shutdown --help