5

I'm working on simulating some commands in a Unix-like environment. I'm on Windows 10 and using GitBash's shell to run commands but chmod doesn't appear to keep the permission changes on a file.

zecuse MINGW64 ~ (dev)
$ touch test
zecuse MINGW64 ~ (dev)
$ ls -l test
-rw-r--r-- 1 zecuse 1049089 0 Nov 13 13:30 test
zecuse MINGW64 ~ (dev)
$ chmod -c -r test
mode of 'test' changed from 0644 (rw-r--r--) to 0200 (-w-------)
zecuse MINGW64 ~ (dev)
$ ls -l test
-rw-r--r-- 1 zecuse 1049089 0 Nov 13 13:30 test

Does Windows prevent me from changing file permissions in this way? If so, do I need to use powershell to modify a file's permissions?

js2010
  • 23,033
  • 6
  • 64
  • 66
zecuse
  • 125
  • 1
  • 1
  • 8
  • 1
    [An off-SO solution](https://chaosandpenguins.com/2016/10/25/chmod-is-ignored-in-the-git-bash-prompt/) that worked in my case: Add a `#!/bin/bash` line. Though I still find it odd that chmod doesn't work from Git Bash. Am I too used to Cygwin? Why have I never noticed this problem before? – Josiah Yoder Nov 26 '22 at 21:03

2 Answers2

2

An equivalent of chmod would be icacls

Please refer -

https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/icacls

How to grant permission to users for a directory using command line in Windows?

In case of chmod 0200 - user write permission

Try using cmd prompt or PowerShell

icacls test1 /grant User1:(w)

Sae1962
  • 1,122
  • 15
  • 31
0

No, it doesn't seem like the windows file system is compatible with gitbash chmod: https://www.reddit.com/r/git/comments/dss843/chmod_not_working_with_git_bash_in_windows/

I don't think this is relevant to powershell.

js2010
  • 23,033
  • 6
  • 64
  • 66