So, I want to quickly get the group ID (GID) of a file using the shell (more accurately, the GID of the owner of the file).

Somewhere in my shell script, I have the following code:

stat -c "%g" foo.txt

In every Linux I have tried, the above works perfectly.

However on Mac OS X, I get: stat: illegal option -- c usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]

How can I get the GID of a file on MacOS X with a shell command? Preferably something that also works on Linux, but I am okay with introducing an if-else if needed.

Your Answer

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

Browse other questions tagged or ask your own question.