Home » Questions » Computers [ Ask a new question ]

Chmod files to recursively give group same permissions as user

Chmod files to recursively give group same permissions as user

Is there a unix command to give the group the same permissions as the user currently has on a file-by-file basis recursively for a directory tree? I.e. if a file is user writeable it should become group writeable, otherwise it should not be group writeable and so on.

Asked by: Guest | Views: 272
Total answers/comments: 1
Guest [Entry]

"I can't think of an easy way to do that with existing commands. Maybe a script like this would help :

#!/bin/bash

DIR=""$1""

find ""$DIR"" -ls | while read a b perm c d e f g h i file; do
uperm=${perm:1:3}
uperm=$(echo ""$uperm"" | tr -d '-')
chmod g=$uperm ""$file""
done

Also, keep in mind that some perms for users might not apply to groups, and vice versa."