All UNIX systems come with a program called date
It shows you the time from the
system clock (51.2
(So, the time is only as accurate as your system's clock.)
Fri Dec 13 08:06:39 PST 1996
||If you need parts of that date, you can split the line into pieces.
There are examples in articles
Most newer versions of date
(including the one on the Power Tools
disc) will also let you set the format of the date.
To do that, type a single argument that starts with a plus (
and has format specification characters in it.
Check your online manual page for a list of format specification
The argument has to be all one word, so you'll usually need to put
Here's a simple example:
date +'Today is %d %h 19%y.'
Today is 13 Dec 1996.
You'll usually use this in a shell script or
can mix any other text with the dates it outputs,
you can do some surprising and useful things.
Greg Ubben uses it to construct arithmetic
expressions for performing calculations on dates.
For example, since
isn't available on all systems,
the following computes the week number of the year
(Sunday as the first day) and makes it available in the Bourne shell
weekno=`expr \`date +"%j / 7 + ( ( %w + 6 ) %% 7 < %j %% 7 )"\``
For some other "real-life" examples, see articles