Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Some years/versions ago I found a script that took the Directory group/permissions of the current folder for NEW files Sub-Folders

Currently when I import Photographs into 12.04 using Shotwell, I have to use terminal to issue: chgrp photography *.JPG. This enables other ubuntu members of 'photography' group to add these files to their version of Shotwell.

I find modifying the Folder Properties/Permissions will NOT set the Group on 'Apply Permissions to Enclosed Files'

share|improve this question

2 Answers 2

So, if I understand you correctly, you want files (pictures) that are put into a specific folder to automatically get assigned to a specific group (photography).

A possible solution is setting the "setgid permission" on the parent folder, where all images are stored. The setgid permission (see e.g. wikipedia) ensures that all files and folders that are created in a folder with the setgid bit set obtain the group of that folder (instead of the group set by the file creator).

Since this does not effect files and folders that are already created inside this directory, first change their group recursively using

chgrp photography -R <your shotwell photo folder>

Now set the setgid bit on that folder. To do so, run

chmod g+s <your shotwell photo folder>

After both commands, your shotwell photo folder and all its contents belong to the group "photography", and the setgid is set:

ls -ld <your shotwell photo folder>
drwxrwsr-x 2 <your user> photography 4096 Aug 27 20:42 <your shotwell photo folder>

Notice the s in drwxrwsr-x. That "s" indicates that the setgid bit is set.

Now each time photos are copied into your shotwell folder, they are automatically assigned to group "photography".

Caution:
If files and folders are moved into that directory (instead of copied). Their group is not changed. This is because of the tool itself. "mv" basically just renames the file, keeping its original ownerships and permissions, while "cp" creates a new file in the target directory.

share|improve this answer

The setgid bit solution in ceage answer will work perfectly (+1) if you have only one group of people and everybody has the same permissions on the files but if you need more control with many groups, different permissions or even a per user rule, you can use acl. You can have a look at man setfacl.

For example in your case, you could define an acl for the photography group:

setfacl -Rm d:g:photography:rwX,g:photography:rwX /photo_dir

    -R : recursive to all sub-folders and files
    -m: modify using arguments in command line (can be used from config files)
    d:g:photography:rwX: apply default (d:) permissions (rwX:) for photography group (g:group) on new files/directories
    g:photography:rwX: same as above on existent files/directories (no d:)

rwX: capital X defines x only for directories

You can check the permissions applied with getfacl /photo_dir

If you need a second group with read-only permissions for example, you define another acl and apply it the same way for the new group with rX instead of rwX. ACLs can be defined for whole directories or individual files.

This will be permanent and you won't need to redefine permissions when you add delete or modify pictures. You define the ACLs once and "forget" about it.

The user and group seen with ls -l will no more be relevant/sufficient to control the file access (they are transformed in acl when you first run setfacl) and there will be a "+" at the end of the permission list like drwxrws---+ 6 root.....

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.