2

The function chmod is implemented in Cygwin but does not fully match access rights in Windows. This appears in the following change log: https://cygwin.com/cygwin-ug-net/ov-new1.7.html

Since 1.7.34, chmod does not always affect the POSIX permission mask as returned by stat(2) or printed by ls(1), due to the improved POSIX ACL handling. However, that's still far from perfect, so, as a temporary workaround, [...]

The implementation of chmod in Msys is not working, as mentioned in the following bug report: https://sourceforge.net/p/mingw/bugs/1475/

This question is asking how to provide full access rights to a file in Msys.

How can I change the rights of a file to respectively "read-only" and "write-only" in Msys/Cygwin?

Thanks

Community
  • 1
  • 1
Jean-Francois T.
  • 11,549
  • 7
  • 68
  • 107

1 Answers1

3

You can use the commands provided by windows: cacls and icacls

Read-Only with cacls

$ cacls "$file_path" //E //P Everyone:N 1>/dev/null
$ cacls "$file_path" //E //G Everyone:R 1>/dev/null

Write-Only with cacls

$ cacls "$file_path" //E //P Everyone:N 1>/dev/null
$ cacls "$file_path" //E //G Everyone:W 1>/dev/null

The first line removes all rights. The second lines add either "Read" or "Write"

If you are not using Windows XP, you can use icacls instead:

  • Read-only: icacls "$file_path" //grant :r Everyone:R 1>/dev/null
  • Write-only: icacls "$file_path" //grant :r Everyone:W 1>/dev/null

More information on these commands:

Jean-Francois T.
  • 11,549
  • 7
  • 68
  • 107