HowTo: Shutdown Linux System

I‘m a new Linux user. How do I shutdown Linux based system using command line options?

The recommend and secure way to shutdown Linux desktops, Laptops, routers, and server is to use the shutdown command. Another option is to use halt or poweroff command. The syntax is as follows for the shutdown command:
Tutorial details
DifficultyEasy (rss)
Root privilegesYes
Requirementsshutdown
TimeLess than a minute
shutdown -h time "message"

ADVERTISEMENTS

Where,

  • -h : Poweroff the system.
  • time : When to shutdown. You can poweroff immediately or after 2 minutes. It can be an absolute time in the format hh:mm, in which hh is the hour (1 or 2 digits) and mm is the minute of the hour (in wo digits). Second, it can be in the format +m, in which m is the number of minutes to wait. The word now is an alias for +0.
  • message: Send warning message to send to all users.

Steps to shutdown the system

First, open a command-line terminal (select Applications > Accessories > Terminal). For remote system, login using ssh. Next, switch to the root user by typing su - or sudo -s and entering the root password, when prompted. Finally, type the following command to shutdown system immediate as root user:
# shutdown -h now
OR
# shutdown -h +0

Task: Shutdown with warning message

To shutdown system in 10 minutes with the following warning message:
# shutdown -h +10 "Development server is going down for maintenance. Please save your work ASAP."
Sample outputs:

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!

Say hi to poweroff command

You can halt the system, switch off the power. This is called as poweroff and poweroff command can be used as follows (warning: the following command will immediately shutodown the Linux system):
# poweroff

Task: See log of system shutdown

The last reboot or last shutdown command will show a log of all reboots and shutdown since the log file was created under Linux:
# last reboot
OR
# last shutdown
# last -x shutdown

Sample outputs:

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
See also
  • See man pages – last(1)
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
7 comments… add one
  • khan Aqib May 7, 2012 @ 4:09

    hi my name is khan aqib

    i’m a student of cs193p.

    how to unlock root account…

  • manoj Jun 8, 2012 @ 7:21

    from single user mode

    use passwd commad for assigning root password

  • Mike Jan 29, 2013 @ 7:22

    Can you guys add how to restart a Ubuntu computer after a fixed duration with command line ?

  • matt jones Jul 16, 2013 @ 15:28

    You need to be root to shut down, I think a simple example is best. Shut down in 30 mins is;

    sudo shutdown -h +30

  • Dejan Dec 26, 2014 @ 16:42

    Hi,

    -h parameter does not shutdown the machine completely. It goes into halt mode. That means that the machine is still powered on. “shutdown now” shuts the machine off for good.

    • food4thoughts Feb 11, 2015 @ 2:54

      well depends if the host is a VM, then you need to do a shutdown -h now. That will shutdown the Linux VM host. If you do a shutdown now, it will only place your to user single mode but your vm will still up.

  • vignesh Jan 7, 2016 @ 11:35

    Hi,
    How to shutdown a linux server immediately when a user login . Is there any possibility to configure for this ?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.