`
If you find these tutorials useful, Please consider making a donation.

TheFrugalComputerLinuxLogo.png
TheFrugalComputerGuy.png
Linux Command Line 10
Time, Date, stat







Linux Command Line (30) Time and Date pt1

To see the computers date and time, we can type "date". We can also see the date in universal time with "date -u" We also see future and past dates and times.

The date and time can be formatted many different ways, looking at the man page a few examples are chosen to show different ways to the date and time can be formatted. We can also add custom text in with the custom date formatting. A customized formatted date would be:
date +"Today is %A %Y/%m%d"

We can see the time in a different timezone by adding the timezone before the date with TZ equals and then the date command:
TZ="America/Los_Angeles" date %T





 






Linux Command Line (31) Time and Date pt2

In this video we use Ubuntu 20.10 and I turned off the "Automatic Date and Time" from the Settings menu.

We start by looking at the timedatectl command.

Because we have turned off the "Automatic Date and Time" we can update the date with the "date -s" command

Typing in the timedatectl command again shows we did not update the RTC (Real Time Clock). To update the real time clock, we can type with the "timedatectl set-time" command.

We see that "System clock synchronized" and "NTP" (Network Time Protocol) go out to the internet to get and update the time on the computer. When either one is enable the other gets enabled and if we set the time with "date -s" The time will be updated, but moments later, the time will be updated again with the time and date from the internet.

We use the "timedatectl list-timezones" to see the timezones available then we update the timezone with "sudo timedatectl set-timezone" command





 






Linux Command Line (32) stat

The stat command shows the information on the inode for that file and the data shown is very similar to the ls command. One big difference is the ls command only shows one date and the stat command shows three dates. The Access date-time, the Modify date-time, and the Change date-time. The ls command shows the modified date and time.

The modified datetime is the last time that file was updated. The Change time and date can be updated by modifying the file permissions. The Access date and time are updated when a file is modified or the first time that file is accessed after an update. Updates to the /etc/fstab file will need to be made to have the Access date and time updated every time the file is accessed as shown in the video.

The output of the stat command can be formatted and examples of how to do that are shown in the video.