Output of stat on OSX – Portability Guide

osxportabilitystat

I want to use the stat command to get information on a file. I did this:

Josephs-MacBook-Pro:Desktop Joseph$ echo 'hello' > info.txt
Josephs-MacBook-Pro:Desktop Joseph$ stat info.txt
16777220 21195549 -rw-r--r-- 1 Joseph staff 0 6 "Dec 21 20:45:31 2014" "Dec 21 20:45:30 2014" "Dec 21 20:45:30 2014" "Dec 21 20:45:30 2014" 4096 8 0 info.txt

The 3rd and 4th lines are the output I got. This happens whenever I use the stat command. Meanwhile everyone on the internet gets stuff like:

File: `index.htm'
Size: 17137 Blocks: 40 IO Block: 8192 regular file
Device: 8h/8d Inode: 23161443 Links: 1
Access: (0644/-rw-r--r--) 
Uid: (17433/comphope) Gid: ( 32/ www)
Access: 2007-04-03 09:20:18.000000000 -0600
Modify: 2007-04-01 23:13:05.000000000 -0600
Change: 2007-04-02 
16:36:21.000000000 -0600

I tried this on Terminal and iTerm 2 and in a fresh session.
On the same laptop, I connected to my CentOS server and put in the same commands. It worked perfectly. This leads me to believe that the terminal application isn't the problem.
I'm on a MacBook Pro (Retina, 15-inch, Late 2013) with OS X Yosemite version 10.10.1

What is going on and how can I fix this?

Best Answer

Using the -x option for stat should give you similar output:

$ stat -x foo
  File: "foo"
  Size: 0            FileType: Regular File
  Mode: (0644/-rw-r--r--)         Uid: (  501/   Tyilo)  Gid: (    0/   wheel)
Device: 1,4   Inode: 8626874    Links: 1
Access: Mon Dec 22 06:17:54 2014
Modify: Mon Dec 22 06:17:54 2014
Change: Mon Dec 22 06:17:54 2014

To make this the default, you can create an alias and save it to ~/.bashrc:

alias stat="stat -x"
Related Question