≡ Menu

How To Install, Edit, or Remove Cron Jobs in Batch Mode

Question:  How can I install all the schedule jobs from a text file to the crontab? Also, can I remove all the cron jobs at once instead of removing the individual lines from the crontab?

Answer: You can install, edit and remove crontab in batch mode as examples below. Also, refer to our 15 crontab examples.

1. Install Crontab in Batch Mode

By specifying the file name as an argument to crontab command, you can install the new cron jobs from a text file as shown below.

First create a text file with all your cron job entries.

$ cat cron-file.txt
* * * * * /bin/date >> /tmp/date-out
* * * * * /bin/ls >> /tmp/ls-out

Next, install the cron jobs from a text file as shown below.

$ crontab cron-file.txt

Note: This will overwrite the existing cron entries.

2. Edit crontab in Batch Mode

You can edit the crontab in batch mode using various methods (for example, using sed).

Example: Change output redirection from write to append for all cron jobs.

$ crontab -l
* * * * * /bin/date > /tmp/date-out
* * * * * /bin/ls > /tmp/ls-out

$ crontab -l | sed 's/>/>>/' | crontab -

$ crontab -l
* * * * * /bin/date >> /tmp/date-out
* * * * * /bin/ls >> /tmp/ls-out

3. Remove All cron jobs of the Current User

Crontab’s -r option removes all cron job for the current user. If you have appropriate privilege, you can even remove other user’s cron jobs using the -r option along with the -u user option.

Example: Remove the current user cron entries.

$ crontab -r

Example: Remove the specified user cron entries.

$ crontab -r -u USERNAME
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • coolhunk May 5, 2010, 11:13 am

    Really like your articles… Can you give a brief about XEN Virtualization.

  • Ajay April 15, 2013, 7:57 am

    Instead you can direct your existing cron jobs like

    crontab -l > cron.base

    Update cron.base file with your changes

    Once you are done with your changes again you can load them like

    crontab cron.base

    This way you will not loose your existing cron jobs.