Preserve file date/timestamp when using chmod

Hello everybody,

I am wondering why chmod changes files and folder dates/timestamps? I use OpenSUSE 11.3.

I have other machines running CentOS 5.5 (RedHat) and Ubuntu on which this does not happen. My users are getting crazy with this because they cannot track when they made modifications on their files (real changes, not chmod).

Is there a way to preserve this information? I read the man put did not find any parameter.

Was there a new behaviour in latest versions of chmod?

Thanks for your help.

Never saw anything like this. Please show a transcript of a session (in a code block) where chmod changed the file timestamps.

On 10/21/2011 03:46 PM, hanapurna wrote:
>
> Hello everybody,
>
> I am wondering why chmod changes files and folder dates/timestamps? I
> use OpenSUSE 11.3.
>
> I have other machines running CentOS 5.5 (RedHat) and Ubuntu on which
> this does not happen. My users are getting crazy with this because they
> cannot track when they made modifications on their files (real changes,
> not chmod).
>
> Is there a way to preserve this information? I read the man put did not
> find any parameter.
>
> Was there a new behaviour in latest versions of chmod?
>
> Thanks for your help.
>
>

i don’t think chmod changes date/times…

at least i can say it does not here:


denver@linux-os114:~/test> ls -hal
drwx------  2 denverd users 4.0K Oct 21 16:00 ./
drwxr-xr-x 69 denverd users 4.0K Oct 21 16:00 ../
-rw-r--r--  1 denverd users 1.1M Jun 29 10:17 danid.log.1
-rw-------  1 denverd users  189 Jun 30 02:53 nohup.out
-rw-r--r--  1 denverd users  155 Oct 18 15:28 sigSUSE
-rw-r--r--  1 denverd users    9 Mar  1  2011 sigSUSEguest
-rw-r--r--  1 denverd users   87 Jun 12 19:14 sigSUSE-longBAK
-rw-r--r--  1 denverd users  251 Mar 11  2011 sigTELE
denverd@linux-os114:~/test> chmod 777 *
denverd@linux-os114:~/test> ls -hal
total 1.1M
drwx------  2 denverd users 4.0K Oct 21 16:00 ./
drwxr-xr-x 69 denverd users 4.0K Oct 21 16:00 ../
-rwxrwxrwx  1 denverd users 1.1M Jun 29 10:17 danid.log.1*
-rwxrwxrwx  1 denverd users  189 Jun 30 02:53 nohup.out*
-rwxrwxrwx  1 denverd users  155 Oct 18 15:28 sigSUSE*
-rwxrwxrwx  1 denverd users    9 Mar  1  2011 sigSUSEguest*
-rwxrwxrwx  1 denverd users   87 Jun 12 19:14 sigSUSE-longBAK*
-rwxrwxrwx  1 denverd users  251 Mar 11  2011 sigTELE*
denverd@linux-os114:~/test>

try it yourself…if you get date/time changes please do as i did and
show both your input and the output…copy/paste the output back to this
thread using the instructions here: http://goo.gl/i3wnr


DD
http://tinyurl.com/DD-Caveat
http://tinyurl.com/DD-Hardware
http://tinyurl.com/DD-Software
openSUSE®, the “German Automobiles” of operating systems

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It depends on which timestamps you view, and maybe with the filesystem
stuff:

<quote>
ab@mybox0:~/Desktop> stat testme
File: `testme’
Size: 0 Blocks: 0 IO Block: 4096 regular
empty file
Device: fd01h/64769d Inode: 10491571 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 1000/aburgemeister) Gid: ( 100/
users)
Access: 2011-10-21 08:19:00.349716949 -0600
Modify: 2011-10-21 08:19:00.349716949 -0600
Change: 2011-10-21 08:19:00.349716949 -0600
2011-10-21 08:19:55 Jobs:0 Err:0

ab@mybox0:~/Desktop> chmod +x ./testme
2011-10-21 08:19:59 Jobs:0 Err:0
aburgemeister@ablaptop0:~/Desktop> stat testme
File: `testme’
Size: 0 Blocks: 0 IO Block: 4096 regular
empty file
Device: fd01h/64769d Inode: 10491571 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 1000/aburgemeister) Gid: ( 100/
users)
Access: 2011-10-21 08:19:00.349716949 -0600
Modify: 2011-10-21 08:19:00.349716949 -0600
Change: 2011-10-21 08:19:59.914716679 -0600
</quote>

Notice that while the Modify time did not change the ‘Change’ time did.
This is my root filesystem which has noatime set in the /etc/fstab file
so I do not know if this would behave the same way without ‘noatime’
set. Generally noatime is a good thing to have set but it is not a
default in SUSE-land.

Good luck.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOoX/3AAoJEF+XTK08PnB56QwQAMLUO1LVBW/MLgSq+9O0vCF9
Ws1OKNwDPwOLcdF2tEY2PCNDjQoi/rvnVbYph+MYyecWhZDBsIKd9VWDTHbxIc3d
xfg5yzrVbH3269D42uCrzu6fVaM0/ho3DOMvItr+YRgfeJbzBDku46D481br+9K/
jbWppgO+Fw5UpYLVhFMcodNvq2fYubJeTEclX/O1pyn9BYLm3pTLEgPl/Wjb4Qwp
942TllXrvRpuzsa0f6mCoDJ4GCJKLgnmhZ04R1Z4RrLSsgFkNTK5mM51cq/rNAtV
+9RtRpkIBCjhWPqB81Lo5EjiOmS5FGToiZ8sFjiucSfutrsvDk9tD+0NTHJPobd7
xgnh+SHw756rmLlvnnm/9WtyJ6WvZ0yWdrYyHKao8OxKkfxd/0UeB9FVRxypeKMT
v2A+tvQiUCTTDAuAPRKorKP3eaSmWCnCBUFJXp1EF1HsUuI6jEfq7omNdT47vLwl
OwJftyvnC2xnl1ymjJf7CQAKlX5+mmqi0Qcfo5Kgz7p90We5UAfDXfvzYSqgIY9a
cZlkJtNV9UJvun+crkZmncxjzPt8UbejPgFxbohYtAgzqU6zX/Url2ceSH1rGemZ
au5vYpbNWPtymLcKZ+zxT2U8FMVEjGJSeVOVqziNMNJMQo4uQc/syCY8pX3OBPg9
L732IltOJ3JqcWLsUbGK
=Bk2X
-----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tested again… lacking ‘noatime’ did NOT cause the Modify timestamps
to be updated. Knowing more about the filesystem involved may be
helpful (output from mount command with a note about where the files
are in the filesystem).

Good luck.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOoYGZAAoJEF+XTK08PnB568cP/iAp+/0YM5iJK8M+1zpxd4Av
hJf9gBW9HtgsL+mLwWVwq7Z76Mn42ZmmgrTzVW8NsT+dtPVqDqsXI514x/FtLEz9
QlJ9kbsFZC7tf6dX3EnQ6M271gawA36y++6nAdd+xqRg0HnhNWgVnuuTEL/aSReZ
rAFy/Ua0h0P0mtO6aqtEGDrPPQlSVPHKnVv8/olciVXnYQP99MUGOpke5usdrr5A
g0svl+tcDuaqd8WAsQ+sRJGYFHBUiTchy/4sSUeVl6uT1ahwkjAy2JuAq83D67d7
SnEe3GwFB6oyx0iIpNHCSTchEpD3JZYR3XTapHPcu7Vdh8I5HmsN/cdGI8b5OA2F
FrhrqjRE+ljUiIZk9smQALKTqKXUQLO/axfzgyFrgwrFcdBmKVnSF1amkASMwd1Q
XmvG2ZohqblAaUY5A0wyhaReCJ7MOGXImyCxxb7gvyML2JzlwWkOMSy7ppTlWrhT
xusq3Tu+WjMnGqoTTomcgh3Sm2YXoWTkViivbO+DlrYKzL0LQhdDnqkUAQn2irsd
u3Quf+80zdjnFBH0zlkAuY4VeZBS+dkb8eEfDUgI93ocrG70jgEY2KWuStZzVmig
3+KScJj8HSLC89fM+v2iznAl5GBvJF0O5o0JV0wF5S9jLfb76oJpbARraqHQUL3L
+aBz/y3E/TOq0zVsxa74
=3gqP
-----END PGP SIGNATURE-----

Hi,

Thanks for your replies.

Here is what I do.
First, I create an empty file and check the dates


[hanapurna@vmtest datetest]$ touch file1
[hanapurna@vmtest datetest]$ ll
total 8
4 drwxr-xr-x  2 hanapurna hanapurna 4096 2011-10-24 10:00 .
4 drwxr-x--- 32 hanapurna hanapurna 4096 2011-10-24 10:00 ..
0 -rw-r--r--  1 hanapurna hanapurna    0 2011-10-24 10:00 file1

Then I wait a bit and issue a chmod. The date changes.


[hanapurna@vmtest datetest]$ chmod g+w file1
[hanapurna@vmtest datetest]$ ll
total 8
4 drwxr-xr-x  2 hanapurna hanapurna 4096 2011-10-24 10:00 .
4 drwxr-x--- 32 hanapurna hanapurna 4096 2011-10-24 10:00 ..
0 -rw-rw-r--  1 hanapurna hanapurna    0 2011-10-24 10:04 file1

I then figure out, thanks to your posts, that I got screwed by the default ll alias as the Modify date did not change …


[hanapurna@vmtest datetest]$ ls -hal
total 8.0K
drwxr-xr-x  2 hanapurna hanapurna 4.0K 2011-10-24 10:00 .
drwxr-x--- 32 hanapurna hanapurna 4.0K 2011-10-24 10:00 ..
-rw-rw-r--  1 hanapurna hanapurna    0 2011-10-24 10:00 file1
[hanapurna@vmtest datetest]$ stat file1
  File: `file1'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 811h/2065d      Inode: 393854      Links: 1
Access: (0664/-rw-rw-r--)  Uid: (10207/hanapurna)   Gid: (10207/hanapurna)
Access: 2011-10-24 10:00:59.532944765 +0200
Modify: 2011-10-24 10:00:59.532944765 +0200
Change: 2011-10-24 10:04:31.715001536 +0200
[hanapurna@vmtest datetest]$ alias
alias ll='ls -lsac'

I just have to remove the -c option of the ls command on my ll alias and it should be fine.

Thanks again for your help.

Regards.