AI Block Lab | Linux Server Tutorials
Linux Server Tutorials
Working with crontab in Linux

1. Show list of all tasks
Display all cron jobs for the current user:
crontab -l
2. Add a new task
Edit your crontab file:
crontab -e
Add the following line at the end of the file to run a command every day at midnight:
0 0 * * * php /full/path/to/index.php
Replace /full/path/to/index.php
with the actual path to your script.
3. Edit a task
Run:
crontab -e
Then modify the desired line in the editor.
4. Delete a task
Also via:
crontab -e
Just delete the task line and save changes.
To delete all cron jobs at once:
crontab -r
Warning: This removes all crontab entries for the user without confirmation.
Useful Examples
Every 5 minutes:
*/5 * * * * php /home/user/script.php
Every day at 6:30 AM:
30 6 * * * php /home/user/script.php
Every Monday at 7:00 AM:
0 7 * * 1 php /home/user/script.php
Log output to file:
0 0 * * * php /home/user/index.php >> /home/user/logs/cron.log 2>&1
>>
appends output; 2>&1
combines stderr and stdout.
Check if cron is running
systemctl status cron
If stopped, start it:
sudo systemctl start cron
Other tips
Edit crontab for another user:
sudo crontab -u username -e
System-wide cron jobs:
/etc/crontab
/etc/cron.daily/
/etc/cron.hourly/
/etc/cron.weekly/
/etc/cron.monthly/