How to specify group with 'chmod'
Solution 1:
The chmod()
system call, and by extension the chmod
program, does not affect the group of a file or directory (or other type of file: block special, character special, socket, ... symlink is something of a special case). So, the group to which the permission is given will be the group to which the file or directory belongs.
To add group rwx
permissions, you should use:
chmod -R g+rwx DirectoryName
However, this adds the permissions to every file as well as every directory, and not all files should be executable. Personally, I'd be very unhappy if someone provided group write permission on all (or any) of my directories, but that's another story.
To affect directories only, use find
instead:
find DirectoryName -type d -exec chmod g+rwx {} +
(The +
notation is POSIX 2008; not all Unix systems support it, though Linux does.)
Solution 2:
Every file on an ext filesystem has:
- An owner user
- An owner group
- Permissions for this user, this group and everybody else.
If you're setting rwx group permissions on a file, only the owner group of that file can read/write/execute it. You can, though, change user and owner with:
chown username file1 file2 ...
chown -R username somedir
chgrp groupname file1 file2 ....
chgrp -R groupname somedir
chown username:groupname file1 file2 ...
There are different implementations for extended filesystem privileges, i.e. ACLs (access control lists) on Mac OS X.