-1

I currently have to change the permission of all the files meeting the criteria g=000 (meaning group has no reading permission, no writing permission and not execution permission) which are in a directory containing ~50 files. I'm with Linux and work on the terminal, using Shell command.

As an example, here are the first 6 (my name have been replaced by user):

-r--r----- 1 user user 0 Sep 23 19:06 fichier_1
-r-x----r- 1 user user 0 Sep 23 19:06 fichier_10
-r--r----- 1 user user 0 Sep 23 19:06 fichier_11
-rwxr----- 1 user user 0 Sep 23 19:06 fichier_12
-r-x---r-- 1 user user 0 Sep 23 19:06 fichier_13
-rw---x--- 1 user user 0 Sep 23 19:06 fichier_14

If they meet the criteria g=---, they need to have all their 'other' permissions removed too, but the user permission have to stay the same. In this case, the files would now look like this (The 2nd and the 5nd files lost all 'others' permissions):

 -r--r----- 1 user user 0 Sep 23 19:06 fichier_1
-r-x------ 1 user user 0 Sep 23 19:06 fichier_10
-r--r----- 1 user user 0 Sep 23 19:06 fichier_11
-rwxr----- 1 user user 0 Sep 23 19:06 fichier_12
-r-x------ 1 user user 0 Sep 23 19:06 fichier_13
-rw---x--- 1 user user 0 Sep 23 19:06 fichier_14

I have to only use 1 command, so I can't do them one by one. I tried to use the find and chmod command, but I simply can't seem to make the find command work to find all files with g=--- ( or 000).

My first attempt was this:

$ find /home/mael/tp1_inf1070/World/permissions -type f -perm g=000 -exec chmod o= {} \;

Which gave:

find: invalid mode ‘g=000’

It doesn't work with simply g=--- or just 'g=' either.

If I try to just do the first step,

$ find -perm  'g=000'

I don't get any output.

I could just do:

$ find -perm 700, 600, 400, 707, 704, 706, 707 

To find all the files with no group permission, but then how to apply chmod to those files so that all their 'others' permissions get removed, but their user's permission stays the same?

Any idea on how to proceed? Thanks.

jww
  • 97,681
  • 90
  • 411
  • 885
MaelPJ
  • 115
  • 5

1 Answers1

0

Try out to adopt the following to your needs:

find . -not -perm /g=r -and -not -perm /g=w -and -not -perm /g=x -exec chmod o-rwx {} \;

This should find all files, without group permissions and will remove any permissions for world (others).

mjrtom
  • 1
  • 2