
Want to have crontab
use the editor of your choice instead of the other way around? This tutorial shows you how. These instructions will work with Linux, macOS and other Unix-like operating systems.
The delicate subject of text editors
A text editor performs a rather mundane task. Despite this, the depth of feelings that people associate with their personal preference editor has led to flame wars that have been burning since 1985. We ain't stoking that fire, nor advocating one publisher over another. What we will show you is how to change the default editor for crontab
to something else, if you wish.
the crontab -e
The command will open an editor so you can edit your cron table. Your cron table contains the list of any scheduled jobs that you have set to occur at specific times. We will not delve into the details of cron jobs in this post.. We are simply looking at the editor associated with the crontab -e
command.
RELATED: How to schedule tasks in Linux: Introduction to Crontab files
The first time you broadcast the crontab
command with the -e
(Edit) in a bash terminal, you will be asked to choose the editor you would like to use. Writes crontab
, a space, -e
and press Enter.
crontab -e
The editor you select is used to open your cron table. In this example, nano was chosen by pressing the key 1.
The editor you select from the menu is used each time you output the crontab -e
command. If you later change your mind, How do you choose another editor if you only get the menu the first time? That is easy. The command to use is select-editor
.
select-editor
Up to now, very easy. But, what if you want to use an editor that is not in that menu? Or what if you're working on an operating system that doesn't provide the select-editor
command? We can also handle those scenarios.
What about distributions that don't provide a selection editor?
We can set the default editor for crontab
adding a line to our .bash_profile file. type this command:
gedit ~/.bash_profile
When the editor appears, add this entry to the file:
export VISUAL="gedit"
Of course, would replace the command that starts the editor you want to use with 'gedit'. save that file and close the editor. To see these changes take effect, log off and log on again or issue this command:
. ~/.bash_profile
Note that the line begins with a point or a point. the source
command is an alias for the period command and performs the same action. But not all distributions provide the source
command. The period command should always be presented. Having given that caveat, the source
command era present in all distributions, this post was tested with Ubuntu, Debian, Manjaro, Arch, Fedora, CentOS and OpenIndiana.
Whether you type a period or the word source
, the command causes your .bash_profile settings to be read and transferred to your current session. Now, when you write:
crontab -e
the editor you specified will be used to open your cron table.
It is feasible that your .bash_profile is not empty
It is feasible that your .bash_profile file is not empty when you edit it. Just scroll to the bottom and add the export VISUAL="gedit"
line at the end of the file. This is the default .bash_profile in Manjaro Linux, with the new line added:
And in conclusion, OpenIndiana
With OpenIndiana, you must add the export VISUAL="gedit"
line to your .bashrc file, not to your .bash_profile. The command you need to enter is:
pen ~/.bashrc
Add the line and save the file, and close and reopen your terminal window.
Issue the crontab -e
command to verify that your changes have taken effect:
crontab -e
And now your cron table is loaded in nano.
Now you can specify the editor of your choice on many types of Linux, whether it is descended from Debian, RedHat, Arch or something more like a plain and ordinary Unix.