1

So basically I need to list files in sub directory which has all permission for user and group but not other. Basically rwxrwx---

All I got is:

 ls -d */*

to show the sub directories but now how do I the permission part, I know I need to use "|" but what command do I do?

Thanks!

  • this might be an opportunity for the find command... – Jeff Schaller Feb 14 '16 at 2:36
  • The only way I know how to use the find command is with the numbers but I wanna use the letters(eg. rwxrwx---) – shawn edward Feb 14 '16 at 2:38
  • see the man page for find or search here for examples – Jeff Schaller Feb 14 '16 at 2:48
  • yeah but what would I put in between "find" and the "-perm" I try putting / but I get dont get the sub directory – shawn edward Feb 14 '16 at 2:55
4

You should use the find command. To get all files and directories with rwxrwx--- in the branch of current directory use:

find . -perm 770

If you only need to check for files:

find .  -type f -perm 770

If you only need to check the immediate subdirectories (in FreeBSD/OSX):

find . -depth 2 -perm 770

or Linux:

find . -mindepth 2 -maxdepth 2 -perm 770
  • how would you do it for any permission for user and group. Not all permission but any permission – shawn edward Feb 14 '16 at 3:55
  • Did you test the third variant? I don't think -depth means what you think it means. You could use -mindepth 2 instead (and add -maxdepth 2 if you don't want to descend further - or alternatively change the path to ./* and just use -maxdepth 1) – steeldriver Feb 14 '16 at 13:22
  • @steeldriver Interesting... Of course I tested, but seems it might be a FreeBSD option -depth n True if the depth of the file relative to the starting point of the traversal is n. – techraf Feb 14 '16 at 13:26
  • Ah I didn't know that - thanks for clarifying. – steeldriver Feb 14 '16 at 13:31
  • @shawnedward If you mean a check for effective permissions with those applied via group membership and/or ACLs, then find has options for -executable, -readable, -writable. You can check with sudo -u user_name find . -readable -or -writable -or -executable. – techraf Feb 14 '16 at 14:10

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.