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?
press i for write; than press ESC and :wq for save and exit.
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.
The crontab -e
command invokes your default editor, which is one of the following:
$VISUAL
environment variable (if it's set); or$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.)
You need to set your editor variable:
$ EDITOR=vi
$ export EDITOR
$ crontab -e
Of course if vi isn't your editor, change it accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With