How to inspect group permissions of a file

I would love to evaluate team permissions of a documents from a bash manuscript. Especially, I require to examine whether a documents has the team writeable little bit on.

That is it. Straightforward as that. However:

  1. I additionally require this to be mobile
  2. test -w <file will not inform me whether it is team writeable
  3. The result of ls -ld behaves for human beings, yet not so certain concerning manuscripts. Technically I could parse result such as drwxrwxr-x to extract the team little bits, yet this appears weak
  4. The user interface for stat is entirely inappropriate in between OS X and also various other systems
  5. find <file> -perm ... can not perhaps be the solution?
2022-07-25 20:39:14
Source Share
Answers: 1

I wound up ls - parsing:

is_group_writable() {
  local ls="$(ls -ld "$1")"
  [ "${ls:5:1}" = "w" ]

I'm happy for @slm is considerable solution, yet none of the various other approaches are as uncomplicated. The stat method would certainly need me to write at the very least 2 various conjurations to cover OS X, and also also afterwards it returns the octal depiction which I still need to use math to. The Perl method is alright yet needs me to start an interpreter for such a straightforward job, and also I would love to maintain it straightforward and also making use of just posix utils.

2022-07-25 22:37:03