2
I would like to automate changing permissions for files copied to a directory. For example, any files copied to folder X should have mode 755, and any files copied to folder Y should have mode 700.
Please advise, thank you!
2
I would like to automate changing permissions for files copied to a directory. For example, any files copied to folder X should have mode 755, and any files copied to folder Y should have mode 700.
Please advise, thank you!
2
You can use umask
for this. to figure out the mode do this:
7777 -umask = new permissions
for example (linux):
777 -022 755
umask is 022, permissions will be 755 for folders and 644 for files. Put something like umask 0027
in your ~/.profile to have it load each time you log in.
UPDATE (due to a skeptic comment):
$ umask
0077
$ ll
total 0
-rw-rw-rw- 1 jaroslav jaroslav 0 Nov 9 20:26 00
-rw-rw-rw- 1 jaroslav jaroslav 0 Nov 9 20:26 01
-rw-rw-rw- 1 jaroslav jaroslav 0 Nov 9 20:26 02
-rw-rw-rw- 1 jaroslav jaroslav 0 Nov 9 20:26 03
$ rm -rf ../copies/*; \
/bin/cp --no-preserve=mode,ownership * ../copies/; ll ../copies/
total 0
-rw------- 1 jaroslav jaroslav 0 Nov 9 20:33 00
-rw------- 1 jaroslav jaroslav 0 Nov 9 20:33 01
-rw------- 1 jaroslav jaroslav 0 Nov 9 20:33 02
-rw------- 1 jaroslav jaroslav 0 Nov 9 20:33 03
I think umask works only on newly created, not copied files – The Chosen One – 2012-11-09T10:02:15.483
copied files are new. – Ярослав Рахматуллин – 2012-11-09T19:29:47.567
Ok, if copied files aren't new, then what are they? ... As I have shown umask can be used to to affect new files that cp makes. Perhaps some versions of cp don't support this, but rsync could probably (haven't checked) be used on those systems to do the same thing. Anyway, this isn't what the question was about and the answer is incorrect. – Ярослав Рахматуллин – 2012-11-10T10:30:53.007
cp works, but not mv. – John Siu – 2012-11-11T00:36:42.970
1
I don't believe it possible to do this on a directory-by-directory basis using standard unix permissions. ACLs, however, can do this.
I edited /etc/fstab and added acl attribute on the partition which contains folders X and Y. What setfacl command should I use to solve my problem? – The Chosen One – 2012-11-13T13:49:01.350
would this help? http://superuser.com/questions/47463/how-to-change-permissions-on-all-files-in-a-directory-and-when-new-files-are-ad?rq=1 or this; http://superuser.com/questions/237802/how-to-set-default-permissions-for-files-moved-or-copied-to-a-directory?rq=1
– wuxmedia – 2012-11-08T21:28:40.930