7

I'm using cp.exe from Cygwin to copy files in Windows 7. Unfortunately, when I do the permissions of the file change.

I've tried using:

cp --preserve=all

But that doesn't work either, and when I check the security of the original file vs the copy, the copy has different permissions.

Clearly there must be a way to preserve permissions when copying using Cygwin, but I can't find it.

mlissner
  • 17,359
  • 18
  • 106
  • 169
  • 1
    `cp --preserver=all` is probably the best you're going to be able to do with the `cp` command. Exactly what permissions are different? Are you copying to a FAT32 file system? If so, it may not support the permissions you want. – Keith Thompson Dec 07 '11 at 19:26
  • It seems like the original permissions are pretty much ignored. It's NTFS - Win7. – mlissner Dec 08 '11 at 00:50
  • @KeithThompson `cp --preserve=all` doesn't work on win7 atleast. cygwin cp permissions are still out of whack! – hawk Jan 08 '14 at 08:12

2 Answers2

10

I believe adding option noacl to the /cygdrive mount point in /etc/fstab will do what you want.

$ cat fstab
# For a description of the file format, see the Users Guide   
# http://cygwin.com/cygwin-ug-net/using.html#mount-table

# This is default anyway:
# none /cygdrive cygdrive binary,posix=0,user 0 0
none /cygdrive cygdrive binary,posix=0,user,noacl 0 0

See http://cygwin.com/cygwin-ug-net/using.html#mount-table and discussion from the cygwin mailing list.

Danila Polevshchikov
  • 2,228
  • 2
  • 24
  • 35
avg
  • 111
  • 2
  • 4
  • 1
    Doesn't work, a simple `mkdir` breaks the NTFS ACL inheritance and creates a bunch of new permissions, which sometimes are also making directories unbrowsable for the user that originally created them (often happens during rsync operation). So mounting with noacl is only a partial solution, still this does not make cygwin behave the way I expect. There are many discussions on this topic, for me it's a clear flaw of cygwin. – jdehaan Jan 17 '14 at 10:52
  • @jdehaan I checked with latest Cygwin and CMD.exe `mkdir` set same permission as Cygwin with path under `noacl` effect. Check you `/etc/fstab`. – gavenkoa Aug 13 '17 at 08:24
  • @jdehaan you have to add this too `F:\cygwin / ntfs override,binary,auto,noacl 0 0` – Badr Elmers Apr 12 '23 at 01:11
8

I did some more investigation about this after asking the question above.

Per this discussion with one of Cygwin's developers, it appears that Cygwin doesn't care about Windows permissions, and just sticks with the POSIX ones.

From what I can tell, POSIX permissions are a whole separate thing from the Windows ones, so yes, it's great that they're supported, but ultimately, Cygwin can't copy files and maintain normal Windows permissions. Making it useless to me. Much better to use Python or Ruby.

I would love to be proven wrong though.

mlissner
  • 17,359
  • 18
  • 106
  • 169
  • 4
    This burned me today, very disappointing. Fixed with: `getfacl src-file.txt | setfacl -f - dest-file.txt` Why can't Cygwin's `cp` do that for me?! Another option might be aliasing `cp` to an equivalent `rsync` command, similar to [this answer](http://unix.stackexchange.com/a/44400). – Dan Nov 01 '12 at 20:57
  • I was able to copy the files with `cp` after setting the `Total Control` Permissions on the destination file. – Lorenz Meyer Apr 09 '14 at 15:31