Linux date command
Linux date command displays or sets the system date and time.
Linux date – Display Date & Time
If you do not provide any arguments to the date command, system date and time is displayed.
$ date
The date is echoed in the terminal window as shown in the following screenshot.
Linux date – Set System Date & Time
Before you can set the date from command line, you have to make sure that Automatic Date & Time is turned off.
You can turn of the Automatic Date & Time from command line using timedatectl command. Run the following command for the same.
$ timedatectl set-ntp false
In the following screenshot, we have run the command and this should set the Date and Time to Manual.
If you are using Ubuntu, you can turn off Automatic Date & Time in Settings > Date & Time > Automatic Date & Time. Turn of the switch against Automatic Date & Time. It should appear as shown in the following screenshot.
Once you care sure that your Date & Time is set to Manual, you can set a required date and time for your system.
The syntax to set a specific Date and Time using date command is given below.
$ date -s "Date and Time String"
$ date --set="Date and Time String"
Let us set the date of our linux system to “30 DEC 2050 22:30:55”. Run the following command in terminal.
$ sudo date -s "30 DEC 2050 22:30:55"
We are running the date command as root or administrator. Following screenshot what happens when you run this date command. If asked for, please enter your password.
Once the command execution is complete, the current time is echoed to the screen. Also you should observe that the system is changed.
Conclusion
In this Linux Tutorial, we learned about Linux date command.