Can someone explain why I get permission denied when running touch -m on this file even though it is group writable and I can write to the file fine.

~/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

3 Answers 3


From 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

So, to change only the modification time for the file (touch -m foo), you'd need to either be root, or the owner of the file.

Being able to write to the file only gives you permission to update both the modified and access times to the current time; you can not update either separately, nor set them to a different time.

  • 1
    Any idea the rational behind this? It seems silly that I would be permitted to overwrite the files content completely yet denied permission to change the mtime to a specific value? Feb 15, 2013 at 14:42
  • 1
    @PeterLyons For example, you can indirectly set the mtime to the current date, but you can't force an mtime in the past, so you can't hide that the file has been modified recently. Feb 15, 2013 at 22:20
  • imho should be man 2 utime. it's a syscall.
    – myrdd
    Jun 14, 2019 at 18:17

It caught me too.

coreutils documentation also says this:

When setting file timestamps to the current time, touch can change the timestamps for files that the user does not own but has write permission for. Otherwise, the user must own the files. Some older systems have a further restriction: the user must own the files unless both the access and modification times are being set to the current time.

Maybe GNU/Linux is already 'some older system'.


It seems like file owner web-data have only read permission that's why you are getting error.

Try to change the permission like

chmod 750 foo

then su web-data and then run touch -m command.

or run touch -m command as a root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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