Date Command in Unix and Linux Examples

  • Updated
  • Posted in Programming
  • 2 mins read


Date command is used to print the date and time in unix. By default the date command shows the date in the time zone that the unix working system is configured.

Now let see the date command utilization in unix

Date Command Examples:

1. Write a unix/linux date command to print the date on the terminal?

>date
Mon Jan 23 01:37:51 PST 2012

This is the default format in which the date command print the date and time. Here the unix server is configured in pacific customary time.

2. Write a unix/linux date command to print the date in GMT/UTC time zone?

>date -u
Mon Jan 23 09:40:21 UTC 2012

The -u choice to the date command tells it to show the time in Greenwich Mean Time.

3. Write a unix/linux date command to sett the date in unix?

You can change the date and time by utilizing the -s choice to the date command.

>date -s "01/01/2000 12:12:12"

4. Write a unix/linux date command to show solely the date half and ignore the time half?

>date '+%m-%d-%Y'
01-23-2012

You can format the output of date command by utilizing the %. Here %m for month, %d for day and %Y for yr.

5. Write a unix/linux date command to show solely the time half and ignore the date half?

>date '+%H-%M-%S'
01-48-45

Here %H is for hours in 24 hour format, %M is for minutes and %S for seconds

6. Write a unix/linux date command to format each the date and time half.

>date '+%m-%d-%Y %H-%M-%S'
01-23-2012 01-49-59

7. Write a unix/linux date command to search out the variety of seconds from unix epoch.

>date '+%s'
1327312228

Unix epoch is the date on January 1st, 1970. The %s choice is used to search out the variety of seconds between the present date and unix epoch.

Leave a Reply