Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binutils stat illegal option -c

I use stat two times in my script once to find the file files permissions and once to find the size of the file.

 `stat -c %A "$directory/$file"`
 `stat -c %s "$directory/$file"`

I am using OSX 10.7 and directory and file are variable of the current directory I am in and the file.

like image 382
Joe Tyman Avatar asked May 19 '12 15:05

Joe Tyman


1 Answers

Darwin stat uses an -f argument, rather than -c, as it is a GNU extension.

You should download the gnu binutils, either from homebrew, from macports or from fink, and then use gstat instead of stat.

If you don't want to install gnu binutils and prefer to stick with the standard BSD tools, then:

stat -f%p t.c

will return the modes (in octal) and

stat -f%z t.c

will return the size.

like image 101
zmo Avatar answered Sep 29 '22 06:09

zmo