System Administration Guide: Advanced Administration

How to Create or Edit a crontab File

  1. (Optional) Become superuser to create or edit a crontab file that belongs to root or another user.

  2. Create a new crontab file, or edit an existing one.


    $ crontab -e [username]

    Where username specifies the name of the user's account for which you want to create or edit a crontab file. To create or edit crontab files requires superuser privileges.


    Caution – Caution –

    If you accidentally type the crontab command with no option, press the interrupt character for your editor. This character allows you to quit without saving changes. If you instead saved changes and exited the file, the existing crontab file is overwritten with an empty file.


  3. Add command lines to the file.

    Follow the syntax described in Syntax of crontab File Entries. The crontab file will be placed in /var/spool/cron/crontabs.

  4. Verify your crontab file changes.


    # crontab -l [username]

Example—Creating or Editing a crontab File

The following example shows how to create a crontab file for another user.


# crontab -e jones

The following command entry added to a new crontab file automatically removes any log files from the user's home directory at 1:00 a.m. every Sunday morning. Because the command entry does not redirect output, redirect characters are added to the command line after *.log to make sure that the command executes properly.


# This command helps clean up user accounts.
1 0 * * 0 rm /home/jones/*.log > /dev/null 2>&1