Anyone know how to use crontab properly?
When I edit my crontab, using "crontab -e", I get stuck inside crontab and I am unable to leave it. I used Google and there was nothing useful that came about, which surprised me.
Anyone know how to save and exit? Please be as specific as possible.
My guess is, you are just unfamiliar with the vi editor.
This is the default editor started by crontab -e
Either learn vi(m), or set a different $EDITOR variable,
To try it in your current session, type:
EDITOR=nano crontab -e
So... how do you save and exit?
Originally Posted by Irithori
In nano, the shortcut keys should be at the bottom.
To save, you want to "Write out" which I believe is ctrl+w
Then, it will ask you something about "write to file such and such?" and confirm.
Then, exit with ctrl+x.
I prefer using vi/vim. To write in vi is to return to command mode, and type :w (then press enter)
To quit, type :q (then press enter).
vi/vim takes some time getting used to. It would be worth your time to read a tutorial somewhere online. I vastly prefer vi/vim over nano because bsd, solaris, and many distros don't include nano by default, and vi is on nearly every distro.
Use this as a quick reference for VI, you will find it useful as VI is the default editor in all Unix platform. You can do fine by knowing 5-6 keyword command.
ESC = exit command mode or abort an entered mode
: = enter command mode
:w = write file
:q = exit file
:wq = write and exit file
:q! = force quit (the ! mean to force the command even if there is a warning, it cannot override OS error like read only file that you try to write etc.)
:wq! = force write and force quit *just adding the ! symbol*
:set number = display row line number
There is type of command that are entered without the : and are editing command shortcut. When you enter one of the editing mode, you have to ESC to exit it and be able to enter another command.
i = Insert (The cursor will be put exactly where you are, you cannot go beyond the last character. Once in insert mode, what you type is going in the text file as you would with any text editor, to exit press ESC once)
a = Append (The cursor will be put after the current character, useful if you want to add a character after the last character of the current line)
s = Suppress the current character and enter Insert mode. The cursor will delete the current character and will be put in editor mode.
dd = Delete the whole current line
dw = delete the next word
123gg = [123 is any number] goto line 123
DEL key = Delete
BackSpace = Delete backward
With that, you can do 90% of the job fast and efficiently.