Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I entered crontab -r instead of crontab -e and all my cron jobs have been removed.

What is the best way (or is there one) to recover those jobs?

share|improve this question
Is it just me or wouldn't it make more sense for crontab -r to ask yes/no by default?? – user1446688 Feb 16 '15 at 22:54
I think having a yes/no prompt would be a great idea. especially since e & r are right next to each other.. and crontab -e is a really common cron command. – JustinP May 11 '15 at 15:52
In 7 or so years of admin work I have never had this happen to me. Now I am scared. Time to start backing up the crontabs regularly. – Caja Jun 23 '15 at 13:35
This has happened to me twice already. It's the worst idea ever to have e for edit and r for remove with absolutely no prompt whatsoever!! – DaniG2k Sep 7 '15 at 14:17
First thing to do, alias crontab=crontab -i. But crontab should have made that default, given that e & r are next to each other... – anishsane Dec 8 '15 at 6:57
up vote 20 down vote accepted

crontab -r removes the only file containing the cron jobs.

So if you did not make a backup, your only recovery options are:

  • On RedHat/CentOS, if your jobs have been triggered before, you can find the cron log in /var/log/cron. The file will help you rewrite the jobs again.
  • Another option is to recover the file using a file recovery tool. This is less likely to be successful though, since the system partition is usually a busy one and corresponding sectors probably have already been overwritten.
share|improve this answer
I could not voted you up but this answer was some how useful for me. thankx – Teerath Kumar Jun 10 '14 at 8:24
@RajaRassani You can mark the answer is a correct one with a tick mark, though. Thanks for feed back! – SkyDan Jun 10 '14 at 8:31
this just happened to me :) total bummer.. I do use virtual servers and backup them up regularly..so I'm going to spin up a backup.. and get the deleted crontabs – JustinP May 11 '15 at 15:49

If you have no /var/log/cron file you can recover the commands (but not the timings) from the syslog.

cat /sys/var/log/syslog | grep "(your user name)" | grep CRON

you can then figure out most timings by looking at the datestamps.

share|improve this answer
Thankyou very much. This saved me @meow – NarayaN Apr 19 at 5:49

vi /var/spool/cron/*user* or if you're the root user then vi /var/spool/cron/root

share|improve this answer
This is worse. It edits the spool files without notifying cron that the file has been edited. It also won't work when the user has accidentally deleted their crontab because there is no file to edit. – roaima Jun 23 '15 at 13:06
Upvote from me for actually stating the location of the crontab. I had an entire system backup and could easily retrieve my cronjobs. Thanks! – Cookie Dec 18 '15 at 14:24

protected by Michael Mrozek Jun 23 '15 at 16:36

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.