Bash: Display Current Date

Posted on in Categories last updated December 6, 2010

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment