This question already has an answer here:

I would like to automate some services using cron jobs.

When I try to edit the crontab file at /etc/crontab, I am not able to save it as it says that it is read only.

What can I do?

marked as duplicate by Arronical, PerlDuck, karel, Melebius, Eric Carvalho Oct 18 '18 at 13:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • crontab -l to view cron jobs, to edit crontab -e and to delete all cronjobs of a user crontab -r – janasaiarun Oct 18 '18 at 11:13

You should note that the reason you got an error specifying that the file is read-only is because you are trying to edit a root owned file without being root.

If you want to edit /etc/crontab you should execute your editor as root - (e.g. sudo vi /etc/crontab). Note that it isn't the recommended way for regular users

The answer in here suggest using crontab -e in order to edit the crontab file.

Note that /usr/bin/crontab is executed as root (set user-id root), and will allow you edit crontab for your own user - the file will be created in this root owned folder /var/spool/cron/crontabs.

If you want to execute crontab services which will run as root You should use sudo in order to became root.

You can either update /etc/crontab directly by using sudo vi /etc/crontab (or use any other text editor) and add a line for your job specifying the user as root...

Or you can run:

sudo crontab -e

Which will edit root's crontab file in /var/spool/cron/crontabs.

  • How do I save the crontab I created with sudo crontab -e cause when I create like that and close the terminal, open and write sudo crontab -l it says there are no crontabs for root – The Only Smart Boy Oct 18 '18 at 12:48
  • @TheOnlySmartBoy - running crontab -e will open your default editor, when you complete writing your crontab rules, you should save the file and exit the editor. You should NOT close the terminal at that point. you should first save the file... – Yaron Oct 18 '18 at 13:49
  • @Zanna - thanks for your comment! I've updated my answer to clarify it. – Yaron Oct 21 '18 at 6:09

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