Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy group permission to other permission

Status
Not open for further replies.

hokky

Technical User
Nov 9, 2006
170
AU
Hi guys,

Just wondering is there any way to copy the group permissions to the other permissions ?

I don't want to set it manually through chmod. Because the files are too many and the permissions is different for the files.

Thanks guys,
 
Here's a bash script that seems to work.
Code:
#!/bin/sh
for file in ${@}; do
        r=`ls -l $file | cut -c5`
        w=`ls -l $file | cut -c6`
        x=`ls -l $file | cut -c7`

        if [[ $r == "r" ]]; then
                chmod a+r $file
        else
                chmod a-r $file
        fi

        if [[ $w == "w" ]]; then
                chmod a+w $file
        else
                chmod a-w $file
        fi

        if [[ $x == "x" ]]; then
                chmod a+x $file
        else
                chmod a-x $file
        fi
done
 
Typed, untested:
for file; do chmod a=$(ls -ld $file | cut -c5-7) $file; done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top