0

I was in the process of getting the time zone details from the some of the machine in the infrastructure.

And some machines have timedatectl and getting the required details seems to be quite easy from this.

$/etc/bin/timedatectl | /bin/grep "Timezone"
  Timezone: America/Los_Angeles (PST, -8000)

But I was looking for alternative was to get the time zone details in the machines which does not have timedatectl command in them.

And ended up checking the /etc/locatime file and since this is a binary file. Hence finding some hard time in getting the required details.

ramp
  • 741

3 Answers3

3
date +%Z

That will give you the time zone. eg GMT,PST...etc

The date command by itself also includes this information.

see man date for more information.

alpha
  • 1,994
1

Since /etc/localtime is usually* a symlink to a file in /usr/share/zoneinfo/, you should be able to issue ls -l /etc/localtime to get the timezone info you need on any linux based machine.

*) unless /usr is on a separate drive/partition, then it's a file, making this method less-than-useful. ^_^;

Mio Rin
  • 3,040
  • 1
    If your setup has /usr as a separate filesystem, then /etc/localtime probably won't be a symlink but an actual copy of the appropriate timezone file from /usr/share/zoneinfo, as it should be available also during early boot when /usr might not be mounted yet. – telcoM Feb 14 '18 at 21:02
  • I was not aware of that. None of my systems have /usr on a separate partition. Thanks for adding that tidbit. :) – Mio Rin Feb 14 '18 at 21:07
1

You can use the following commands:

cat /etc/timezone

Sample output:

Africa/Tunis

Then:

zdump Africa/Tunis

Sample output:

Africa/Tunis  Wed Feb 14 21:09:03 2018 CET
GAD3R
  • 66,769