How to boot, shut down, and suspend your system from the Linux command line (2024)

Image

How to boot, shut down, and suspend your system from the Linux command line (1)

Let's face it: The most fundamental thing we do with computers is turn them on and off. Everything else happens between those two particular events. And sometimes, restarting the system is a key component of troubleshooting or completing installation processes.

Typically, you need root privileges to shut down or reboot the system. Ensure your account is configured in /etc/sudoers for this authority. Remember, it's generally a bad idea to log on directly as root.

Boot the system

Starting the system is as simple as pressing the power button. What happens from there varies a bit depending on your hardware, but in general, the process looks like this:

  1. The firmware (BIOS or UEFI) finds the boot media.
  2. The boot loader starts, and the Master Boot Record (MBR) or GUID Partition Table (GPT) loads.
  3. The operating system selection menu appears.
  4. The boot loader stage 2 starts and loads the selected kernel.
  5. The kernel and drivers load and mount the root filesystem.
  6. systemd launches as PID 1.
  7. The default.target file loads.
  8. The user is prompted to authenticate.

The system launches to the default.target (providing either a command-line interface or graphical environment). Changing these targets is outside the scope of this article but is something I cover in How to switch between the CLI and GUI on a Linux server.

Shut down the system

WhenRed Hat Enterprise Linux(RHEL) adopted systemd with RHEL 7, what happened to the venerable Linuxshutdown command? It remains—but now it maps to systemd's shutdown functions.

The shutdown command features two options: --halt and --poweroff. The --halt option stops the operating system while the --poweroff option turns off the system.

[ Free download: Advanced Linux commands cheat sheet. ]

One of the main benefits of the shutdown command is the ability to define a shutdown delay to give users time to save their work and log off the system. Schedule a time that suits your needs by using the format hh:mm (24-hour time designations).

For example, to halt the system at 10pm, type:

$ sudo shutdown --halt 22:00

It's more likely that you'll want to halt the operating system a few minutes into the future. In that case, specify the number of minutes from now to begin the shutdown process.

For example, to halt the system after a five-minute delay, type:

$ sudo shutdown --halt +5

You can append a message to all users by entering it after the time specification, like this:

$ sudo shutdown --halt +5 “Attention. The system is going down in five minutes.”

Cancel a timed shutdown by using the -c option:

$ sudo shutdown -c

Skip to the bottom of list

Image

Download now

You can also use the systemctl command to shut down the system. For example, type systemctl halt or systemctl poweroff to achieve similar results to the shutdown command. The main disadvantage of using systemctl is losing the ability to schedule or cancel the shutdown process.

Reboot the system

When someone approaches you for help with their computer, I suspect one of your first responses is, "Did you reboot it?" Restarting a computer helps with various problems and may even be necessary to finalize some configurations. However, restarting is considered downtime on a server and should be avoided if possible. Try to use systemctl restart {service-name} to restart services rather than reboot the whole system.

However, sometimes a restart is inevitable. The option for restarting the system immediately with the shutdown command is -r, so it looks like this:

$ sudo shutdown -r now

You can still specify a delayed time using the hh:mm format explained above.

You can also use systemctl to reboot the device by typing:

$ sudo systemctl reboot

Again, the disadvantage with systemctl is the inability to delay the process.

Suspend the system

There are a couple of ways to place the system in a reduced or no-power mode. The first is suspend and the second is hibernate.

When you suspend the system:

  • Contents of memory are moved to the swap location.
  • The boot loader is configured to boot directly to the current kernel.
  • The system shuts down (no-power mode).
  • Upon power up, the system reloads itself from swap.

When you hibernate the system:

  • Applications are stopped.
  • System state is moved to RAM.
  • The system remains powered on in a low-power state.

You can also suspend and hibernate the system by using the systemctl command. The commands are exactly what you'd expect:

$ sudo systemctl suspend$ sudo systemctl hibernate$ sudo systemctl hybrid-sleep

The systemctl hybrid-sleep command both suspends and hibernates the system.

Use the GUI

Depending on the graphical user interface (GUI) environment you have installed, you can initiate a reboot or shutdown from a menu. Many people rely on a graphical desktop like GNOME, so this is certainly a viable option.

Image

How to boot, shut down, and suspend your system from the Linux command line (3)

[ Because sudo is something you don't configure often, it can be hard to remember its nuances. Download theLinux sudo cheat sheet. ]

Wrap up

The familiar shutdown command now maps to systemd and executes timed shutdowns and reboots. You can use systemctl if you wish, but being able to schedule the shutdown is helpful. In addition, systemctl also offers suspend and hibernateoptions. Try to avoid bringing down the system when possible, but sometimes it's necessary.

Topics: Certification Linux Linux administration

How to boot, shut down, and suspend your system from the Linux command line (2024)

FAQs

How do you shutdown a Linux system from the command line? ›

You can also use the systemctl command to shut down the system. For example, type systemctl halt or systemctl poweroff to achieve similar results to the shutdown command.

How do you restart a system through the command line on Linux? ›

The most straightforward way to reboot a Linux system from the command line is by using the sudo reboot command. This command will immediately restart your system. In this example, we use the sudo reboot command to initiate an immediate system reboot.

What is booting and shutdown process in Linux? ›

Startup and shutdown mechanisms on Linux platforms use descendants of a standard system startup and initialization mechanism known as SysVInit, or provide compatibility with it. SysVInit works by integrating run-level independent startup scripts into the startup and shutdown mechanism for any Linux run level.

How to immediately shut down the system using the command line? ›

Start by pressing the Windows + R keys to open the Run window. From there, type "cmd" in the box and then select the "OK" button. This will open the Command Prompt. Here, type shutdown /s .

What is the shutdown key for Linux? ›

Linux operating systems can easily be stopped, shut down, and restarted using the shutdown command and its various options. Linux shutdown commands are entered in the Linux terminal that is launched by using the keyboard shortcut [Ctrl] + [Alt] + [T].

How do I use shutdown command? ›

Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to gracefully shut down the device after one minute and press Enter: shutdown /s. Type the following command to shut down the device after a specific time and press Enter: shutdown /s /t TIME.

How to restart system by command? ›

Open Command Prompt as an administrator, then type shutdown /m \\[your computer's name] /s. Add a /f to the end of the command if you want to force all apps to quit on the remote computer. Use /c if you want to add a message (for example: /c "This computer will shut down momentarily. Please save all work.")

How to restart from command line? ›

Press the Windows key + "S" to open the search bar. Type in "cmd". Right-click the Command Prompt and click "Run as administrator". Type "shutdown /r" and press "Enter".

How do I start a stop and restart service in Linux? ›

To do this:
  1. Open a terminal window.
  2. Run the command sudo systemctl start httpd. In this command: sudo tells Linux you are running the command as the root user. systemctl manages systemd services. start tells the systemctl command to start the Apache service. ...
  3. Once you run the command you will get the following message:
Jun 22, 2023

What is boot command in Linux? ›

The boot commands are what the MBR calls to start the bootloader along with the appropriate files the boot loader needs to start Linux. The startup commands are what the bootloader uses to start things like the Linux kernel and essential kernel modules.

What is reboot command in Linux? ›

To reboot Linux using the command line: To reboot the Linux system from a terminal session, sign in or “su”/”sudo” to the “root” account. Then type “ sudo reboot ” to reboot the box.

What is the command to shutdown and restart the system? ›

To shutdown Windows, use the shutdown command with the /s key. To reboot your computer, use the /r parameter. After running it, Windows will be gracefully restarted. This command works in the same way as logoff.exe command.

How to shut down your system after 15 minutes using command? ›

Enter the command “shutdown -s -f -t (time)”. In the placeholder “(time)”, you can designate how much time (in seconds) should pass before your PC shuts down. For example, enter “shutdown -s -f -t 900” if you want your PC to shut down after fifteen minutes of inactivity.

How to shutdown in 1 hour command line? ›

Enter “shutdown -s -f -t (time)” in the Windows search bar in the taskbar. The placeholder “(time)” is used to indicate the amount of time before your PC should shut down. For example, “shutdown -s -f -t 3600” specifies that the PC will shut down after one hour of inactivity.

How to restart system in Ubuntu? ›

Use reboot button

The reboot button is, of course, the easiest and quickest method to reboot Ubuntu. The 'Power Off / log Out' option may be found by clicking on the top right corner of your Ubuntu-powered device. Click on this option and find the Power Off option at the end of the list.

How to restart computer from command line Ubuntu? ›

Restarting Ubuntu can also be done with the wonderful shutdown command in Linux. You just have to use the -r option to specify that it's a reboot request. By default, if you just use shutdown -r , it will reboot your system after one minute.

Top Articles
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 6333

Rating: 5 / 5 (60 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.