2 Replies Latest reply: Mar 11, 2013 10:46 PM by 956800 RSS

    Display current nanosecond

    984266
      Hi,

      I need to write a script to write a current nanosecond time stamp to a file
      The time stamp should looks like ls -lE output.

      I have try the man page for date, it seems that there are no options for displaying nanosecond

      And I have try the following method, it also doesn't seems the same as ls -lE
      =============================

      root@newUAT> /usr/sfw/bin/gcc /tmp/time_ms.c -o /var/tmp/time_ms
      root@newUAT> date +%H:%M:%S.`/var/tmp/time_ms|cut -d . -f2`
      15:36:07.366
      root@newUAT> cat /tmp/time_ms.c
      #include <sys/time.h>
      main()
      {
      struct timeval tv;
      gettimeofday(&tv,(void*)0);
      printf("%d.%d\n",tv.tv_sec,tv.tv_usec/1000);
      }
      root@newUAT> date +%H:%M:%S.`perl -e 'print time()*1000;print "\n";'`
      15:36:38.1360136198000
      root@newUAT>
        • 1. Re: Display current nanosecond
          Bjoern Rost
          I have a suggestion for a workaround. If you need the "current" timestamp in the format of, ls -iE, you could "touch" a file and read the ls -iE output and cut out the timestamp from there?
          -bash-3.2$ touch /tmp/time
          -bash-3.2$ ls -iE /tmp/time
          4204467824 -rw-r--r--   1 brost    portrix        0 2013-02-06 10:27:20.369465998 +0100 /tmp/time
          Bjoern
          • 2. Re: Display current nanosecond
            956800
            Hi,

            Touch a file first and using ls -lE get its nanosecond details. Sample as given below:

            touch <filename>
            ls -lE <filename> | awk '{print $7}' | cut -d'.' -f2

            Regards,
            Vinay K