0

I need to find all files in a directory where “other” have permissions to read, write, or execute, and I need to apply those permission to “group”.

Example: if file1 has rwxr--rw-, this would change it to rwxrw-rw-.

But in the case that “group” has permissions but “other” doesn’t, I need to leave it as is.

I need to use one command for this with no pipes.

Any tips you can help me with?

6
  • "One command with no pipes" sounds like a homework assignment requirement. Is that it, or is this a real-life problem you're trying to solve?
    – l0b0
    Mar 4, 2021 at 2:01
  • It sounds like you're looking for the -perm /mode form of the command ("Any of the permission bits mode are set for the file") rather than the -perm -mode form ("All of the permission bits mode are set for the file") Mar 4, 2021 at 2:09
  • it is indeed an asignment @l0b0, as i stated, ido not want the answer, i only want tips that might point me in the right direction.
    – julie
    Mar 4, 2021 at 2:13
  • @steeldriver thanks, i will look into it right now.
    – julie
    Mar 4, 2021 at 2:13
  • @julie Hint: chmod with "symbolic" modes (see the man page) will allow you to surgically set individual bits in a file's mode, without affecting other bits. Mar 4, 2021 at 2:29

2 Answers 2

0

In hint form, since this is an assignment:

We can check whether a specific group and other permission is different with the following find syntax:

\( -perm -o=PERMISSION -not -perm -g=PERMISSION \)

Since there are eight different possibilities you'll need eight of these to match all differences.

Once you have these files you can use -exec COMMAND {} \; to run COMMAND for each file.

chmod is the command to change the permissions.

Now, how you'd actually copy the permissions from other to group without running another command is a bit of a conondrum.

7
  • I found a way to isolate all files that have other permissions (any of the 7 possibilities, since if it have no perms nothing is changing in group). my issue is the chmod that i have to basicly tell, if other has r perm and groupe doesnt, give group r perm, and do the same for all seven possibilities. thanks you for your help anyway, because i used another way to do it, i didnt know i could do it youre way.
    – julie
    Mar 4, 2021 at 2:23
  • Thank you very much @l0b0 ! That helps alot
    – julie
    Mar 4, 2021 at 2:39
  • I'd be interested to know how you end up copying the permissions across within a single command.
    – l0b0
    Mar 4, 2021 at 2:40
  • I figured it all out, thanks to your help and @steeldriver but i dont want to send the answer here. is there a way to pm someone?
    – julie
    Mar 4, 2021 at 2:51
  • 2
    Note that -not is a GNUism. The standard equivalent is !. Mar 4, 2021 at 7:05
0

The command I used to solve my problem was :

find ./directory/ -perm /o=rwx -execdir chmod g+o {} +

Thanks again for the help, @l0b0 and @steeldriver!

1
  • It would appear that you are using two different accounts. Please consider contacting the administrators to merge them.
    – AdminBee
    Mar 10, 2021 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.