Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How to save and exit crontab -e?

i tried every method listed here and none works, i have a centos 5, vi comes by default with yum and i installed nano

Solved

just changed the default editor

export EDITOR=nano

and now i can do what I do using nano :) thanks everyone and yes i should learn Vi.. someday!!!

share|improve this question
    
echo $EDITOR? –  quanta Sep 4 '11 at 16:25
    
@quanta sir didn't work well maybe I'm doing something wrong since I'm used to use nano and not vi ok so I open contab -e, write echo $EDITOR and press enter, it does not exit, it goes down 1 line –  user Sep 4 '11 at 16:38
    
No, I mean type echo $EDITOR from the terminal to determine what default editor you are using. –  quanta Sep 4 '11 at 16:49
    
@quanta thank you for reminding me that i can change my default editor :D –  user Sep 4 '11 at 17:14
add comment

4 Answers

up vote 6 down vote accepted

As others have pointed out, the first thing is to make sure you're using an editor you like.

We're all admins here, so we all like vi (ducks, runs).

export VISUAL=vi
crontab -e

(do some edits, finishing with ESCAPE)

:wq

And crontab -l should now show you your new crontab. If you prefer some other editor, set that in the VISUAL environment variable, and exit it as appropriate.

share|improve this answer
    
sir, I'm not used to vi, i use nano, that's why I'm having difficulties :) –  user Sep 4 '11 at 16:40
    
I'm glad you've found a solution; but may I encourage you to ask the question you want answered in future? Perhaps a better question here would have been "how do I change the editor that's invoked when I type crontab -e"? People will be quick enough to offer alternatives if the thing you actually want seems impossible. –  MadHatter Sep 4 '11 at 18:15
    
You can also hit ESC then :x to save and exit, or hit ESC then ZZ (that's shift+zz). –  laebshade Sep 4 '11 at 18:36
    
sorry :D when I asked the question i wanted to figure out how to do it in vi and then quanta asked me to see what is my default editor, then i remembered to change it and do it easily with nano - I did not have that idea when i asked the question :D –  user Sep 4 '11 at 19:57
add comment

Ctrl+x, answer by pressing y to save changes and Enter to confirm.

share|improve this answer
add comment

To exit vi editor:

Usually the new or modified file is saved when you leave vi. However, it is also possible to quit vi without saving the file. The cursor moves to bottom of screen whenever a colon (:) is typed.

:x<Enter>   quit vi, writing out modified file to file named in original invocation
:wq<Enter>  quit vi, writing out modified file to file named in original invocation
:q<Enter>   quit (or exit) vi
:q!<Enter>  quit vi even though latest changes have not been saved for this vi call
share|improve this answer
add comment

esc-esc-:wq? Are you saying vi is the default editor, and you want nano instead?

Saving and quitting vi is outlined here: http://www.helpdesk.umd.edu/documents/4/4793/#a13

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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