home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 6.5 PATH and path Chapter 6
Shell and Environment Variables
Next: 6.7 What Time Is It in Japan?

6.6 The TZ Environment Variable

The TZ environment variable is a little obscure, but it can be very useful. It tells UNIX what time zone you're in. The default time zone was set when your system was first installed (and we'll assume it was done correctly). However, there are lots of times when you want to change your time zone temporarily. For example, you might be connected via a communications program to a UNIX system in another time zone; its notion of the correct time is right for its location, but not for your location. Or you may move your system to another location; you need to change the time zone, but you don't want to reinstall the software (which can be painful). Article 6.7 shows how to use TZ to check the time in another zone.

To set TZ , give a command like:

% setenv TZ 


                      C shell

$ TZ=


; export TZ

                  Bourne shell

This setting takes effect immediately; if you give the date (51.10 ) command, you'll see the current time in your new zone.

The time zones are, basically, files in the directory /usr/lib/zoneinfo or its subdirectories. You'll have to look through there to see what's available - but a lot is available, including all the time zones in the United States, Canada, Australia, most of Europe, and a lot of Asia, Africa, and South America. A lot of "oddball" time zones are included: for example, the state of Indiana, large parts of which don't observe Daylight Savings Time, and Michigan, for reasons that are completely unclear to me.

So, let's say you want to set the current time so that it's correct in Wyoming. You look in /usr/lib/zoneinfo and see a directory named US . You then look in the US directory, and see a file named Mountain . So your time zone setting is US/Mountain :

% setenv TZ US/Mountain

% date

Wed Mar  6 19:34:53 MST 1996

You don't have to worry about the difference between daylight and standard time, or the fact that Daylight Savings Time rules aren't the same everywhere. That information is all encoded in the zonefiles database.

- ML

Previous: 6.5 PATH and path UNIX Power Tools Next: 6.7 What Time Is It in Japan?
6.5 PATH and path Book Index 6.7 What Time Is It in Japan?

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System