1

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)?

1 Answer 1

2

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 {} \;
    
3
  • 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
    Commented Feb 13, 2012 at 16:39
  • Ah! you're correct. Hadn't parsed the - in front of the mode bits. Sorry for the noise :)
    – Mat
    Commented Feb 13, 2012 at 16:42
  • Thanks, It took me a while to decipher the logic behind the two last statements, especially the last one.
    – qonf
    Commented Feb 14, 2012 at 13:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .