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
    Commented Jun 11, 2019 at 15:49
  • are you trying to set the system time & date based on the contents of a file?
    – Jeff Schaller
    Commented Jun 11, 2019 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
    Commented Jun 11, 2019 at 15:54
  • @bu5hman, I think my comment to Jeff clarifies my purpose
    – A.A
    Commented Jun 11, 2019 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
    Commented Jun 11, 2019 at 16:15

1 Answer 1

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
    Commented Jun 11, 2019 at 16:34
  • 1
    So? What of it?
    – muru
    Commented Jun 11, 2019 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
    Commented Jun 11, 2019 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
    Commented Jun 11, 2019 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .