2

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!

lily
  • 1,735
  • 3
  • 14
  • 14
  • Did you just tried (on a `cp -p` copy) to [touch -OptionYouNeed](http://www.linfo.org/touch.html) it? – Hastur Dec 19 '15 at 06:23

2 Answers2

1

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.

Thomas Dickey
  • 8,632
  • 3
  • 22
  • 31
  • 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 03:35
0

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 ~]#
jbrahy
  • 131
  • 3
  • 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. http://lxr.free-electrons.com/source/include/linux/fs.h – jbrahy Dec 19 '15 at 00:28
  • only thing you can use to edit the file attributes is chattr. http://linux.die.net/man/1/chattr It's part of the e2fs progs set http://e2fsprogs.sourceforge.net/ – jbrahy Dec 19 '15 at 01: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 03: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