Linux Date Command

by — Sandeep Kumar Patel

Date command in Linux-

date command is used to display the system date and time. date command is also used to set date and time of the system. By default the date command displays the date in the time zone on which unix/linux operating system is configured.You must be the super-user (root) to change the date and time.

Syntax:

date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

Options with Examples
1: date (no option) : With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the time zone name, and the year.

Command: 
$date
Output:
Tue Oct 10 22:55:01 PDT 2017

Note : Here unix system is configured in pacific daylight time.

2:-u Option: Displays the time in GMT(Greenwich Mean Time)/UTC(Coordinated Universal Time )time zone.

Command: 
$date -u
Output :
Wed Oct 11 06:11:31 UTC 2017

3: –date or -d Option: Displays the given date string in the format of date. But this will not affect the system’s actual date and time value.Rather it uses the date and time given in the form of string.
Syntax:

$date --date=" string "Command: 
$date --date="2/02/2010"
$date --date="Feb 2 2010"
Output:
Tue Feb 2 00:00:00 PST 2010
Tue Feb 2 00:00:00 PST 2010

4:Using –date option for displaying future date:

  • Date and time of upcoming particular week day.
Command: 
$date --date="next tue"
Output:
Tue Oct 17 00:00:00 PDT 2017

5:–file or -f Option: This is used to display the date string present at each line of file in the date and time format.This option is similar to –date option but the only difference is that in –date we can only give one date string but in a file we can give multiple date strings at each line.
Syntax:

$date --file=file.txt

Thank You For you Time …!!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sandeep Kumar Patel

Sandeep Kumar Patel

58 Followers

Enthusiastic, aspirant in artificial intelligence, machine learning Research is formalized curiosity. It is poking and prying with a purpose.