odiszapc
odiszapc

Reputation: 4109

Are these cron expressions equivalent?

Is there any diffenrence between

*/5 * * * * <COMMAND>

and

0/5 * * * * <COMMAND>

?

Upvotes: 1

Views: 895

Answers (1)

fedorqui
fedorqui

Reputation: 289525

It is not the same.

  • The first one will be executed every 5 minutes starting any moment, while
  • the second one will be executed on minutes 0, 5, 10,... 55.

Only if the first one is executed on minute 5k for the first time, they will have the same behaviour.


Every 5 minutes can be written like this:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * <COMMAND>

this

0/5 * * * * <COMMAND>

or

*/5 * * * * <COMMAND>

Anyway, last one will start any time the minute changes and then keep a distance of 5 minutes to next execution.


The * character means every. If it is alone, it will mean every minute, every hour, etc.

The / character can be used to specify increments to values. If we indicate X/Y it means every Y minutes starting at minute X.

  • 0/15 = every 15th minute of the hour, starting at minute zero = 0,15,30,45
  • 3/20 = every 20th minute of the hour, starting at minute three = 3,23,43
  • /40 = every 40th minute of the hour= 40
  • 3/40 = every 40th minute of the hour, starting at minute three= 43

Coming back to your question, the use of both operators gets the following result:

*/5 = every 5 minutes starting anytime. This way, it will start whenever changes the minute and repeat after 5 minutes, 10, etc.

0/5 = every 5 minutes starting on minute 0. It will be internally considered as: 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55 as these are the minutes that suit the condition +5 minutes coming from start at minute 0.


Some references:

Upvotes: 3

Related Questions