UNIX Date Command Examples

https:‮www//‬.lautturi.com
UNIX Date Command Examples

The date command is a useful tool for displaying and formatting the current date and time in Unix. Here are a few examples of how you can use the date command:

  • To display the current date and time in the default format, you can simply run the date command without any options:
date

This will output the current date and time in the format Wed Dec 22 16:40:53 EST 2021.

  • To display the current date and time in a different format, you can use the + option to specify a custom format string. For example, to display the date and time in the format YYYY-MM-DD HH:MM:SS, you can use the following command:
date +%Y-%m-%d %H:%M:%S

This will output the current date and time in the format 2021-12-22 16:40:53.

  • To set the system clock to a specific date and time, you can use the -s option followed by the date and time in the format YYYY-MM-DD HH:MM:SS. For example, to set the system clock to January 1, 2022 at 12:00:00, you can use the following command:
date -s "2022-01-01 12:00:00"

This will set the system clock to the specified date and time.

Overall, the date command is a simple and convenient tool for displaying and formatting the current date and time in Unix. It has many other options and features that allow you to customize its behavior and output.

Created Time:2017-10-30 14:27:22  Author:lautturi