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?

Stephen Kitt
  • 434,908
julie
  • 3
  • "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 04 '21 at 02: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") – steeldriver Mar 04 '21 at 02: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 04 '21 at 02:13
  • @steeldriver thanks, i will look into it right now. – julie Mar 04 '21 at 02: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. – Gordon Davisson Mar 04 '21 at 02:29
  • There's always the option of doing chmod g+o on all files without checking if that's needed first (would have the side effect of updating the ctime though). – Stéphane Chazelas Mar 04 '21 at 07:29

2 Answers2

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.

l0b0
  • 51,350
  • 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 04 '21 at 02:23
  • Thank you very much @l0b0 ! That helps alot – julie Mar 04 '21 at 02:39
  • I'd be interested to know how you end up copying the permissions across within a single command. – l0b0 Mar 04 '21 at 02: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 04 '21 at 02:51
  • Not really, but you could always add another comment here once you've handed it in :) – l0b0 Mar 04 '21 at 03:09
  • Okey i will in a couple of days! – julie Mar 04 '21 at 03:18
  • 2
    Note that -not is a GNUism. The standard equivalent is !. – Stéphane Chazelas Mar 04 '21 at 07: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!

AdminBee
  • 22,803
julie
  • 1