music |
| | OSdata.com |
date
summary
This subchapter looks at date, a UNIX (and Linux) command.
date is used to set or view the system date and time.
date
This subchapter looks at date, a UNIX (and Linux) command.
date is used to set or view the system date and time.
$ date
Mon Sep 3 00:56:17 PDT 2012
$
The format for the output is: day of the week, month, day of the month, 24 hour time, time zone, year.
formatted output
Display the time and/or date with formatting by including formatting options (which can be used to set variables to a specific format).
$ date '+DATE: %m/%d/%y%nTIME: %H:%M:%S'
DATE: 11/23/13
TIME: 22:12:19
$
Setting a variable with the current date:
$ NOW=$(date +"%m/%d/%Y")
$ echo $NOW
11/23/2013
$
Format specifiers (format string starts with +)
Specifier |
Description |
Values or example |
Day |
%a |
weekday, abbreviated |
Sun |
%A |
weekday, full |
Sunday |
%d |
day of the month, two digits, zero filled |
08 |
%e |
day of the month |
8 |
%j |
day of year, zero filled |
001Ð366 |
%u |
day of week from Monday to Sunday |
1Ð7 |
%w |
day of week from Sunday to Saturday |
0Ð6 |
Week |
%U |
week number, Sunday as first day of week |
00Ð53 |
%W |
week number, Monday as first day of week |
00Ð53 |
%V |
ISO standard week of the year |
01Ð53 |
Month |
%m |
two-digit month number |
01Ð12 |
%h |
month name, abbreviated |
Nov |
%b |
month name, localised abbreviation |
Nov |
%B |
locale's full month, variable length |
November |
Year |
%y |
two-digit year |
00Ð99 |
%Y |
four-digit year |
2013 |
%g |
two-digit year corresponding to the %V week number |
|
%G |
four-digit year corresponding to the %V week number |
|
Century |
%C |
two century digits from year |
00Ð99 |
Date |
%D |
mm/dd/yy |
11/24/13 |
%x |
locale's date representation |
11/24/2013 |
%F |
%Y-%m-%d |
2013-11-24 |
Hours |
%l |
hour (12 hour) |
4 |
%I |
hour (12 hour), zero-filled |
04 |
%k |
hour (24 hour) |
4 |
%H |
hour (24 hour), zero-padded |
04 |
%p |
locale's upper case AM or PM (blank in many locales) |
AM |
%P |
locale's lower case am or pm |
am |
Minutes |
%M |
two-digit minute number |
05 |
Seconds |
%s |
seconds since 00:00:00 1970-01-01 UTC (Unix epoch) |
1385265929 |
%S |
two-digit second number |
00Ð60 (Includes 60 to accommodate a leap second) |
%N |
nanoseconds |
000000000Ð999999999 |
Time |
%r |
hours, minutes, seconds (12-hour clock) |
04:05:29 AM |
%R |
hours, minutes (24 hour clock) |
04:05 |
%T |
hours, minutes, seconds (24-hour clock) |
04:05:29 |
%X |
locale's time representation |
11:07:26 AM |
Date and time |
%c |
locale's date and time |
Sat Nov 04 12:02:33 EST 1989 |
Time zone |
%z |
RFC-822 style numeric time zone |
-0500 |
%Z |
time zone name; nothing if no time zone is determinable |
EST, EDT |
literals: %n newline %% percent %t horizontal tab
By default, date normally fills numeric fields with zeroes. GNU date, but not BSD date, recognizes a modifier between the per cent sign (%) and the format specifier:
- hyphen (-): do not fill the field
- underscore (_): pad the field with spaces
TZ Specifies the time zone, unless overridden by command line parameters. If neither is specified, the setting from /etc/localtime is used.
setting time and date
Only the root or superuser an set the system date and time. In Mac OS X, you can use the clock system preferences t set the time and date. In Ubuntu-based Linux, you can click on the clock and select Time and Date settings from the menu or click on the System menu, select Adminsitration, select Time and Date.
Set the time to noon:
$ date 1200
$
Set the time to 3:30:30 a.m.:
$ date 0330.30
$
Set the date to October 31st (Halloween) at 3:30 a.m.:
$ date 10310330
$
other
On November 8, 2010, Ramesh Natarajan named this the number 49 most frequently used UNIX/Linux command at this web page 50 Most Frequently Used UNIX / Linux Commands (With Examples).
comments, suggestions, corrections, criticisms
free music player coding example
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
Names and logos of various OSs are trademarks of their respective owners.