1

Seems simple, but couldn't find any answer:

Is it possible to edit a file for the purpose of updating the Linux date instead of using date +%y%m%d -s "DATE" command?

6
  • 1
    Could you give an example of what you are trying to do? Modify a date within a file? Modify the created/accessed time?
    – bu5hman
    Jun 11 '19 at 15:49
  • are you trying to set the system time & date based on the contents of a file?
    – Jeff Schaller
    Jun 11 '19 at 15:50
  • @JeffSchaller Actually I want to know which file contains system time and date and whether it is possible to manually edit this file or not by vim editor for example.
    – A.A
    Jun 11 '19 at 15:54
  • @bu5hman, I think my comment to Jeff clarifies my purpose
    – A.A
    Jun 11 '19 at 15:56
  • 1
    @A.A Clarifications should be made to the question, not left in comments where they may be ignored. Also, what makes you believe that the system time is stored in a file somewhere?
    – Kusalananda
    Jun 11 '19 at 16:15
2

There's no file representing the current system time on Linux. Linux gets the current time from the RTCs (real-time clocks) or from external sources like NTP servers, and then keeps track of it internally. The file-like representations of the RTC (/dev/rtc*) are used for configuring and recieving alarms, and can't be used for setting the time. The RTC status file (/proc/driver/rtc) is read-only. See the kernel documentation for details.

4
  • I thought that the command "hwclock --systohc" writes the system clock to RTC, ya?
    – A.A
    Jun 11 '19 at 16:34
  • 1
    So? What of it?
    – muru
    Jun 11 '19 at 16:35
  • And maybe the "date" command could have a representation file somewhere. Anyway, thank you for your answer. I'm a noob and I must go through the kernel documentation.
    – A.A
    Jun 11 '19 at 16:40
  • 2
    Both use system calls. date uses the clock_settime(2) function. You can use strace to examine what the commands actually do.
    – muru
    Jun 11 '19 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.