Bash: Display Current Date

by on December 6, 2009 · 0 comments· LAST UPDATED December 6, 2010

in

How do I display the current date under Bash UNIX / Linux / OS X shell?

Use the date command to dispkay or set system date and time. Invoking date command with no FORMAT argument is equivalent to invoking it with a default format that depends on the LC_TIME locale category. Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following command:
$ date
Sample outputs:

Tue Dec  7 03:08:34 IST 2010

To display the date of the day before yesterday, enter:
$ date --date='2 days ago'
To display the date of the day three months and one day, enter:
$ date --date='3 months 1 day'
To display the current full month name and the day of the month:
$ date '+%B %d'
Anytime you need assistance with date command, turn to the man or info pages first. They give you detailed information, parameters and switches for date command. Just type man followed by the name of the command (i.e. date) to open the appropriate man page. For example, man date opens the man page for the date command:
$ man date
OR (may not work on OS X and other UNIX like systems)
$ info date

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: