Chris Dzombak

sharing preview •

Small commands, big consequences

My personal favorite Linux CLI gotcha is crontab -e vs. crontab -r.

Small commands, big consequences

Rachel Kroll, via Michael Tasi:

$ date -d @1700000000
Tue Nov 14 14:13:20 PST 2023

The problem is, there’s another command very much like it that will even spit out the same output, only it has a nice little side-effect: it also sets the clock. That command is date -s.

If you’re on a QWERTY layout or are generally familiar with it, you might notice that [S] and [D] are right next to each other and are an easy typo to make with your left hand. That’s one way to screw up.

Another problem is that you might not have known that -s has that effect[…]

My favorite Linux CLI gotcha, which I’ve noted before on Twitter: crontab -e opens an editor to edit your crontab.

crontab -r removes your crontab, without asking for confirmation.

On a QWERTY keyboard, E and R are right next to each other.

This has bitten me enough times that I make sure, when setting up a new system, that /var/spool/cron is included in the system’s regular, offsite backups.

(Reviewing the documentation, I just learned that the -i option “modifies the -r option to prompt the user for a ‘y/Y’ response before actually removing the crontab.” I’ll go ahead and alias crontab='crontab -i' in my standard Linux server bash setup, but how on earth does this not ask by default?)