[Introduction to UNIX for Web Developers]
[Spacer] [Table of Contents]
[Next Page]
[Previous Page]
[Spacer]
Time and Date
Another set of useful tools are those that help you keep track of the time and date. There are two primary utilities that you will use for this purpose: date and cal.

The "date" utility simply displays the current time and date (according to the computer...recall that since you can login to a UNIX machine remotely, the date utility may not give you your local time if you are not in the same time zone as the computer you are logged in to). The "date" utility comes with several options that allow you to format the date displayed.

Options Description
MMDDhhmmYY This option may only be used by the superuser and gives you the ability to set the date. MM is the month (01-12). DD is the day (01-31). hh is the hour (00-23). mm is the minute (00-59) and YY is the year (00-99)
+%format This option specifies how the date is displayed. The valid formats include
a = weekday (represented as a name)
d = day of month (represented as a digit)
D = mm/dd/yy
h = month (represented as a name)
J = julian date
m = month (represented as a digit)
M = minute
n = newline
r = am/pm
S = second
t = tab
W = Day of week(represented as a digit)
y = last two digits in year

Check out the date utility in action

[Date]

The second time telling utility is the "Cal" utility that displays a calendar through standard output. The "cal" utility is fairly simple and takes only a month and a year as arguments. If no arguments are specified, it assumes the current month and year. If no month is specified, the utility will display all the months for the given year

Check out the following examples.

[Date]

[Spacer]
[Year with Cal]

Previous | Next | Table of Contents