The basic syntax for editing crontab files is:
crontab [ -u user ] { -l | -r [ -i ] | -e }
This means:
-u user
: Specifies which user's crontab to modify (requires sudo)-e
: Edit the crontab-l
: List the crontab contents-r
: Remove the crontab
With sudo privileges, you should use:
sudo crontab -u jake -e
This will open jake's crontab in your default editor (usually vim or nano).
These incorrect formats will all fail:
crontab jake -e # Wrong: user must be specified with -u
crontab [jake] -e # Wrong: brackets are not literal
crontab [-u jake] -e # Wrong: don't include brackets
Here are some common operations you might need:
To view jake's crontab:
sudo crontab -u jake -l
To completely remove jake's crontab (with confirmation):
sudo crontab -u jake -r -i
To add a new entry for jake without interactive editing:
(echo "0 3 * * * /home/jake/backup.sh") | sudo crontab -u jake -
- Always use
sudo
when modifying another user's crontab - The
-u
option must come before the operation (-e
,-l
, etc.) - System crontabs are stored in
/var/spool/cron/crontabs/
but you shouldn't edit them directly - After editing, the crontab service will automatically reload the changes
If you get permission errors even with sudo:
sudo -u jake crontab -e
This alternative syntax sometimes works better with certain sudo configurations.
The correct syntax for editing another user's crontab requires using the -u
flag followed by the username, then the operation flag (-e
for edit). The square brackets in the man page indicate optional parameters, not literal syntax.
# Correct format:
crontab -u username -e
The error "usage error: no arguments permitted after this option
" occurs because:
crontab jake -e
- The username must follow-u
crontab [jake] -e
- Square brackets aren't literal syntaxcrontab [-u jake] -e
- Same issue with brackets
To edit user 'jake's crontab with sudo privileges:
sudo crontab -u jake -e
If you need to script this operation:
# View crontab
sudo crontab -u jake -l
# Edit crontab (opens default editor)
sudo crontab -u jake -e
# Replace entire crontab from file
sudo crontab -u jake /path/to/new/crontab/file
Remember that:
- You must have sudo privileges
- The target user must exist on the system
- The
/etc/cron.allow
file (if present) must include your username - Your user shouldn't be listed in
/etc/cron.deny
Here's how to add a daily backup job for user 'jake':
sudo crontab -u jake -e
# Add this line:
0 2 * * * /home/jake/scripts/backup.sh
# Save and exit
If you encounter problems:
# Verify cron service is running
sudo systemctl status cron
# Check logs for cron errors
sudo tail -f /var/log/syslog | grep CRON
- Always use absolute paths in cron jobs
- Consider using
/etc/cron.d/
for system-wide jobs - Limit sudo access to crontab modification
- Review user crontabs regularly