Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am not sure if I understood the way find ignores the fractional part when using one of these predicates to find. For e.g. I used

$ find . -ctime .2 # files status changed exactly 4.8 hours ago ? 
$ find . -ctime +.2 # files status changed more than 4.8 hours ago ?
$ find . -ctime -.2 # files status changed less than 4.8 hours ago ?

And always got a different output. How is the computation of hours being done here ?

share|improve this question

migrated from May 18 '11 at 15:13

This question came from our site for professional and enthusiast programmers.

Not really a programming question. –  Konerak May 18 '11 at 15:07

1 Answer 1

up vote 1 down vote accepted

You may be better served by the -cmin and -mmin predicates

Yes it will do the interpolation sub-day and sub-hour:

parser.c, line 3243

/* Get a timestamp and comparison type.

   STR is the ASCII representation.
   Set *NUM_DAYS to the number of days/minutes/whatever, taken as being
   relative to ORIGIN (usually the current moment or midnight).
   Thus the sense of the comparison type appears to be reversed.
   Set *COMP_TYPE to the kind of comparison that is requested.
   Issue OVERFLOWMESSAGE if overflow occurs.
   Return true if all okay, false if input error.

   Used by -atime, -ctime and -mtime (parsers) to
   get the appropriate information for a time predicate processor. */

static boolean
get_relative_timestamp (const char *str,
            struct time_val *result,
            struct timespec origin,
            double sec_per_unit,
            const char *overflowmessage)
  double offset, seconds, nanosec;
  static const long nanosec_per_sec = 1000000000;

  if (get_comp_type(&str, &result->kind))
      /* Invert the sense of the comparison */
      switch (result->kind)
    case COMP_LT: result->kind = COMP_GT; break;
    case COMP_GT: result->kind = COMP_LT; break;
    default: break;

      /* Convert the ASCII number into floating-point. */
      if (xstrtod(str, NULL, &offset, strtod))
      /* Separate the floating point number the user specified
       * (which is a number of days, or minutes, etc) into an
       * integral number of seconds (SECONDS) and a fraction (NANOSEC).
      nanosec = modf(offset * sec_per_unit, &seconds);
      nanosec *= 1.0e9; /* convert from fractional seconds to ns. */
      assert (nanosec < nanosec_per_sec);

      /* Perform the subtraction, and then check for overflow.
       * On systems where signed aritmetic overflow does not
       * wrap, this check may be unreliable.   The C standard
       * does not require this approach to work, but I am aware
       * of no platforms where it fails.
      result->ts.tv_sec  = origin.tv_sec - seconds;
      if ((origin.tv_sec < result->ts.tv_sec) != (seconds < 0))
          /* an overflow has occurred. */
          error (1, 0, overflowmessage, str);

      result->ts.tv_nsec = origin.tv_nsec - nanosec;
      if (origin.tv_nsec < nanosec)
          /* Perform a carry operation */
          result->ts.tv_nsec += nanosec_per_sec;
          result->ts.tv_sec  -= 1;
      return true;
      /* Conversion from ASCII to double failed. */
      return false;
      return false;

pred.c, line 237:

/* Returns ts1 - ts2 */
static double ts_difference(struct timespec ts1,
                struct timespec ts2)
  double d =  difftime(ts1.tv_sec, ts2.tv_sec)
    + (1.0e-9 * (ts1.tv_nsec - ts2.tv_nsec));
  return d;
share|improve this answer
"Not really a programming question," but we got a programming answer ..... –  Felipe Alvarez Feb 16 '12 at 3:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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