In the realm of Linux, ‘crontab’ is a term you may come across fairly often. This utility, available on Unix-like operating systems, is used to schedule tasks that are automatically executed at predefined times and intervals. This is highly beneficial for administrators and power users, allowing them to automate various system tasks.
Crontab files are edited using a text editor. Often, the default editor might be one you’re not comfortable with, such as vi. However, the good news is that you can change this default editor to one of your preference, like nano or emacs. In this article, we’ll walk you through a step-by-step process of changing your default crontab editor.
Step 1: Understand Your Current Default Editor
Before making any changes, it’s useful to know what your current default editor is. In most Linux distributions, ‘vi’ is set as the default editor. You can check this by typing the following command in your terminal:
This command will output the current default editor.
Step 2: Get Familiar with Available Editors
There are many text editors available for Linux. Some of the more popular ones include:
- vi/vim: A traditional text editor for Unix-like systems.
- nano: A simple and user-friendly text editor.
- emacs: A feature-rich text editor that offers a plethora of capabilities.
Choose the one you’re most comfortable with.
Step 3: Changing the Default Editor
Temporarily (for the current session only)
To change the default editor for the current session only, use the following command:
For instance, if you want to set nano as the editor, the command would be:
This change will only last for the current session. If you exit the terminal or start a new session, it will revert to the previous default editor.
Permanently (for all future sessions)
If you want to make the change permanent, you need to add the ‘export’ command to your shell’s configuration file (.bashrc for bash shell, .zshrc for zsh shell, etc.).
Open the appropriate configuration file with your current editor:
And then append the export command at the end of the file:
Save and close the file.
After this, load the new configuration using the ‘source’ command:
Now, the new editor setting will persist across sessions.
Step 4: Verifying the Change
To verify that your changes have taken effect, use the ‘echo’ command again:
This command should now return the new default editor you set.
As you can see, changing the default crontab editor on your Linux system is quite straightforward. It’s a small customization that can significantly enhance your system usage experience, particularly if you’re dealing with crontab files frequently. Remember to choose an editor you’re comfortable with, and you’re good to go!