In today's post, We will see how can configure time and date in Linux system. There are basically two types of clock presents in all modern systems. (i) Real-Time Clock means hardware based clock e.g CMOS which is working even your system is shutdown/ power off (ii) System Software Clock means software based clock which is managed by kernel itself. kernel fetch its initial value from the RTC(real time clock) It only works when the system is turn on. Basically we have an inbuilt package utility name 'date' which we use to display date & time and manage it.
To manage time and date in Linux , we have two utilities available (i) date which is available in all old and new Unix-Like system (ii) timedatectl utility is available in modern Linux OS and it is a part systemd system and service manager. In this post we will use both these utilities to display , manage , modify system date and time in Linux. lets start...
'timedatectl' commands in Linux
timedatectl : This command will display the current time and date along with detailed information.
timedatectl set-time YYYY-MM-DD : Set the current date in your Linux system.
Where YYYY = Year , MM = Month, DD = Date .
timedatectl set-time HH:MM:SS : Set the current time in your Linux system.
Where HH = Hours, MM = Minute, SS = Seconds
timedatectl set-local-rtc boolean : To maintain your system clock in local time. By default it is set to UTC
Where boolean = yes / no
Please read the warning message in the last of the above pic.
timedatectl list-timezones : To list the all available time-zones .
timedatectl set-timezone zone : To set the time zone for your system.
where zone = your time zone name
timedatectl set-ntp boolean_value : To enable sync the time with NTP server.
where boolean = yes / no
'date' Commands in Redhat Linux
date : This command simply show the current time and date.
date --utc : By default 'date' command show the local time. To check universal time coordinator use
--utc option along with 'date' command
date +"format" : This is the universal way to show the date in desire format.
replace "format" with desire date format.
All available formats are below :
Examples
date +"%Y-%m-%d %H:%M" : Shows the current date and time in given format .
date +%F -s YYYY-MM-DD : To set the date according to given format.
Where YYYY-MM-DD is the actual date which you want to set in system. %F = Full , -s = set
date +%T --set HH:MM:SS : To set the time in system as given format. If you want to set the clock
UTC add --utc option.
Where HH:MM:SS is actual time and --set to set the time in system , --utc to set clock to UTC.
Please share the post with your friends 😀
0 Comments