Linux-like stat in FreeBSD

The default output of the stat command in FreeBSD was completely different from what I got used to in Linux. For example:

linux% stat /boot/vmlinuz-linux 
  File: ‘/boot/vmlinuz-linux’
  Size: 3269840         Blocks: 6416       IO Block: 1024   regular file
Device: 801h/2049d      Inode: 12          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-08-28 23:35:55.000000000 +0300
Modify: 2012-08-26 11:19:01.000000000 +0300
Change: 2012-08-28 23:35:47.000000000 +0300
 Birth: -

vs

freebsd% /usr/bin/stat /boot/boot0
1149243074 13 -r--r--r-- 1 root wheel 0 512 "Jul 12 18:52:22 2012" "Mar  2 10:39:17 2011" "Feb 11 16:24:47 2012" "Feb 11 16:24:47 2012" 4096 2 0 /boot/boot0

Found it hard to read, I made some use of the -f argument to get it uniformed. Here’s the alias I use and the new output:

freebsd% alias stat="/usr/bin/stat -f \"  File: '%N'%SY%n  Size: %-15z Blocks: %-10b IO Block: %-6k %HT%nDevice: %7Hr/%-7Lr Inode: %-11i Links: %l%nAccess: (%Mp%Lp/%Sp) Uid: (%5u/%8Su)  Gid: (%5g/%8Sg)%nAccess: %Sa%nModify: %Sm%nChange: %Sc%n Birth: %SB\" -t '%F %T %z'"

freebsd% stat /boot/boot0
  File: '/boot/boot0'
  Size: 512             Blocks: 2          IO Block: 4096   Regular File
Device:       0/0       Inode: 13          Links: 1
Access: (0444/-r--r--r--) Uid: (    0/    root)  Gid: (    0/   wheel)
Access: 2012-07-12 18:52:22 +0000
Modify: 2011-03-02 10:39:17 +0000
Change: 2012-02-11 16:24:47 +0000
 Birth: 2012-02-11 16:24:47 +0000

Looks much better huh?

4 thoughts on “Linux-like stat in FreeBSD

Leave a comment