Site icon Edumotivation

Linux Shutdown Command Examples (Complete Guide)

Linux Shutdown command Examples

Do you know How to shutdown your Linux Operating System securely?

It’s straightforward.

In this guide, you will learn How to Shutdown Linux OS securely using the shutdown command.

Before starting the topic, I would like to explain to you the different shutdown process.

Types of Shutdown

There are two types of shutdown:

When we forcefully shutdown an operating system, it is called a hard shutdown.

This is not a recommended shutdown process, but sometimes circumstances arise that force us to perform a Hard Shutdown such as When the system hangs, Power Failure and So on.

But as much as possible we should avoid this option as This type of shutdowns can cause problems such as Operating System corruption or Hardware malfunctions.

This is a recommended shutdown process.

Such practice causes the operating system to shutdown all services systematically. Gives information to users to save their data.

So there are many benefits of such type of shutdown.

Features of Linux Shutdown Command:

Now, first of all, let’s focus on some of the most important options that we can use with the shutdown.

OptionsExplanation
-H, --haltHalt the machine
-P --poweroffPower-off the machine
-r --rebootReboot the machine
-hEquivalent to --poweroff, overridden by --halt
-kDon't halt/power-off/reboot, just send warnings
--no-wallDon't send wall message before halt/power-off/reboot
-cCancel a pending shutdown

Syntax:

You must follow the syntax given below to use the shutdown command.

shutdown [OPTIONS...] [TIME] [WALL...]

1. How to Shutdown your System

The superuser (root) or the users listed in the sudoers file can run the shutdown command.

So you always have to run this command with sudo.

Note: sudoers file is located at /etc/sudoers

To Shutdown your system type the following command.

~$ sudo shutdown
[sudo] password for ubuntu: 
Shutdown scheduled for Fri 2020-06-19 03:52:23 PDT, use 'shutdown -c' to cancel.

Without any argument by default, this command starts the shutdown process after an interval of 1 minute from now.

2. Shutdown the System Immediately

To shutdown the system immediately you have to pass now argument to shutdown command.

~$ sudo shutdown now

Also, you can run the following command to get the same result.

Note:now” is an alias for “+0

~$ sudo shutdown +0

3. Shutdown the System at Specified Time

You can schedule to Shutdown the system at specified time. You must specify the time in HH:MM (Hour:Minute) format.

shutdown command executes the scheduled task in a 24-hour time format.

Alternatively, you can use the +m as a syntax to shutdown the system after specified minutes.

Where “m” stands for Minutes.

Now let’s take some examples:

Ex # 1: Shutdown the system after 5 Minutes from now.

~$ sudo shutdown +5

Ex # 2: Shutdown the system after 1 Hour from now.

~$ sudo shutdown +60

Ex # 3: Shutdown the System at 07:30 AM.

~$ sudo shutdown 07:30

Ex # 4: Shutdown the machine at 07:30 PM.

~$ sudo shutdown 19:30

4. Halt the machine

To Halt the Machine, pass the -H option to Linux shutdown command.

By default, this command will start the halt process after an interval of 1 minute from now.

~$ sudo shutdown -H
Shutdown scheduled for Sat 2020-06-20 05:24:15 PDT, use 'shutdown -c' to cancel.

It’s possible to Halt the system at specified time. Let’s take some examples:

Ex # 1: Halt the system after 5 Minutes from now.

~$ sudo shutdown -H +5
Shutdown scheduled for Sat 2020-06-20 05:29:06 PDT, use 'shutdown -c' to cancel.

Ex # 2: Halt the System at 10:00 PM.

~$ sudo shutdown -H 22:00
Shutdown scheduled for Sat 2020-06-20 22:00:00 PDT, use 'shutdown -c' to cancel.

You can also use the long option --halt.

~$ sudo shutdown --halt

5. Power-off the System

What is the difference between Halt and Power-Off/Shutdown?

Halt Instruction stops the operating system and CPU, but the system remains on.

Shutdown or Power-Off instructions also act as halts, and at the same time, It sends an ACPI command that completely disconnects the system from power.

ACPI stands for Advanced Configuration and Power Interface.

To Power-Off the system pass the -P option to shutdown.

By default, this command will start the Power-Off process after an interval of 1 minute from now.

Example:

~$ sudo shutdown -P
Shutdown scheduled for Sat 2020-06-20 05:21:39 PDT, use 'shutdown -c' to cancel.

It’s possible to Power-Off the system at specified time. Let’s take some examples:

Ex # 1: Power-Off the system after 7 Minutes from now.

~$ sudo shutdown -P +7
Shutdown scheduled for Sat 2020-06-20 05:28:12 PDT, use 'shutdown -c' to cancel.

Ex # 2: Power-Off the System at 09:00 PM.

~$ sudo shutdown -P 21:00
Shutdown scheduled for Sat 2020-06-20 21:00:00 PDT, use 'shutdown -c' to cancel.

You can also use the long option --poweroff.

~$ sudo shutdown --poweroff

We have another option in the shutdown command which will give us the same result as -P (Power-Off) and that option is -h unless --halt is specified.

~$ sudo shutdown -h
Shutdown scheduled for Sat 2020-06-20 07:11:05 PDT, use 'shutdown -c' to cancel.

But when you specify the --halt option with -h it will Halt the system.

~$ sudo shutdown -h --halt

6. Reboot the machine

To Reboot (Restart) the machine pass the -r option to shutdown Command.

By default, this command will start the Reboot process after an interval of 1 minute from now.

~$ shutdown -r
Shutdown scheduled for Sat 2020-06-20 05:17:36 PDT, use 'shutdown -c' to cancel.

It’s possible to Reboot the system at a specified time. Let’s take some examples:

Ex # 1: Reboot the system after 10 Minutes from now.

~$ sudo shutdown -r +10
Shutdown scheduled for Sat 2020-06-20 05:26:09 PDT, use 'shutdown -c' to cancel.

Ex # 2: Reboot the System at 11:00 PM.

~$ sudo shutdown -r 23:00
Shutdown scheduled for Sat 2020-06-20 23:00:00 PDT, use 'shutdown -c' to cancel.

You can also use the long option --reboot.

~$ sudo shutdown --reboot

7. Cancel a pending Shutdown

To cancel a pending Shutdown, pass the -c option to shutdown command.

~$ sudo shutdown -c

8. Send wall message before Halt/Power-Off/Reboot.

You can send a wall message to the users while Shutdown/Restarting the system.

The purpose behind sending messages is to communicate users the reason for the system Shutdown/Restart.

The following command will shutdown the system at 7:30 AM and will send the specified wall message to all users.

~$ sudo shutdown 07:30 "Patch Installation"

Note: Always type the message within Quotes.

To send wall message to users without Shutdown, Halt or Reboot the system use the -k option.

~$ sudo shutdown -k +1 "This is a test  Message"

If you don’t want to send wall message before Halt/Power-Off/Reboot, pass the --no-wall option to shutdown.

~$ shutdown --no-wall

Infographic

Refer to this Infographic for complete shutdown command options.

You can visit at following websites to get more information on shutdown command.

Conclusion

I hope you have learned something from this article and you may have found that shutdown is a very important command in Linux.

I have tried my best to include all the features of shutdown command in this guide.

Now I’d like to hear your thoughts.

Was this guide useful to you?

Or maybe you have some queries.

Have I not included any command in this guide?

Leave a comment below.

Exit mobile version