Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH

Bash crontab Command

Understanding Cron and Crontab

The cron system is a time-based job scheduler in Unix-like operating systems.

It automates the execution of tasks (known as cron jobs) at specified intervals.

While cron is the background service that runs these tasks, crontab is the command used to manage them.

There is no direct "cron" command; instead, you use crontab to set up and control cron jobs.


Using Crontab

The crontab command allows you to define scheduled tasks.

These tasks are specified in a crontab file, which is a simple text file containing a list of commands meant to be run at specified times.

Crontab Syntax

The basic syntax of the crontab command is:

crontab [options]

Options

  • -e: Edit the crontab file for the current user.
  • -l: List the crontab entries for the current user.
  • -r: Remove the crontab file for the current user.

Setting Up Cron Jobs

Cron jobs are defined using a specific syntax in the crontab file. Each line in the file represents a task and follows this format:

* * * * * command_to_execute
  • Minute: 0-59
  • Hour: 0-23
  • Day of Month: 1-31
  • Month: 1-12
  • Day of Week: 0-7 (0 and 7 are Sunday)

Each asterisk can be replaced with a specific value or range to schedule the command at specific times.

Example: Schedule a Task

To run a script every day at midnight, you would use:

0 0 * * * /path/to/script.sh

This entry will execute /path/to/script.sh every day at 00:00 (midnight).


Common Uses

Cron jobs are commonly used to:

  • Automate system maintenance tasks, like backups and updates.
  • Schedule scripts to run at specific times or intervals.
  • Perform regular monitoring and reporting tasks.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.