3 added 3 characters in body
source | link

If you know times are not much over one hour, you can simply add 60 if the result is negative. However, this is not the way to do it anyway. There are several points I'd like to raise:

  1. NEVER parse output of ls, especially not the time part. It depends on the locale willand can give completely unpredictable results.
  2. Why assume times are around a hour and just like at the minutes, if you can just subtract dates? Use the unix timestamp - the number of second since the beginning of the world (1970). That's the standard way of storing time.
  3. Just write let i++ and let l=j-k, don't use millions of parentheses
  4. You are making $l an array of length 1, and then access $i th member. This is why it only works for the first pair.
  5. You are using very c-like programming style. Use a loop of the form for i in "${MMarray[@]}"; do... and just save the previous one.
  6. You are using too much arrays and loops, do everything in a stream of dates, it will be much better. So pretty much everything can be rewritten.
  7. You do realize, that an average time is simply first minus last divided by the number of files minus 1 (the number of diffences)? You don't need to subtract and then add together again...

What to do if you want to get all the time differences in seconds, one per line:

find /some/location -type f -name '*your filter which files you want*' -printf '%T@\n' | sort -n | awk 'NR>1 { print  $1-previous } {previous = $1}'

What it does? find finds the files and prints the unix timestamps. If you don't specify -name it lists eveything. -type f means only files, no directories. sort -n sorts the times numerically. awk simply computes and prints differences.

For average, just keep the first and the last date. For instance, for all the files in the current directory:

find . -type f -printf '%T@\n' | sort -n | awk 'NR==1 { first = $1 } END{ print ($1-first)/(NR-1) }'

The results are decimal numbers in seconds, but you can easily just write int(($1-first)/(NR-1)) for an integer or int(($1-first)/(NR-1))/60 for minutes.

If you know times are not much over one hour, you can simply add 60 if the result is negative. However, this is not the way to do it anyway. There are several points I'd like to raise:

  1. NEVER parse output of ls, especially not the time part. It depends on the locale will give completely unpredictable results.
  2. Why assume times are around a hour and just like at the minutes, if you can just subtract dates? Use the unix timestamp - the number of second since the beginning of the world (1970). That's the standard way of storing time.
  3. Just write let i++ and let l=j-k, don't use millions of parentheses
  4. You are making $l an array of length 1, and then access $i th member. This is why it only works for the first pair.
  5. You are using very c-like programming style. Use a loop of the form for i in "${MMarray[@]}"; do... and just save the previous one.
  6. You are using too much arrays and loops, do everything in a stream of dates, it will be much better. So pretty much everything can be rewritten.
  7. You do realize, that an average time is simply first minus last divided by the number of files minus 1 (the number of diffences)? You don't need to subtract and then add together again...

What to do if you want to get all the time differences in seconds, one per line:

find /some/location -type f -name '*your filter which files you want*' -printf '%T@\n' | sort -n | awk 'NR>1 { print  $1-previous } {previous = $1}'

What it does? find finds the files and prints the unix timestamps. If you don't specify -name it lists eveything. -type f means only files, no directories. sort -n sorts the times numerically. awk simply computes and prints differences.

For average, just keep the first and the last date. For instance, for all the files in the current directory:

find . -type f -printf '%T@\n' | sort -n | awk 'NR==1 { first = $1 } END{ print ($1-first)/(NR-1) }'

The results are decimal numbers in seconds, but you can easily just write int(($1-first)/(NR-1)) for an integer or int(($1-first)/(NR-1))/60 for minutes.

If you know times are not much over one hour, you can simply add 60 if the result is negative. However, this is not the way to do it anyway. There are several points I'd like to raise:

  1. NEVER parse output of ls, especially not the time part. It depends on the locale and can give completely unpredictable results.
  2. Why assume times are around a hour and just like at the minutes, if you can just subtract dates? Use the unix timestamp - the number of second since the beginning of the world (1970). That's the standard way of storing time.
  3. Just write let i++ and let l=j-k, don't use millions of parentheses
  4. You are making $l an array of length 1, and then access $i th member. This is why it only works for the first pair.
  5. You are using very c-like programming style. Use a loop of the form for i in "${MMarray[@]}"; do... and just save the previous one.
  6. You are using too much arrays and loops, do everything in a stream of dates, it will be much better. So pretty much everything can be rewritten.
  7. You do realize, that an average time is simply first minus last divided by the number of files minus 1 (the number of diffences)? You don't need to subtract and then add together again...

What to do if you want to get all the time differences in seconds, one per line:

find /some/location -type f -name '*your filter which files you want*' -printf '%T@\n' | sort -n | awk 'NR>1 { print  $1-previous } {previous = $1}'

What it does? find finds the files and prints the unix timestamps. If you don't specify -name it lists eveything. -type f means only files, no directories. sort -n sorts the times numerically. awk simply computes and prints differences.

For average, just keep the first and the last date. For instance, for all the files in the current directory:

find . -type f -printf '%T@\n' | sort -n | awk 'NR==1 { first = $1 } END{ print ($1-first)/(NR-1) }'

The results are decimal numbers in seconds, but you can easily just write int(($1-first)/(NR-1)) for an integer or int(($1-first)/(NR-1))/60 for minutes.

2 added 1174 characters in body
source | link

If you know times are not much over one hour, you can simply add 60 if the result is negative. However, therethis is not the way to do it anyway. There are several points I'd like to raise:

  1. NEVER parse output of ls, especially not the time part. It depends on the locale will give completely unpredictable results.
  2. Why assume times are around a hour and just like at the minutes, if you can just subtract dates? Use the unix timestamp - the number of second since the beginning of the world (1970). That's the standard way of storing time.
  3. Just write let i++ and let l=j-k, don't use millions of parentheses
  4. You are making $l an array of length 1, and then access $i th member. This is why it only works for the first pair.
  5. You are using very c-like programming style. Use a loop of the form for i in "${MMarray[@]}"; do... and just save the previous one.
  6. Why assume times are around a hour and just like at the minutes, if you can just subtract dates? 
  7. You are using too much arrays and loops, do everything in a stream of dates, it will be much better. So pretty much everything can be rewritten.
  8. You do realize, that an average time is simply first minus last divided by the number of files minus 1 (the number of diffences)? You don't need to subtract and then add together again...

I'll write up a proper solution for thisWhat to do if you want to get all the time differences in a few minutesseconds, one per line:

find /some/location -type f -name '*your filter which files you want*' -printf '%T@\n' | sort -n | awk 'NR>1 { print  $1-previous } {previous = $1}'

What it does? find finds the files and prints the unix timestamps. If you don't specify -name it lists eveything. -type f means only files, no directories. sort -n sorts the times numerically. stay tunedawk simply computes and prints differences.

For average, just keep the first and the last date. For instance, for all the files in the current directory:

find . -type f -printf '%T@\n' | sort -n | awk 'NR==1 { first = $1 } END{ print ($1-first)/(NR-1) }'

The results are decimal numbers in seconds, but you can easily just write int(($1-first)/(NR-1)) for an integer or int(($1-first)/(NR-1))/60 for minutes.

If you know times are not much over one hour, you can simply add 60 if the result is negative. However, there are several points I'd like to raise:

  1. NEVER parse output of ls, especially not the time part. It depends on the locale will give completely unpredictable results.
  2. Just write let i++ and let l=j-k
  3. You are using very c-like programming style. Use a loop of the form for i in "${MMarray[@]}"; do... and just save the previous one.
  4. Why assume times are around a hour and just like at the minutes, if you can just subtract dates?
  5. You are using too much arrays, do everything in a stream of dates, it will be much better.

I'll write up a proper solution for this in a few minutes... stay tuned.

If you know times are not much over one hour, you can simply add 60 if the result is negative. However, this is not the way to do it anyway. There are several points I'd like to raise:

  1. NEVER parse output of ls, especially not the time part. It depends on the locale will give completely unpredictable results.
  2. Why assume times are around a hour and just like at the minutes, if you can just subtract dates? Use the unix timestamp - the number of second since the beginning of the world (1970). That's the standard way of storing time.
  3. Just write let i++ and let l=j-k, don't use millions of parentheses
  4. You are making $l an array of length 1, and then access $i th member. This is why it only works for the first pair.
  5. You are using very c-like programming style. Use a loop of the form for i in "${MMarray[@]}"; do... and just save the previous one. 
  6. You are using too much arrays and loops, do everything in a stream of dates, it will be much better. So pretty much everything can be rewritten.
  7. You do realize, that an average time is simply first minus last divided by the number of files minus 1 (the number of diffences)? You don't need to subtract and then add together again...

What to do if you want to get all the time differences in seconds, one per line:

find /some/location -type f -name '*your filter which files you want*' -printf '%T@\n' | sort -n | awk 'NR>1 { print  $1-previous } {previous = $1}'

What it does? find finds the files and prints the unix timestamps. If you don't specify -name it lists eveything. -type f means only files, no directories. sort -n sorts the times numerically. awk simply computes and prints differences.

For average, just keep the first and the last date. For instance, for all the files in the current directory:

find . -type f -printf '%T@\n' | sort -n | awk 'NR==1 { first = $1 } END{ print ($1-first)/(NR-1) }'

The results are decimal numbers in seconds, but you can easily just write int(($1-first)/(NR-1)) for an integer or int(($1-first)/(NR-1))/60 for minutes.

1
source | link

If you know times are not much over one hour, you can simply add 60 if the result is negative. However, there are several points I'd like to raise:

  1. NEVER parse output of ls, especially not the time part. It depends on the locale will give completely unpredictable results.
  2. Just write let i++ and let l=j-k
  3. You are using very c-like programming style. Use a loop of the form for i in "${MMarray[@]}"; do... and just save the previous one.
  4. Why assume times are around a hour and just like at the minutes, if you can just subtract dates?
  5. You are using too much arrays, do everything in a stream of dates, it will be much better.

I'll write up a proper solution for this in a few minutes... stay tuned.