1

I have a Linux (bash) script to generate a login message (motd). One of the things it displays is the timezone, using the command timedatectl | grep Time | awk {'print $3'}. The command returns something like America/Chicago which is the format I am seeking.

Naturally, since there is no timedatectl under FreeBSD, this command does not work and I am seeking an alternative.

The closest I have managed is using date +'%z %Z', but that is still quite different.

Is there a way to display the system's timezone in Continent/Region format under FreeBSD?

Thanks!

6
  • 2
    Does the file /var/db/zoneinfo exist on the system? Apr 26, 2022 at 11:33
  • No, it does not. I've also sought out /etc/timezone which is also missing
    – PGEL
    Apr 26, 2022 at 11:35
  • 1
    Does /etc/localtime exist? Apr 26, 2022 at 11:42
  • It does, but it is a binary file
    – PGEL
    Apr 26, 2022 at 11:45
  • 2
    cd /usr/share/zoneinfo && find . -type f -exec cmp -s /etc/localtime '{}' \; -print | sed -e 's|^\./||' -e '/posix/d' Apr 26, 2022 at 11:50

1 Answer 1

2

This command will provide what you are looking for:

cd /usr/share/zoneinfo && find . -type f -exec cmp -s /etc/localtime '{}' \; -print | sed -e 's|^\./||' -e '/posix/d'

Output (I'm in the US on the East Coast):

America/New_York

1
  • Good stuff, +1. A slight edit to get rid of the possibly annoying cd component: find /usr/share/zoneinfo -type f -exec cmp -s /etc/localtime '{}' \; -print | sed -e 's|^/usr/share/zoneinfo/||' -e '/posix/d'
    – Jim L.
    Apr 26, 2022 at 19:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .