crontab -e 简单问题

crontab -e 简单问题

我是 crontab 命令的新手,当我研究这个命令时,我突然输入一些数字并使我的 crontab -e 看起来像这样:


pi@raspberrypi:~ $ crontab -e
no crontab for pi - using an empty one
889


有什么方法可以将 crontab 设置回默认值或如何删除它们?我只想使用 crontab 自动执行我的任务。

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
"/tmp/crontab.QzVh1G/crontab" 23 lines, 898964 characters


在我按照您的指示进行操作后,它显示如下export VISUAL=vi crontab -e,似乎除了使用 qa 之外我无法编辑此文件!退出。有什么我错过的吗?

答案1

您的编辑器设置为ed.编辑ed是一位非常基本行编辑器将在您打开文件时输出文件中的字节数。在本例中,您的 crontab 文件包含 889 个字节(在编辑器中,p键入并按Enter以查看文件的内容)。

您很可能不想将ed其用作编辑器(或者您会意识到您已经启动了它)。要退出编辑器,只需键入q并按Enter,或按Ctrl+D

然后再次运行crontab -e,但将VISUAL环境变量设置为您最常用来编辑系统上的文件的编辑器。

作为示例,以下是您可以设置的方式VISUAL,但您可以使用或恰好安装的任何其他终端编辑器。vinano

export VISUAL=vi
crontab -e

VISUAL您可能需要在 shell 的启动文件中设置 的值(~/.bashrc如果您使用的是bash)。

相关内容