Msys shell command to change the attributes of a file

烂漫一生 提交于 2019-12-04 03:35:15

问题


Please let me know a MSYS shell command that can be used for changing the attributes of a file. When I ran a command as ls -l I got the following :

-rw-r--r-- 1 lenovo Admin .....m4sugar.m4

I want to provide full access rights.

Any help is highly appreciated.

Thanks


回答1:


@cdhowie is right; this is a bug of msys tracked there -> http://sourceforge.net/tracker/?func=detail&atid=102435&aid=3071537&group_id=2435

It cannot do anything more useful than it already does, unless it fakes it in the POSIX emulation, as Cygwin does. However, what Cygwin does is mostly irrelevant; since MSYS was forked from Cygwin-1.3, most of that faking was deliberately disabled -- it isn't an objective of MSYS, to provide faked POSIX features to the extent supported by Cygwin. If you want Cygwin's behaviour, and MSYS doesn't retain it sufficiently for your needs, then you should use Cygwin.

MSYS is designed to better integrate with the native MS-Windows features supported by MinGW. In this native MS-Windows environment, there is no file system attribute which can mark a file as executable -- that is indicated by magic byte sequences within the file's data space, (and usually also qualified by a file name extension to match). There is no way MSYS chmod can safely modify that, without risk of file corruption, other than by more completely embracing Cygwin's emulation. However, that is diametrically opposed to the MSYS Project objectives -- it just ain't going to happen.

@kbulgrien gives the good approach to change the permissions:

  • cacls: http://ss64.com/nt/cacls.html, or
  • icacls: http://ss64.com/nt/icacls.html

Note: icacls is the new version of cacls correcting several issues but seems to be not present in Windows XP.

You can use either of the following commands to give full access rights to Everyone:

  • cacls "$file_path" //E //P Everyone:F
  • icacls "$file_path" //grant Everyone:F

Note that ls -l in Msys won't display accurate information on real ACLs after the usage of cacls or icacls.




回答2:


The problem is very likely one of the minimal implementation in MSYS tools. You would also be restricted from making changes you cannot change with a Windows tool like attrib.exe.

$ >test
$ ls -l test
-rw-r--r--    1 kbulgrie Administ        0 Aug 24 13:51 test
$ chmod u-w test
$ ls -l test
-r--r--r--    1 kbulgrie Administ        0 Aug 24 13:51 test
$ chmod u+w test
$ ls -l test
-rw-r--r--    1 kbulgrie Administ        0 Aug 24 13:51 test

As you can see, chmod works fine. Now, see what happens with attrib.exe, a Windows binary:

$ ls -l test
-rw-r--r--    1 kbulgrie Administ        0 Aug 24 13:51 test
$ attrib +R test
$ ls -l test
-r--r--r--    1 kbulgrie Administ        0 Aug 24 13:51 test
$ attrib -R test
$ ls -l test
-rw-r--r--    1 kbulgrie Administ        0 Aug 24 13:51 test

attrib, the Windows tool, is agnostic about the ugoa permissions and simplifies things down to having or not having rights:

$ attrib +R test
$ attrib test
     R     C:\msys\1.0\home\kbulgrien\test

I'm note sure its fair to expect an MSYS tool to do more than the Windows "equivalent". The M in MSYS means "Minimal".

cacls.exe can do some things under MSYS. For instance, this says I and Administrators have full control even though ls -l appears to say Administrat doesn't have write. Be careful. If on Windows, perhaps use Windows methods. $ cacls test
C:\msys\1.0\home\kbulgrien\test BUILTIN\Administrators:F NT AUTHORITY\SYSTEM:F APD\kbulgrien:F BUILTIN\Users:R

The following command is one I use in an MSYS environment to fix permissions on SQL database files after I restore from archive. You can run Windows binaries from MSYS. I do it all the time... for instance, scripts run diskpart, format, etc. in an MSYS shell without invoking cmd.exe.

$ cacls "Mantis*.*" //E //G "NETWORK SERVICE":F


来源:https://stackoverflow.com/questions/10915178/msys-shell-command-to-change-the-attributes-of-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!