Editing crontab from command line
In some cases you need to edit your crotab via command line interface. That’ s easy, but if you’ re not familiar with vi and its commands, you might have problems saving and editing cronjobs. First of all, let’s[ list your current crontab contents by issuing the following command:
crontab - l
This will show all the tasks you have at the moment. Your crontab may be empty so don’t worry, if you don’t find anything there. This is just to ensure that we don’t add duplicate records.
Now let’s type crontab -e to add a new task. If you don’t have any tasks for current user, you may get something like this:
[root@lampdocs ~]# crontab -e
no crontab for root - using an empty one
So let’s edit it. First of all. press I button of your keyboard. You will see a little message at the bottom of your screen:
Now add the command you need, and how often you need to run it. It should look like:
10 * * * * /root/clean.sh
(I will not tell about crontab format in this article).
In order to save it press Escape button. — INSERT — message will disappear. Now type in: :wq and press return (Enter). This will save your crontab and exit the editor interface. In order to quit without saving, just type in :q! and your changes will not be saved.
I will tell you about other VI commands in my future posts and you will find out how many possibilities it includes.