codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐧

Linux & Bash

29 / 60 topics
29Cron Jobs30System Monitoring31Log Management
Tutorials/Linux & Bash/Cron Jobs
🐧Linux & Bash

Cron Jobs

Updated 2026-04-20
3 min read
import CodeBlock from '@/components/mdx/CodeBlock'
import Tip from '@/components/mdx/Tip'
import Terminal from '@/components/mdx/Terminal'
import OutputBlock from '@/components/mdx/OutputBlock'

export const meta = { title: 'Cron Jobs', description: 'Scheduling tasks using cron jobs.', lastUpdated: '2026-05-15', readTime: '10 min read', order: 29 }

# Cron Jobs

## Introduction

In the world of Linux and automation, **cron** is a powerful tool that allows you to schedule tasks (cron jobs) to run automatically at specified times or intervals. This can be incredibly useful for routine maintenance tasks, backups, sending emails, and more. Whether you're a beginner looking to automate simple tasks or an intermediate developer aiming to streamline complex workflows, understanding cron jobs is essential.

## Concept

Cron operates by reading a configuration file called the crontab (cron table). Each user on a Linux system can have their own crontab file, which specifies commands to be executed periodically. The syntax for a cron job is straightforward and consists of six fields:

1. **Minute** (0-59)
2. **Hour** (0-23)
3. **Day of the Month** (1-31)
4. **Month** (1-12 or Jan-Dec)
5. **Day of the Week** (0-7 or Sun-Sat, where both 0 and 7 represent Sunday)
6. **Command to be executed**

These fields are separated by spaces or tabs. For example, a cron job set to run at 3:15 PM every day would look like this:

15 15 * * * command_to_be_executed


## Examples

### Basic Syntax

Let's start with some basic examples to illustrate how cron jobs work.

#### Example 1: Run a Command Every Minute

To run a command every minute, you can use the following cron job:

<CodeBlock language="bash">
{`* * * * * /path/to/command`}

This means "at every minute of every hour, every day of every month, and every day of the week."

#### Example 2: Run a Command at a Specific Time

To run a command at 10:30 AM every day, you can use:

{`30 10 * * * /path/to/command`}
</CodeBlock>

This means "at minute 30 of hour 10, every day of every month, and every day of the week."

#### Example 3: Run a Command on Specific Days

To run a command at 2 AM every Monday, you can use:

<CodeBlock language="bash">
{`0 2 * * 1 /path/to/command`}

This means "at minute 0 of hour 2, every day of every month, and only on Mondays."

### Special Characters

Cron also supports special characters that allow for more complex scheduling:

- **Asterisk (`*`)**: Matches any value in a field.
- **Comma (`,`)**: Used to separate values within a field.
- **Dash (`-`)**: Specifies a range of values.
- **Slash (`/`)**: Steps, or increments, can be used to specify every Nth value.

#### Example 4: Run a Command Every Hour

To run a command every hour at the 15th minute:

{`15 * * * * /path/to/command`}
</CodeBlock>

This means "at minute 15 of every hour, every day of every month, and every day of the week."

#### Example 5: Run a Command Every Monday and Wednesday

To run a command at 8 AM on Mondays and Wednesdays:

<CodeBlock language="bash">
{`0 8 * * 1,3 /path/to/command`}

This means "at minute 0 of hour 8, every day of every month, and only on Mondays (1) and Wednesdays (3)."

### Editing the Crontab

To add or edit cron jobs, you need to access your crontab file. You can do this using the `crontab -e` command:

<Terminal>{`$ crontab -e`}</Terminal>

This will open the crontab file in your default text editor. You can add new cron jobs by appending lines with the desired schedule and command.

#### Example 6: Adding a Cron Job

Let's say you want to run a backup script every day at midnight:

1. Open the crontab file:
   <Terminal>{`$ crontab -e`}</Terminal>

2. Add the following line:
{`0 0 * * * /path/to/backup_script.sh`}
</CodeBlock>

3. Save and exit the editor.

### Viewing Cron Jobs

To view your current cron jobs, use the `crontab -l` command:

<Terminal>
{`$ crontab -l`}

This will list all the cron jobs that are scheduled for your user account.

<OutputBlock>{`
0 0 * * * /path/to/backup_script.sh
15 * * * * /path/to/command
30 10 * * * /path/to/command
0 2 * * 1 /path/to/command
`}</OutputBlock>

### Removing Cron Jobs

To remove a specific cron job, you can edit the crontab file and delete the line corresponding to that job. Alternatively, you can use the `crontab -r` command to remove all cron jobs for your user:

{`$ crontab -r`}
</Terminal>

**Caution:** This will permanently delete all of your scheduled cron jobs.

## What's Next?

Now that you have a solid understanding of how to schedule tasks using cron jobs, the next step is to explore system monitoring. Monitoring tools can help you keep track of system performance and ensure that your scheduled tasks are running as expected. Look out for our upcoming tutorial on "System Monitoring" to learn more!

By mastering cron jobs and system monitoring, you'll be well-equipped to automate and manage your Linux systems efficiently. Happy coding!

PreviousDebugging ScriptsNext System Monitoring

Recommended Gear

Debugging ScriptsSystem Monitoring