Linux/Time

From Omnia
(Redirected from Linux/Time Zone)
Jump to navigation Jump to search

Time Zones

See current timezone setting:

sudo zdump /etc/localtime   # /etc/localtime  Wed Mar 14 09:46:46 2012 MDT
strings /etc/localtime      # MST7MDT,M3.2.0,M11.1.0  (and other garbage)

Set timezone for all users:

mv /etc/localtime /etc/localtime.original
# cp /usr/share/zoneinfo/America/Boise /etc/localtime
ln -sfn /usr/share/zoneinfo/America/Denver /etc/localtime
ln -sfn /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

Set time zone for current user:

export TZ=America/Denver


In Linux, most timezone information is controlled by GLIBC, which relies on the file /etc/localtime. Different distributions do different things with this file; some have it as a symbolic link to the proper timezone definition file (usually in /usr/share/zoneinfo), but most have it as an actual, explicit file.

Verifying the Timezone File [1]

zdump is a small program that is part of GLIBC. It dumps the information about a given timezone file. If you want to verify what the Daylight Savings times are for a given year with a given file, you can do something like this:

$ zdump -v /etc/localtime | grep 2007

The -v tells zdump to display timezone information for all transitions rather than just the current date.

date:

date
  Sun May  2 15:49:55 MDT 2010

Time Zone:

ENVIRONMENT
  TZ  Specifies the timezone, unless overridden by command line parameters.
      If neither is specified, the setting from /etc/localtime is used.

Time zones are kept here:

/usr/share/zoneinfo/

NTP

See NTP

File Time

Files have access, modify and change times.

  • access time (atime): time the file was last accessed
  • modify time (mtime): file modification times
  • change time (ctime): status change times
$ stat test/
  File: `test/'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 900h/2304d      Inode: 20987905    Links: 2
Access: (0700/drwx------)  Uid: ( 1068/ kenneth)   Gid: ( 1068/ kenneth)
Access: 2010-09-20 11:30:01.000000000 -0600
Modify: 2010-09-20 11:14:45.000000000 -0600
Change: 2010-09-20 11:14:45.000000000 -0600

List file times:

$ ls -lt
$ ls -ltr  # reverse

Modifiers:

-t mtime - modification time
-u atime - access time
-c ctime - change time

America Time Zones

# cat /etc/timezone
Etc/UTC
Universal
UTC
Zulu
Etc/UTC

US/Central
America/Chicago

US/Eastern
America/New_York

US/Hawaii
Pacific/Honolulu

US/Mountain
America/Denver

US/Pacific
America/Los_Angeles

https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

# date
Sat 16 Feb 15:46:56 UTC 2019

# TZ=America/Denver date
Sat 16 Feb 08:47:01 MST 2019

keywords

Linux date time timezone