Queen Mobile Blog

4 lệnh Linux quản lý thời gian cực kỳ quan trọng

watchhereo

4 lệnh Linux quan trọng cho quản lý thời gian và tại sao điều đó quan trọng? Hãy biết cách quản lý thời gian trên hệ điều hành Linux với 4 lệnh quan trọng sau:

1. Lệnh date: Để in ra hoặc thiết lập thời gian hệ thống trên máy Linux của bạn. Bạn có thể cài đặt ngày và giờ bằng cách sử dụng các cú pháp đơn giản.

2. Lệnh timedatectl: Đảm bảo máy Linux của bạn được đặt đúng múi giờ. Bạn cũng có thể thiết lập múi giờ và thời gian với lệnh này.

3. Lệnh hwclock: Dùng để thay đổi và xem xét thời gian của đồng hồ phần cứng trên bo mạch của máy tính.

4. Lệnh ntp: Đảm bảo máy tính của bạn luôn đồng bộ với server mạng thông qua Network Time Protocol.

Việc quản lý thời gian đúng đắn giúp hệ thống giao tiếp hiệu quả và hoàn thành công việc một cách chính xác. Hỏi, bạn đã biết 4 lệnh quản lý thời gian trên Linux chưa? #Linux #QuảnLýThờiGian #HệĐiềuHành

Nguồn: https://www.zdnet.com/article/4-linux-commands-for-managing-time-and-why-thats-important/#ftag=RSSbaffb68

Jack Wallen/ZDNET

The right time helps systems communicate and ensures you can complete tasks — and with Linux, there are a few commands for managing time on your system.

Each of the following commands I’ll show you has a different purpose, but they all serve time. Although you may never use these commands, it’s good to know them, especially if you ever intend on using Linux as more than just a desktop operating system.

Also: The best Linux distros for beginners: You can do this!

Let me introduce you to the commands you need to know to work with time on Linux.

1. date

With date, you can print out or set the system time on your Linux machine. If you run the date command without any arguments, it will print out the date in the format:

Mon Jul 15 08:53:41 AM EDT 2024

You can also set the time and date with this command. The syntax of such a command would be something like this:

sudo date -s "15 July 2024 08:53:00"

You can also just set the date like this:

date +%Y%m%d -s "20240715"

Or set the time with:

2. timedatectl

The timedatectl command ensures your Linux machine is set to the right time zone. You can also use the command to set the time. If your Linux desktop or server doesn’t have the right time (by a few hours), the timezone could be improperly set. 

Also: The first 5 Linux commands every new user should learn

Thanks to timedatectl, setting the timezone isn’t all that hard. The trick is to know your timezone. You might be in America/New_York, America/Toronto, or America/Kentucky/Louisville. To find out what timezones are available, issue the command:

timedatectl list-timezones

Once you know your timezone, issue a command like this:

sudo timedatectl set-timezone America/Kentucky/Louisville

You can also set the date and time with this command like so:

timedatectl set-time 'YYYY-MM-DD HH:MM:SS'

For example:

timedatectl set-time '2024-07-15 08:53:00'

3. hwclock

Next, we have a command that can manipulate the hardware clock. The hardware clock is known as the Real-Time Clock (RTC), a battery-powered clock on your computer’s motherboard that keeps time, even when the system is powered off. Your computer’s BIOS manages the RTC.

Also: There’s a new coolest Linux distribution ready to wow you 

Should you need to change the hardware clock, Linux has a command for that purpose. 

You can view the hardware clock with the command:

If you find the hardware clock is wrong, you can set it with a command like this:

sudo hwclock --set --date="YYYY-MM-DD HH:MM:SS"

For example:

sudo hwclock --set --date="2024-07-15 09:15:00"

4. ntp

Now let’s return to timedatectl because the command includes a feature that works with Network Time Protocol (ntp) and keeps your computer in sync with a more reliable networked server. This feature does two things: it ensures your computer has the right time, and keeps you from dealing with time manually.

You can enable NTP on your system with the command:

sudo timedatectl set-ntp yes

Other tools allow you to make use of NTP. For example, you can use timesyncd, which most likely isn’t enabled by default. To enable timesyncd, issue the command:

systemctl enable --now systemd-timesyncd

Now, your system will always have the correct time. 

Also: How to enable Linux on your Chromebook

To learn more about these commands, make sure to read the man pages, with the following commands:

  • man date
  • man timedatectl
  • man hwclock

You won’t find a man page for systemd-timesyncd, but you can learn more about the command from the official Arch Linux Wiki page.


Exit mobile version