I use stat to get information of files, I notice

Access: 2013-12-28 13:12:11.244573123 +0100
Modify: 2013-11-12 22:54:42.274460079 +0200
Change: 2013-12-13 12:45:08.164394887 +0100

the +0100 +0200 means "time offset from UTC"

I want to make the second line as:

Modify: 2013-11-12 22:54:42.274460079 +0100

How to modify it?

thanks!

The stat program is showing local-time for each of the access, modify and change-dates. The odd one is probably in the daylight savings time, shifting it by an hour (though November 12 seems late for this, I see the pattern in results from stat on my Debian 7 machine).

For example, my timezone is normally EST5EDT, and I see this:

$ stat vbx-minix3.2-gcc-normal-run.log
  File: `vbx-minix3.2-gcc-normal-run.log'
  Size: 164806          Blocks: 328        IO Block: 4096   regular file
Device: fe01h/65025d    Inode: 550759      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1001/     tom)   Gid: (  100/   users)
Access: 2015-12-18 21:30:09.081845121 -0500
Modify: 2014-07-25 17:16:10.000000000 -0400
Change: 2015-09-18 19:08:03.501222363 -0400
 Birth: -

By overriding the timezone, I can see the dates all with the same offset:

$ TZ=EST5 stat vbx-minix3.2-gcc-normal-run.log
  File: `vbx-minix3.2-gcc-normal-run.log'
  Size: 164806          Blocks: 328        IO Block: 4096   regular file
Device: fe01h/65025d    Inode: 550759      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1001/     tom)   Gid: (  100/   users)
Access: 2015-12-18 21:30:09.081845121 -0500
Modify: 2014-07-25 16:16:10.000000000 -0500
Change: 2015-09-18 18:08:03.501222363 -0500
 Birth: -

You can probably choose an equivalent TZ which omits the daylight savings time option.

What one sees depends on what their timezone is set to. The offset shown depends solely on (a) the time of the year when the change occurred and (b) the local machine configuration used to display the time.

  • I don't understand what you mean. I need to send the files to someone else, and I hope when he use stat to see the time, he can see Modify: 2013-11-12 22:54:42.274460079 +0100 instead of Modify: 2013-11-12 22:54:42.274460079 +0200 in his machine. – lily Dec 19 '15 at 3:35

Have you tried changing your TZ export?

[root@pm-prod-email01 ~]# stat /etc/sysconfig/clock
  File: `/etc/sysconfig/clock'
  Size: 27          Blocks: 8          IO Block: 4096   regular file
Device: ca01h/51713d    Inode: 65628       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-12-18 14:08:21.000000000 -0800
Modify: 2013-10-10 10:53:17.000000000 -0700
Change: 2013-10-10 10:53:17.000000000 -0700
[root@pm-prod-email01 ~]# TZ='Asia/Kolkata'
[root@pm-prod-email01 ~]# export TZ
[root@pm-prod-email01 ~]# stat /etc/sysconfig/clock
  File: `/etc/sysconfig/clock'
  Size: 27          Blocks: 8          IO Block: 4096   regular file
Device: ca01h/51713d    Inode: 65628       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-12-19 03:38:21.000000000 +0530
Modify: 2013-10-10 23:23:17.000000000 +0530
Change: 2013-10-10 23:23:17.000000000 +0530
[root@pm-prod-email01 ~]#
  • I don't want to change my system UTC, i ONLY want to change the file UTC – lily Dec 18 '15 at 23:28
  • files don't have timezones associated. they're all in UTC and your shell has the offset. Here's the source for the linux file structure. lxr.free-electrons.com/source/include/linux/fs.h – jbrahy Dec 19 '15 at 0:28
  • only thing you can use to edit the file attributes is chattr. linux.die.net/man/1/chattr It's part of the e2fs progs set e2fsprogs.sourceforge.net – jbrahy Dec 19 '15 at 1:13
  • then how can I make the second line become Modify: 2013-11-12 22:54:42.274460079 +0100, the same UTC as the other two lines ? – lily Dec 19 '15 at 3:33
  • you can set an environment variable for a single command without exporting for the system like this: "TZ=Asia/Kolkata stat /etc/sysconfig/clock" – jbrahy Dec 21 '15 at 19:56

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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