I want to repeat a task every day at 6PM.

I know this command executes a task at the next 6PM:

echo "ls -l" | at 18:00

I tried to RTFM but didn't find anything relevant to repeating said task. What's the right way to do this?

  • Do you want to print the string ls -l or do you want to run the command ls -l every day at 18:00? – terdon Jul 26 '17 at 14:45
  • 2
    at is for running a job one time. cron is for running a reoccurring job at a regular schedule. – jesse_b Jul 26 '17 at 14:48

man cron is your friend. For this, you might want to try something like:

0 18 * * * echo "ls -l" > /var/log/ls_log.log

Add it to the crontab with crontab -e. Check the output of the command by looking at /var/log/ls_log.log. Google "cron tutorial"- there are lots of them

  • Does this persist across system restarts? This is for a raspberry pi. – shashanka n Jul 26 '17 at 14:55
  • It should, yes. cron starts a deamon that reads from the crontab on startup. – Ben Jul 26 '17 at 14:59
  • @shashankan if you type man cron into your terminal, it tells you this. though not succintly – Ben Jul 26 '17 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.