Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get group ID (GID) of a file in Mac OS X via a shell command. What is the equivalent of stat -c "%g" <filename> for Mac OS X?

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.

like image 358
user1942541 Avatar asked Oct 26 '25 00:10

user1942541


1 Answers

The equivalent on OS X is stat -f "%g" foo.txt.

like image 179
anthony Avatar answered Oct 27 '25 15:10

anthony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!