38

What command(s) can I use to examine the contents of the timezone files, such as /etc/localtime or the files under /usr/share/zoneinfo/*?

Evgeny
  • 5,476
slm
  • 369,824

3 Answers3

46

The most appropriate command would appear to be zdump.

$ zdump /etc/localtime 
/etc/localtime  Wed Aug  7 23:52:25 2013 EDT

$ zdump /usr/share/zoneinfo/* | tail -10
/usr/share/zoneinfo/Singapore    Thu Aug  8 11:52:48 2013 SGT
/usr/share/zoneinfo/Turkey       Thu Aug  8 06:52:48 2013 EEST
/usr/share/zoneinfo/UCT          Thu Aug  8 03:52:48 2013 UCT
/usr/share/zoneinfo/Universal    Thu Aug  8 03:52:48 2013 UTC
/usr/share/zoneinfo/US           Thu Aug  8 03:52:48 2013
/usr/share/zoneinfo/UTC          Thu Aug  8 03:52:48 2013 UTC
/usr/share/zoneinfo/WET          Thu Aug  8 04:52:48 2013 WEST
/usr/share/zoneinfo/W-SU         Thu Aug  8 07:52:48 2013 MSK
/usr/share/zoneinfo/zone.tab     Thu Aug  8 03:52:48 2013
/usr/share/zoneinfo/Zulu         Thu Aug  8 03:52:48 2013 UTC

You can also interrogate these files using the file command:

$ file /etc/localtime 
/etc/localtime: timezone data, version 2, 4 gmt time flags, 4 std time flags, no leap seconds, 235 transition times, 4 abbreviation chars

$ file /usr/share/zoneinfo/Singapore
/usr/share/zoneinfo/Singapore: timezone data, version 2, 8 gmt time flags, 8 std time flags, no leap seconds, 8 transition times, 8 abbreviation chars
slm
  • 369,824
  • 2
    To extract maximum detail, - Give -v option to zdump(8). - If focusing on a particular city, be sure to prepend the country-or-continent prefix (or just give the TZ file's absolute path). Singapore, which is both a country and a city, is a special case: zdump -v Singapore and zdump -v Asia/Singapore print same result. But you will get far less information from zdump -v Berlin than from zdump -v Europe/Berlin, for example. – Vainstein K Dec 19 '20 at 02:00
1
### For OpenWrt only ### Fixes /etc/TZ and /etc/localtime

curl -so - https://who.is/whois-ip/ip-address/`curl -s ifconfig.me`|\
    egrep 'Country:|City:'

IAMIN=Europe/Amsterdam
tail -1 /usr/share/zoneinfo/$IAMIN | tee /tmp/TZ
ln -s /usr/share/zoneinfo/$IAMIN /tmp/localtime
cinober
  • 11
  • 3
    Welcome to the site, and thank you for your contribution. Please consider adding some explanation to your post. For example, on most recent Unix/Linux systems the files in zoneinfo are binary, so the tail command will not yield readable output. Also, please explain what the ln command is supposed to do in respect to the OPs question of "how to examine the contents". – AdminBee Feb 24 '21 at 11:05
  • @AdminBee I think the ln command is supposed to relink the timezone, but the file was accidentally linked to /tmp, not /etc. – Amint Feb 27 '21 at 23:45
  • @AdminBee I know zoneinfo files are binary, but it just happens to be that they end in normal text line. As stackexchanger sugested "strings /etc/localtime | tail -1" also works. Non-related... To minimize the intrusion into default OpenWrt setup, linked files are in /tmp as OpenWrt have default links from /etc to /tmp. The goal was to correct the localtime-zone as terminal "uci set ..." setup of timezone did not do the work. Lately I found out that confirming the "uci set ..." setup in web-luci seemingly eliminates the problem, by adding some "default" settings; not sure, just seems like. – cinober May 15 '21 at 06:00
0

Try tzdump. I found it here: http://www.cise.ufl.edu/~seeger/dist/tzdump.c It is a C program and so will need to be compiled.