Linux Date Command - (Tips)

Following examples described using CentOS


The date command is used to display the current date and time.it can also be used by the super user to set the system clock. An argument that begins with a plus sign (+) specifies a format string for the date command.

Print the current date and time

[root@CentOs ~]# date

Linux Date Command


Print the current time in 24-hour format

[root@CentOs ~]# date +%R

Linux date command in 24 hour format


Print the current time in 12-hour format

[root@CentOs ~]# date +%r

Linux date command 12 hour format


Print last modification time file of FILE

[root@CentOs ~]# date -r <FILE NAME>

in following example used the file called "Test.file"

[root@CentOs ~]# date -r Test.file

Linux date command file modify time


Change system date and time from command line

Change date only (Without date format)

[root@CentOs ~]# date -s "2018-08-19"

Linux Change date only (Without date format)

Change date only (With date format)

[root@CentOs ~]# date +%Y%m%d -s "20180825"

Change date only (With date format)

Remember if system date changed without providing time, system time will reset to 00:00:00


Change both date and time

[root@CentOs ~]# date -s "24 aug 2018 20:00:00"

Linux Change both date and time






Tech info

Comments