Output of stat on OSX
Solution 1
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"
Solution 2
The stat
command that you saw from “everyone on the internet” is the one from GNU coreutils, which is found on non-embedded Linux and Cygwin. It could also be the one from BusyBox, which is commonly found on embedded Linux. OSX has a different stat
utility (the one from FreeBSD/NetBSD/OpenBSD), with a similar purpose but different options and a different output format.
The stat
command isn't standardized, so you can't expect it to have the same behavior on all Unix variants. In practice, there's BSD stat, and Linux stat, and many other variants don't have a stat
command.
Related videos on Youtube
Gilles 'SO- stop being evil'
Updated on September 18, 2022Comments
-
Gilles 'SO- stop being evil' over 1 year
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?
-
Stéphane Chazelas over 8 yearsNote that's there's no
Linux
stat
(unless you're refering toLinux
stat() system call), just GNUstat
from GNU coreutils. -
Stéphane Chazelas over 8 yearsIRIX also had a
stat
command long before the GNU or BSD ones.zsh
also had astat
builtin long (though not as long) before GNU and BSD ones. -
ahmet alp balkan over 5 yearsOn zsh, for some reason
stat
is a shell-built in and masks the actual stat command. Any ideas how to disable this? (I have GNU coreutils installed on my macOS, but zsh prevents me from using it).