cron

How to save the file after typing "crontab -e"


I open the file in terminal through crontab -e command and now I want to save it. I've tried several things, like :wq or Ctrl-X, but it did not save the file. How can I do that?


Solution

  • The crontab -e command invokes your default editor, which is one of the following:

    The latter is a symbolic link to some editor. On Linux, the default appears to be nano.

    If it's nano, then there should be a 2-line menu at the bottom of the screen. Type Ctrl-X to exit; if you've modified the file it will ask you whether you want to save it.

    If you have a preferred editor, you should set both $VISUAL and $EDITOR to the command used to invoke it. For example, I have:

    export EDITOR=vi
    export VISUAL=$EDITOR
    

    in my $HOME/.bash_profile.

    This applies to the system I'm using, a recent Linux system with the Vixie cron implementation. If your system differs significantly, not all of this is necessarily applicable.

    man crontab should explain how the crontab command works. If not, the documentation is also available here.

    (Incidentally, I keep my crontab in a separate file under my home directory, maintained in a source control system. That lets me keep track of changes and revert to a working version if I mess something up. With crontab -e, it's easy to make mistakes and difficult to recover from them.)