Humanity

Edit the world by your favorite way

crontabファイルをうっかり消さないようにする

-iオプションという便利なオプションがあったのでaliasしておく。*1

alias crontab='crontab -i'

すると

$ crontab -r
crontab: really delete tyru's crontab?

こうなる。


あとcrontabは何も引数を与えずに起動すると標準入力から受け取った文字列を
現在のユーザのcrontabファイルとして置き換えるけど、
aliasしてれば

$ crontab
crontab: usage error: file name must be specified for replace
usage:  crontab [-u user] file
        crontab [-u user] { -e | -l | -r }
                (default operation is replace, per 1003.2)
        -e      (edit user's crontab)
        -l      (list user's crontab)
        -r      (delete user's crontab)
        -i      (prompt before deleting user's crontab)

ちゃんとエラーになる。


追記

おお。たしかにバックアップも簡単そうでよさそう。

*1:これDebian系特有のオプションとかだったりするんだろうか