What is the shell command and option to turn off a Linux computer immediately?

The shutdown command in Linux is used to shutdown the system in a safe way. You can shutdown the machine immediately, or schedule a shutdown using 24 hour format.It brings the system down in a secure way. When the shutdown is initiated, all logged-in users and processes are notified that the system is going down, and no further logins are allowed.
Only root user can execute shutdown command.

Syntax of shutdown Command

shutdown [OPTIONS] [TIME] [MESSAGE]
  • options – Shutdown options such as halt, power-off (the default option) or reboot the system.
  • time – The time argument specifies when to perform the shutdown process.
  • message – The message argument specifies a message which will be broadcast to all users.
  • Options
    -r : Requests that the system be rebooted after it has been brought down.
    -h : Requests that the system be either halted or powered off after it has been brought down, with the choice as to which left up to the system.
    -H : Requests that the system be halted after it has been brought down.
    -P : Requests that the system be powered off after it has been brought down.
    -c : Cancels a running shutdown. TIME is not specified with this option, the first argument is MESSAGE.
    -k : Only send out the warning messages and disable logins, do not actually bring the system down.

    How to use shutdown
    In it’s simplest form when used without any argument, shutdown will power off the machine.

    sudo shutdown

    How to shutdown the system at a specified time
    The time argument can have two different formats. It can be an absolute time in the format hh:mm and relative time in the format +m where m is the number of minutes from now.

    The following example will schedule a system shutdown at 05 A.M:

    sudo shutdown 05:00

    The following example will schedule a system shutdown in 20 minutes from now:

    sudo shutdown +20

    How to shutdown the system immediately
    To shutdown your system immediately you can use +0 or its alias now:

    sudo shutdown now

    How to broadcast a custom message
    The following command will shut down the system in 10 minutes from now and notify the users with message “System upgrade”:

    sudo shutdown +10 "System upgrade"

    It is important to mention that when specifying a custom wall message you must specify a time argument too.

    How to halt your system
    This can be achieved using the -H option.

    shutdown -H

    Halting means stopping all CPUs and powering off also makes sure the main power is disconnected.

    How to make shutdown power-off machine
    Although this is by default, you can still use the -P option to explicitly specify that you want shutdown to power off the system.

    shutdown -P

    How to reboot using shutdown
    For reboot, the option is -r.

    shutdown -r

    You can also specify a time argument and a custom message:

    shutdown -r +5 "Updating Your System"

    The command above will reboot the system after 5 minutes and broadcast Updating Your System”
    How to cancel a scheduled shutdown
    If you have scheduled a shutdown and you want to cancel it you can use the -c argument:

    sudo shutdown -c

    When canceling a scheduled shutdown, you cannot specify a time argument, but you can still broadcast a message that will be sent to all users.

    sudo shutdown -c "Canceling the reboot"

    Fatmawati Achmad Zaenuri/Shutterstock.com

    Feel like starting over? This tutorial will show you how to cleanly and safely reboot or shut down your Linux or macOS computer from the command line.

    We’re Going Down

    Sometimes you just have to go for the reboot or the total shutdown. If you’re working on a GUI-less server or you’re on an SSH session to a remote computer, the command line is your only option. Linux and Unix-like systems such as macOS provide several commands to shutdown or reboot your system right from the command line.

    The commands you can use are:

    • shutdown
    • reboot
    • halt
    • poweroff

    Looking through the man pages for these commands can be confusing. Depending on which command line options you choose, all of these commands can perform shutdowns, reboots, and system halts. In fact, the man pages for reboot, halt, and poweroff contain exactly the same information.

    What’s Behind This?

    The answer lies in the systemd bootstrap system which replaced the venerable System V init system. In the Linux world, Fedora started to use systemd in 2011. Since then it has been adopted by a great many distributions. Debian and Ubuntu swapped to systemd in 2015.

    On systemd-based distributions the shutdown, reboot,  halt, and poweroff commands are effectively shortcuts that point to the systemctl command. Retaining these commands provides a degree of compatibility with System V init-based distributions. It means shell scripts (and hard-core System V system administrators) don’t keel over if they are moved to a computer with a systemd distribution running on it.

    Using Shutdown

    Shutting down or rebooting a multi-user system means you have to plan ahead. You need to decide when you’re going to go for the shutdown or reboot, and warn the other system users the shutdown is coming, and when. If it is your own computer and you’re the only one who uses it, life is much simpler.

    To run any of these commands you have to be in the sudo group. That is, you must have superuser permissions and be able to use the sudo command. If the command you have issued is going to take effect immediately and will not affect other logged in users, you will not need to use sudo. If you try to use one of these commands and the command is refused, re-try with sudo .

    By default the shutdown command ensures that all processes are stopped cleanly, all filesystems are synced, and all CPU activity has ceased. This is the ‘halt’ state. It then sends a message to the hardware to cut off power. This, of course, is the shutdown or “poweroff” state.

    It is common to pass shutdown some parameters, such as a time string and a message that will be sent to the logged in users to warn them off the shutdown. Let’s schedule a shutdown for 15 minutes from now. Type shutdown , a space, +15, a space, and then the message to send to the users.

    shutdown +15 Shutting down in 15 minutes!

    The time string we used was +15 , representing 15 minutes from now. The + is optional. We could have typed 15.

    We get a response that confirms a shutdown is scheduled and when it will occur.  Logged in users will receive the message that we provided.

    To cancel a shutdown, use the -c (cancel) option.

    shutdown -c

    Although you don’t get any notification that your shutdown has been canceled, your logged in users do get notified.

    If you don’t provide a time string a shutdown will be scheduled for one minute from now. Note that you can’t provide a message to your logged in users if you don’t specify a time string.

    shutdown

    If you can’t even wait a minute, you can use now as the time string and the shutdown takes immediate effect. Using now is like using +0.

    The time string can be a set time, such as 23:00. It must follow the format of HH:MM and must be in the 24-hour clock. Five minutes before the system goes down new logins are prevented.

    We know the default action of shutdown makes the computer go down to the halt state and then into the powered off state. We can override this behavior by passing other command line options to it.

    • The -H (halt) option will take your computer down to the halt state but will not ask the hardware to power down.
    • The -P (poweroff) is the default action . The computer is brought down to the halt state and is then powered off.
    • The -r  (reboot) option will take your computer down to the halt state and then restart it.
    • The -h (halt and poweroff) option is the same as -P. If you use -h and -H together, the -H option takes priority.
    • The -c (cancel) option will cancel any scheduled shutdown, halt or reboot.

    Here’s an example where we have scheduled a reboot.

    shutdown -r 08:20 System rebooting at 08:20

    The reboot, halt and poweroff Commands

    These commands perform the action their name suggests. However, each of them will accept command line options to make any one of them perform a reboot, a halt, or a poweroff. But why confuse matters? These commands are best used at face value.

    If you want to reboot now, use reboot . If you want to poweroff now, use poweroff, and if you want halt the system now, use halt.

    reboot

    halt

    poweroff

    These commands take immediate effect. If any of these commands are refused, precede them with sudo. But be aware, a refusal is usually because there are other users logged into the system that you’re about to take offline.

    Which Command is Right For Me?

    In multi-user environments using shutdown to perform these actions gives you more control. The facility to schedule shutdowns and reboots, and to alert users with a broadcast message will be invaluable in these cases. For a single-user computer, reboot and poweroff will probably meet your needs.

    READ NEXT

    • › How to Solve the “Too Many Open Files” Error on Linux
    • › 37 Important Linux Commands You Should Know
    • › How to Install Arch Linux on a PC
    • › How to Move Your Linux home Directory to Another Drive
    • › How to Set the Default Gateway in Linux
    • › How to Use the nohup Command in Linux
    • › How to Turn Off an Ubuntu PC
    • › Should You Use a TV as a PC Monitor?

    Which command is used to shutdown the system immediately?

    CTRL-ALT-DEL begins the reboot/shutdown immediately, the user does not have to be logged in.

    Which command you run if you want to shutdown your system in Linux?

    Here are some additional Linux shutdown command options you should be familiar with: -poweroff, -P : like halt Powers off the system (also turns off unit) -reboot, -r : Reboot the system. -halt, -h : Halt the machine after terminating processes.

    What is Sudo shutdown?

    sudo shutdown -h now This will perform a system shutdown in a proper way. You can also specify a timer (in seconds), instead of the word "now", for example: shutdown -h -t 30. This will bring the computer down in 30 seconds. sudo halt is another way to shutdown.

    Which command shuts the system down and reboots immediately?

    shutdown -r says to reboot the system immediately after it shuts down.

    Toplist

    Neuester Beitrag

    Stichworte