How to change the default crontab editor

Removing crontab Files

By default, crontab file protections are set up so that you cannot inadvertently delete a crontab file by using the rm command. Instead, use the crontab -r command to remove crontab files.

By default, the crontab -r command removes your own crontab file.

You do not have to change the directory to /var/spool/cron/crontabs (where crontab files are located) to use this command.

How to Remove a crontab File

Before You Begin

Become the root user to remove a crontab file that belongs to root or another user. Roles contain authorizations and privileged commands.

You do not need to become root to remove your own crontab file.

    Remove the crontab file.

where username specifies the name of the user’s account for which you want to remove a crontab file. Removing crontab files for another user requires superuser privileges.

Caution – If you accidentally type the crontab command with no option, press the interrupt character for your editor. This character allows you to quit without saving changes. If you instead saved changes and exited the file, the existing crontab file would be overwritten with an empty file.

Example 14-5 Removing a crontab File

The following example shows how user smith uses the crontab -r command to remove his own crontab file.

Crontab is the program used to install, remove or list the tables used to drive the cron daemon. Cronjobs are predefined jobs which are running periodically according to the settings we have done previously. In the /etc folder there is a file called crontab where we can write the command or name of the script that is to be executed at as per our customized time.

The command used to edit the cron configuration file is “crontab.” You can use the “-e” switch along with the command “crontab” to edit the configuration. If it’s for a particular user you can use the “-u” switch to specify the user name. Managing crontab via CLI is not a big task.

Examples are listed below:

For a particular user:

How to check the default editor in my server?

You can use the echo command to display the default editor on your server. Please see the command pasted below:

There are different editing tools are available with a default Linux installation, like vi, vim, nano, pico etc..

Different command-line users prefer different editors for their daily work. Here I’m explaining the steps to change the default editor selection. The corntab editor command “crontab -e” uses the default file editor to configure cron.

How to change the default editor from command line?

1. Checking current editor:

You can use the aforementioned echo command to check the current editor.

2. Exporting the new editor details:

3. Check if it’s changed:

4. To set it permanently, please run the following command:

That’s it dude!!
Go ahead and set it to yours favorite!!

If you have any questions, please commend here or create a topic here.

Post navigation

Arunlal Ashok

Senior Operations Engineer (SRE) at NewFold Digital. Linux lover. Traveller. Father of two princesses.

I am trying to change the default editor from nano to vim .

I have run the following commands:

sudo update-alternatives –config editor

update-alternatives –config editor

Both now output:

I have restarted my ssh session and restarted sshd but crontab -e still opens in nano

What else do I need to do?

10 Answers 10

Just simply run select-editor , this will let you choose any editor you want.

Try your ssh session followed by

The format of setting of the EDITOR variable depends on which shell you are using.

In Ubuntu you can set the EDITOR environment variable on logon by adding the above to the

Your SSH session will read a similar file (if it exists) on the remote host called

/.ssh/environment . This has to be specifically defined by the ssh daemon config. See man sshd_config and look for PermitUserEnvironment for more details.

My personal preference.

If you only want to choose the editor temporarily, you can do the following

This sets the EDITOR environment variable for the command

From “man crontab”:

Perhaps you have the EDITOR enivronment variable set to nano?

On my Ubuntu 12.04 computer, crontab uses the

/.selected_editor file, which contains the path of the selected editor. Edit it:

I have edited it directly or used select-editor , which is a script to do the same thing. Edit the following line:

IHMO people should not be changing anything in /etc or /bin to do this. It is a user level thing, not a system wide task.

How to change the default crontab editor

I was having difficulties with select-editor and update-alternatives , my solution was to simply edit the link:

  1. sudo rm /etc/alternatives/editor
  2. sudo ln -s /usr/bin/vim /etc/alternatives/editor

editor now opens Vim

I’ve had the same problem – crontab -e relies on select-editor, visudo relies on the config of “alternatives”

run both commands as root

After trying the answers above, the only thing that worked for me (in Debian strech) was to remove

/.selected_editor by running:

And then select the new editor next time you run crontab -e .

In addition to checking that the environmental variable EDITOR is set correctly, you should also check to make sure the variable VISUAL is also set correctly.

VISUAL will override EDITOR

From the documentation:

The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.

In this article, we will see how to change default editor for crontab. The crontab -e command will check the environment variables $EDITOR and $VISUAL for an override of the default text editor.

Now we are going to change the default editor for crontab to vi or vim.

We are going to change temporary and permanent.

1. Change default editor for crontab to vi Temporarily:
2. Change default editor for crontab to vi Permanently:

First time if you run crontab -e, it asks us to select editor of any of the following choices. Then, we have to provide numbers. That option is permanent for the user.

In my environment default text editor for crontab is selected as nano editor. Now, I am going to change it to vi or vim.

How to change the default crontab editor

1. Change default editor for crontab to vi Temporarily:
Following method is for current session. If we disconnect the session and reconnect them default editor for crontab will be same as original.

if you want to give vim, then just replace vi with vim.

Now, run crontab -e. Then, it will open with vi editor.

2. Change default editor for crontab to vi Permanently:
Following method is permanent
Open profile.

Then add $EDITOR=vi
Then save and quit.

Now, run crontab -e. Then, it will open vi as text editor for crontab.

How to change the default crontab editor

Want to change the crontab editor on the Mac? You can do that! We’ll show you how to use a different crontab editor on a selective per-edit basis, and also how to change the default crontab text editor. You can use vi, emacs, nano, or whatever else you’d like. Most hardcore command line users and unix geeks love vi, but I personally prefer nano, so that will be what is demonstrated here.

If you want to change your default crontab editor to nano, here’s how to do this via the command line in Mac OS X (and linux too but we’re focusing on Mac here obviously).

How to Use a Different crontab Editor Once

For a one time edit, launch the terminal and type:

EDITOR=nano crontab -e

How to Change crontab Default Editor in Mac OS X Command Line

If you want to set nano as your default editor in general, you use this command:

Now when you go to edit crontab, nano will be the default editor than vi.

How to Check What Editor Crontab is Using

You can test changes to cron editor or check what editor this is using by typing:

Looking beyond Mac OS X, this should work in Linux as well.

If you know of other approaches to methods to modifying crontab editors and cron, or any other helpful cron or command line tips, share in the comments below!

Cron expressions are a useful tool for automating tasks using cron expressions. In this tutorial, we’ll learn how to change the default editor for maintaining our crontab.

2. Environment Variables

There are two environment variables we can use to change the editor opened by crontab -e.

Note that the examples below will change the editor for the current terminal session only. We can make this change persistent by using environment variables.

2.1. EDITOR

First, we can use EDITOR. Let’s change our editor to nano:

Depending on our configuration, this might not actually work because there is another variable that takes precedence.

2.2. VISUAL

The VISUAL environment variable takes precedence to EDITOR. Let’s see if we can override the EDITOR variable we set before by setting VISUAL to joe:

Now, every time we issue crontab -e, it should open our crontab in joe instead of nano.

3. select-editor

Some Linux distributions (like Ubuntu) provide us with a command select-editor. Running select-editor gives us a list of editors to choose from:

The selection is stored in our home directory in

/.selected-editor and therefore persistent across terminal sessions.

Note that the environment variables EDITOR and VISUAL take precedence over select-editor, so we’ve got to make sure these variables aren’t set.

4. Conclusion

In this article, we’ve learned how to make crontab -e use our favorite editor. The recommended way is by setting the VISUAL environment variable.

Depending on our Linux distribution, we might also use the select-editor utility.

Creating and Editing crontab Files

The simplest way to create a crontab file is to use the crontab -e command. This command invokes the text editor that has been set for your system environment. The default editor for your system environment is defined in the EDITOR environment variable. If this variable has not been set, the crontab command uses the default editor, ed. Preferably, you should choose an editor that you know well.

The following example shows how to determine if an editor has been defined, and how to set up vi as the default.

When you create a crontab file, it is automatically placed in the /var/spool/cron/crontabs directory and is given your user name. You can create or edit a crontab file for another user, or root, if you have superuser privileges.

How to Create or Edit a crontab File

Before You Begin

If you are creating or editing a crontab file that belongs to root or another user you must become root.

You do not need to become root to edit your own crontab file.

    Create a new crontab file, or edit an existing file.

where username specifies the name of the user’s account for which you want to create or edit a crontab file. You can create your own crontab file without superuser privileges, but you must have superuser privileges to creating or edit a crontab file for root or another user.

Caution – If you accidentally type the crontab command with no option, press the interrupt character for your editor. This character allows you to quit without saving changes. If you instead saved changes and exited the file, the existing crontab file would be overwritten with an empty file.

Follow the syntax described in Syntax of crontab File Entries. The crontab file will be placed in the /var/spool/cron/crontabs directory.

Example 14-1 Creating a crontab File

The following example shows how to create a crontab file for another user.

The following command entry added to a new crontab file automatically removes any log files from the user’s home directory at 1:00 a.m. every Sunday morning. Because the command entry does not redirect output, redirect characters are added to the command line after *.log. Doing so ensures that the command executes properly.

How to Verify That a crontab File Exists

  • To verify that a crontab file exists for a user, use the ls -l command in the /var/spool/cron/crontabs directory. For example, the following output shows that crontab files exist for users jones and smith.

Verify the contents of user’s crontab file by using the crontab -l command as described in How to Display a crontab File.

Linux crontab FAQ: How do I edit my Unix/Linux crontab file?

I was working with an experienced Linux sysadmin a few days ago, and when we needed to make a change to the root user’s crontab file, I was surprised to watch him cd to the root cron folder, make changes to the file, then do a kill -HUP on the crontab process.

Thinking he knew something I didn’t know, I asked him why he did all of that work instead of just entering this:

at the command line. After he asked me what that did, we both had a good laugh when I said, “Dude, it automates everything you just did manually.”

What “crontab -e” does

The Linux crontab documentation is pretty clear about editing the crontab files:

Each user can have their own crontab, and though these are files in /var/spool, they are not intended to be edited directly.

The documentation further states that the crontab command should be used to edit your crontab file, and you specifically edit the file with the crontab -e command.

Here’s a description of what the crontab -e command does, taken directly from the crontab man page:

I assume that when they say “the modified crontab (file) will be installed automatically,” they mean that the new file is put in place of the other file, and then a -HUP signal is sent to the cron daemon, but I don’t know this for fact. I do know that’s what I had to do in the old days, so again, I assume that’s what they’ve done to automate this process.

What “kill -HUP” means

If you’ve never sent a HUP signal to a Unix or Linux daemon before, the first thing to know is that HUP stands for “hangup”. While you should be very careful doing this, you can send a HUP signal to a daemon by using this command:

or this equivalent command:

(That’s the number “one” in that last example.)

Again, for daemons that support this signal, the HUP command typically means “re-read your configuration files, something just changed”. I used to use it all the time with the cron and inetd daemons, issuing that command whenever I changed their configuration files.

Other crontab command options

Before leaving this topic, I just noticed that besides seeing the crontab command options on the crontab man page, you can also see them from the command line by typing something like crontab -h or crontab –help . Technically, this doesn’t give you the help I expected, but it does give you a crontab usage statement. 🙂

Here’s the output from that usage statement:

As you can see, the crontab -l command lists your crontab, which is the same as cat’ing it out. Personally, I always use the crontab -e command, but this is one other option I can see using from time to time.

More Unix/Linux crontab information

For more information on the Unix and Linux crontab system, here are two links to the crontab man pages (help/support documentation):

By default, nano is the text editor in Ubuntu. Sometimes you may need to change the default text editor for applications like crontab, that require a text editor. For example, if you are comfortable with vi then you may want to set the default text editor to vi. There are two ways to do this. In this article, we will look at both these methods. Here are the steps to set default text editor in Ubuntu. You can also use them to change text editor in other Linux distributions like CentOS, Redhat, Debian, and other systems.

How To Set Default Text Editor in Ubuntu

You can change default text editor in Ubuntu by editing .bashrc file, or using update-alternatives command.

Using .bashrc

Open terminal and run the following command to open .bashrc file. Please use the dot(.) before its filename since it is a hidden file.

Add the following lines to .bashrc file to set default editor to vi in Ubuntu. Replace vi with the text editor of your choice.

Save and exit the file.

Now log out of your account and log in again, to apply changes. Alternatively, you can also run the following command.

That’s it. The default text editor in Ubuntu will be changed to vi.

Using update-alternatives

Open terminal and run the following command. It will list all the editors available in your system, with a * displayed before the present default text editor.

When you enter the above command, you will see a prompt as shown below.

In the above output, * is displayed before option 3 since it is our default editor. If you want to change the default text editor to vim, enter 1. If you want to continue with your existing default text editor, then enter 3.

That’s it. Your default text editor will be changed.

You can easily test the change by entering crontab -e command, which will open the default text editor.