📄 ch06_06.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 6] 6.6 The TZ Environment Variable </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-10-23T15:38:04Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch06_01.htm"TITLE="6. Shell and Environment Variables"><LINKREL="prev"HREF="ch06_05.htm"TITLE="6.5 PATH and path "><LINKREL="next"HREF="ch06_07.htm"TITLE="6.7 What Time Is It in Japan? "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch06_05.htm"TITLE="6.5 PATH and path "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 6.5 PATH and path "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 6<BR>Shell and Environment Variables</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch06_07.htm"TITLE="6.7 What Time Is It in Japan? "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 6.7 What Time Is It in Japan? "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1173">6.6 The TZ Environment Variable </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-1173-IX-TZ-ENVIRONMENT-VARIABLE"></A><ACLASS="indexterm"NAME="UPT-ART-1173-IX-TIMEZONES-TZ-VARIABLE-FOR"></A>The <EMCLASS="emphasis">TZ</EM> environment variable is a little obscure, but it can be veryuseful. It tells UNIX what time zone you're in. The default timezone was set when your system was first installed (and we'll assumeit was done correctly).However, there are lots of times when you wantto change your time zone temporarily. For example, you might beconnected via a communications program to a UNIX system in another time zone; its notion of thecorrect time is right for its location, but not for your location.Or you may move your system to another location; you need to changethe time zone, but you don't want to reinstall the software (which canbe painful).Article<ACLASS="xref"HREF="ch06_07.htm"TITLE="What Time Is It in Japan? ">6.7</A>shows how to use <EMCLASS="emphasis">TZ</EM> to check the time in another zone.</P><PCLASS="para">To set <EMCLASS="emphasis">TZ</EM>, give a command like:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>setenv TZ </B></CODE><CODECLASS="replaceable"><I>timezone</I></CODE> <EMCLASS="emphasis">C shell</EM>$ <CODECLASS="userinput"><B>TZ=</B></CODE><CODECLASS="replaceable"><I>timezone</I></CODE><CODECLASS="userinput"><B>; export TZ</B></CODE> <EMCLASS="emphasis">Bourne shell</EM></PRE></BLOCKQUOTE></P><PCLASS="para">This setting takes effect immediately; if you give the<SPANCLASS="link"><EMCLASS="emphasis">date</EM> (<ACLASS="linkend"HREF="ch51_10.htm"TITLE="The date Command ">51.10</A>)</SPAN>command, you'll see the current time in your new zone.</P><PCLASS="para">The time zones are, basically, files in the directory<EMCLASS="emphasis">/usr/lib/zoneinfo</EM> or its subdirectories. You'll have to lookthrough there to see what's available - but a lot is available,including all the time zones in the United States, Canada, Australia, most ofEurope, 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 reasonsthat are completely unclear to me.</P><PCLASS="para">So, let's say you want to set the current time so that it's correct inWyoming. You look in <EMCLASS="emphasis">/usr/lib/zoneinfo</EM> and see a directory named<EMCLASS="emphasis">US</EM>. You then look in the <EMCLASS="emphasis">US</EM> directory, and see a file named <EMCLASS="emphasis">Mountain</EM>.Soyour time zone setting is <EMCLASS="emphasis">US/Mountain</EM>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>setenv TZ US/Mountain</B></CODE>% <CODECLASS="userinput"><B>date</B></CODE>Wed Mar 6 19:34:53 MST 1996</PRE></BLOCKQUOTE></P><PCLASS="para">You don't have to worry about the difference between daylight andstandard time, or the fact that Daylight Savings Time rules aren'tthe same everywhere. That information is all encoded in the<EMCLASS="emphasis">zonefiles</EM> database.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch06_05.htm"TITLE="6.5 PATH and path "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 6.5 PATH and path "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch06_07.htm"TITLE="6.7 What Time Is It in Japan? "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 6.7 What Time Is It in Japan? "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">6.5 PATH and path </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">6.7 What Time Is It in Japan? </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -