Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

cron

crontab

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?

like image 883
Moaz Ateeq Avatar asked Aug 01 '14 00:08

Moaz Ateeq


People also ask

How do I save after crontab E?

press i for write; than press ESC and :wq for save and exit.

How do I save a crontab in a text file?

crontab -e simply fires up the crontab file for that account in your default text editor so you can edit it. With nano, which is the default on ubuntu, you can hit ctrl-x then choose to save. From the comments :wq for Vim and C-x C-s to save and C-x C-c to exit for emacs.


2 Answers

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

  • The command specified by the $VISUAL environment variable (if it's set); or
  • The command specified by $EDITOR; or
  • /usr/bin/editor

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.)

like image 115
Keith Thompson Avatar answered Sep 23 '22 02:09

Keith Thompson


You need to set your editor variable:

$ EDITOR=vi
$ export EDITOR
$ crontab -e

Of course if vi isn't your editor, change it accordingly.

like image 44
Jason Enochs Avatar answered Sep 19 '22 02:09

Jason Enochs