Wednesday 15 January 2020

top 10 examples of date command in Linux

The date command in Linux is used to display and set the system date and time. It is a powerful tool that can display the date and time in various formats, set the system date and time, and perform simple date calculations. 

Here are 10 examples of how the date command can be used in Linux:

Display the current date and time:

date Output: Thu Mar 24 13:25:36 EDT 2022

Display the date and time in a specific format:

date +"%Y-%m-%d %H:%M:%S" Output: 2022-03-24 13:25:36

Display the date and time in UTC:

date -u Output: Thu Mar 24 17:25:36 UTC 2022


Display the day of the week:

date +"%A" Output: Thursday


Display the month in numeric form:

date +"%m" Output: 03


Display the year:

date +"%Y" Output: 2022


Set the system date and time:

sudo date --set "24 MAR 2022 13:30:00" This command will set the system date and time to March 24, 2022, at 1:30 PM.


Perform date calculations:

date -d "1 week ago" +"%Y-%m-%d" Output: 2022-03-17


Display the date and time in ISO 8601 format:

date --iso-8601=seconds Output: 2022-03-24T13:25:36-0400


Display the date and time in RFC 2822 format:

date --rfc-2822 Output: Thu, 24 Mar 2022 13:25:36 -0400


These are just a few examples of the many ways the date command can be used in Linux. By using different options and formatting strings, you can display and manipulate the date and time in a variety of ways.

Labels: , ,

0 Comments:

Post a Comment

Note: only a member of this blog may post a comment.

<< Home