Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How do I transfer write/execute and execute permissions from owner to group and other, respectively?

I have some libraries I want to move to opt and set ownership of to root. Unfortunately, permissions are a bit messed up for group and other, and that creates a problem as group and other cannot use the libraries, call the executables and read the files.

I want to recursively set the permissions of write/execute and execute to group and other respectively. For example, I want this:

-rw-r--r--.   1 root root    4464 Jan 11 23:58 CPackSourceConfig.cmake
-rwxr--r--.   9 root root   28672 Jan 11 23:58 executable
drwxr--r--.   9 root root   28672 Jan 11 23:58 Source

to be this:

-rw-rw-r--.   1 root root    4464 Jan 11 23:58 CPackSourceConfig.cmake
-rwxrwxr-x.   9 root root   28672 Jan 11 23:58 executable
drwxrwxr-x.   9 root root   28672 Jan 11 23:58 Source

How do I best go about doing this, considering there are quite a number of files/folders (recursive)?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Some mix of find and chmod should do the trick:

  • all the directories:

    find /opt -type d -exec chmod 775 {} \;
    
  • all the "executable" files:

    find /opt -type f -perm -0500 -exec chmod 775 {} \;
    
  • all the other files:

    find /opt -type f -not -perm -0500 -exec chmod 664 {} \;
    
share|improve this answer
    
Yes it does, due to the "-not" on the "-perm" select option (I verified the whole case on a BSD box and a RedHat). –  Ouki Feb 13 '12 at 16:39
    
Ah! you're correct. Hadn't parsed the - in front of the mode bits. Sorry for the noise :) –  Mat Feb 13 '12 at 16:42
    
Thanks, It took me a while to decipher the logic behind the two last statements, especially the last one. –  qonf Feb 14 '12 at 13:42
add comment

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.