Linux Date Command: Convert Named Stats Dump Date

The rndc stats commands created /var/named/chroot/var/named/data/named_stats.txt file under RHEL 5.x or CentOS 5.x BIND 9 server. However, date is not is correct format. The date is in the following format:
grep ‘Dump’ /var/named/chroot/var/named/data/named_stats.txt

+++ Statistics Dump +++ (1263408025)
— Statistics Dump — (1263408025)
+++ Statistics Dump +++ (1263408071)
— Statistics Dump — (1263408071)
+++ Statistics Dump +++ (1268304218)
— Statistics Dump — (1268304218)
+++ Statistics Dump +++ (1268304248)
— Statistics Dump — (1268304248)

How do I convert date (e.g., 1263408025) in a human readable format?

The number 1263408025 is seconds since 1970-01-01 and can be converted to a human readable format using the following simple date command:
$ date -d '1970-01-01 1263408025 sec'
Sample outputs:
Wed Jan 13 18:40:25 CST 2010
Your named stats was dumped on Jan/13/2010 at 18:40:25 local time.

More About UNIX Time

Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds. See wikipedia article for more information or refer to man page:
$ man date
$ info coreutils date

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Marc Mar 11, 2010 @ 12:04

    Also possible in Perl :

    perl -e ‘print(scalar(localtime(1263408025)));’

  • unix Mar 11, 2010 @ 13:24

    date -d ‘1970-01-01 1263408025 sec’
    is the same as
    date -d @1263408025

  • Nerdoug Mar 11, 2010 @ 14:23

    general Unix Timestamp conversion:

    A) in bulk, in Excel:
    Step 1: Put the timestamp in cell a1.
    Step 2: In cell a2, enter “=a1/86400+25569”. Don’t enter the double quotes.
    Step 3: Apply a new format to this cell by right-clicking on the mouse and choosing “Format cells” -> “Numbers” -> “Custom”.
    Step 4: In the “Type” field, enter “dd:mmm:yyyy hh:mm”.

    You can build a timezone adjustment into the formula. To generate Eastern Daylight time, which is a 4 hour offset, use the formula
    Using Excel is the most convenient method if you have a number of timestamps to interpret, especially if you can easily paste them into a spreadsheet and apply the formula to them all at once.

    B) in awk, using strftime

    for example, to make squid logs more readable:
    awk ‘{print strftime(“%y%m%d %H:%M:%S “,$1)” “substr($0,17,999)}’ squidlog > nicer

    This format makes it easier to extract stats for a given day, or hour.

  • Krieg Mar 11, 2010 @ 19:48

    Excelente maestro.

    Y sencillito…
    … y sin ser argentino.

  • Florin Mar 11, 2010 @ 20:32

    You can also do something like:

    while read line; do
      nix=`echo $line | awk '{print substr($5,2,10)}'`
      see=`date -d '1970-01-01 '$nix' sec'`
      echo "${line%(*}($see)" >> toto2
    done < toto

    To have the log file with the readable date.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum