Skip to content
Ubuntu Linux

Schedule Automatic Shutdown in Ubuntu with Cron

Richard
Written by
Richard
Updated 4 min read
How to Use Sticky Notes in Windows 11
How to Use Sticky Notes in Windows 11
Before you start
  • 3 steps
  • Needs administrator rights

Scheduling an automatic shutdown in Ubuntu 22.04 LTS turns off your computer on a set schedule using Cron. Cron is a built-in background tool that runs commands at set times. It stops your PC from running all night, so you save power without shutting it down by hand.

You can create a simple rule that shuts down your system every day at 11 PM with a few terminal steps. Once you save the rule, Cron runs it silently in the background. You don’t need to log in or keep a terminal open.

⚡ Quick Answer

Schedule an automatic shutdown in Ubuntu 22.04 LTS by running sudo crontab -e in a terminal and adding a line such as 30 18 * * * shutdown now, which shuts the computer down every day at 6:30 PM. Cron reads the five time fields (minute, hour, day, month, weekday) in 24-hour format, and the job runs even when no terminal is open.

Advertisement

How to automatically turn off Ubuntu Linux

Setting up an automatic shutdown in Ubuntu is easy when you combine Cron with a basic power command. The system turns off at the same time every day without you being there. The whole job comes down to three actions: open a terminal, edit your scheduled tasks, and add the shutdown command with the time you want.

⚠️WarningKeep in mind that the shutdown is immediate. Anything you haven’t saved when the scheduled time arrives is lost, so pick a time when you are normally done for the day.
Advertisement
📝Good to KnowIf you are new to Cron or to the shutdown command, read these two posts first. They explain the time format and the command options that the steps below rely on.

After reading those posts, you should know how Cron works and how to shut down Ubuntu Linux from the command line.

For example, say you want your Ubuntu computer to shut down every day at 6:30 PM. You will edit the crontab (the file where Cron keeps its list of scheduled jobs), add the shutdown command, and set the time. Cron uses a 24-hour clock, so 6:30 PM is hour 18, minute 30. Cron also reads the time from your system clock, so check that your time zone is correct.

First, open a terminal and run the command below to edit the crontab. Shutting down a machine needs administrator rights, so use the exact command shown in the code block. If you add the job to a crontab that lacks those rights, it will be saved but the shutdown will not happen.

🐧Bash / Shell
sudo crontab -e

When you run crontab -e for the first time, you may see a prompt asking you to choose an editor. Ubuntu only asks once. If you are not sure which to pick, choose nano. It is the simplest one and the steps below assume it. Type the number next to the editor and press Enter. The crontab file then opens in the terminal.

💻Code
no crontab for root - using an empty one
Select an editor.  To change later, run 'select-editor'.

  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.tiny
  3. /bin/ed

Choose 1-3 [1]: 1

Next, scroll to the bottom of the file with the arrow keys. Lines that start with # are comments, and Cron ignores them. Add the command shown below on a new line to shut down daily at 6:30 PM. A Cron line has five time fields in this order: minute, hour, day of the month, month, and day of the week. An asterisk in a field means “every”. The command comes after the five fields.

💻Code
30 18 * * * shutdown now
Editing crontab to schedule automatic shutdown in Ubuntu
crontab edit new line

To save the file and leave the editor, follow these steps:

  1. Press Ctrl+X to exit. Nano asks whether you want to save the changes.
  2. Press Y to confirm, then press Enter to keep the same file name.
  3. You are back at the terminal prompt, and the job is active. Cron picks up the change by itself, so you don’t need to restart anything.

To check your work or remove the job later, open the crontab again with the same edit command. Your line should still be there. Delete it, save the file the same way, and the automatic shutdown stops. Note that Cron only runs the job while the computer is on. It will not turn the machine back on.

If you want to restart Ubuntu Linux instead of shutting down, you’ll use -r in the command. The rest of the line, including the time fields, stays the same.

💻Code
shutdown -r now

Again, the post above about Cron shows how to specify different days, dates, times, and other variables in Cron. For example, you can limit the shutdown to weekdays or run it at a different hour on certain days. Change only the five time fields, and leave the command part alone.

That should do it! Your Ubuntu computer will now shut down on its own at the time you set.

Conclusion:

  • Regularly shutting down your Ubuntu Linux system using Cron can help save energy and reduce electricity costs.
  • Getting comfortable with the command line and understanding how Cron works is crucial for scheduling automated tasks. The five time fields are the part to learn first.
  • Be sure to refer to the recommended tutorials for detailed guidance on using Cron and managing shutdown and restart processes in Ubuntu Linux.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Tags: #Windows 11

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *