Pet*_*ons 5 filesystems permissions
有人可以解释为什么我在运行touch -m
此文件时权限被拒绝,即使它是组可写的并且我可以很好地写入文件。
~/test1-> id
uid=1000(plyons) gid=1000(plyons) groups=1000(plyons),4(adm),20(dialout),24(cdrom),46(plugdev),109(lpadmin),110(sambashare),111(admin),1002(webadmin)
~/test1-> ls -ld .; ls -l
drwxrwxr-x 2 plyons plyons 4096 Feb 14 21:20 .
total 4
-r--rw---- 1 www-data webadmin 24 Feb 14 21:29 foo
~/test1-> echo the file is writable >> foo
~/test1-> touch -m foo
touch: setting times of `foo': Operation not permitted
~/test1-> lsattr foo
-------------e- foo
~/test1-> newgrp - webadmin
~/test1-> id
uid=1000(plyons) gid=1002(webadmin) groups=1000(plyons),4(adm),20(dialout),24(cdrom),46(plugdev),109(lpadmin),110(sambashare),111(admin),1002(webadmin)
~/test1-> touch -m foo
touch: setting times of `foo': Operation not permitted
~/test1-> echo the file is writable >> foo
~/test1->
Run Code Online (Sandbox Code Playgroud)
来自man utime
:
The utime() system call changes the access and modification times of
the inode specified by filename to the actime and modtime fields of
times respectively.
If times is NULL, then the access and modification times of the file
are set to the current time.
Changing timestamps is permitted when: either the process has appropri?
ate privileges, or the effective user ID equals the user ID of the
file, or times is NULL and the process has write permission for the
file.
Run Code Online (Sandbox Code Playgroud)
因此,要仅更改文件 ( touch -m foo
)的修改时间,您需要是root
或文件的所有者。
能够写入文件只允许您将修改时间和访问时间更新为当前时间;您不能单独更新,也不能将它们设置为不同的时间。