The formatting character %s makes stat print the filesize in bytes

# stat -c'%A %h %U %G %s %n' /bin/foo
-rw-r--r-- 1 root root 45112 /bin/foo 

ls can be configured to print the byte size number with "thousand-separator", i.e. 45,112 instead of the usual 45112.

# BLOCK_SIZE="'1" ls -lA 
-rw-r--r-- 1 root root 45,112 Nov 15  2014

Can I format the output of stat similarly, so that the file size has thousand-separator?

The reason why I am using stat in the first place is, I need to output like ls, but without time, therefore -c'%A %h %U %G %s %n'.

Or is there some other way to print the ls-like output without the time?

  • On what operating system? Should we assume Linux? – terdon Jun 2 '15 at 9:07

Specify the date format, but leave it empty eg.

ls -lh --time-style="+"


-rwxrwxr-x 1 christian christian 8.5K  a.out
drwxrwxr-x 2 christian christian 4.0K  sock
-rw-rw-r-- 1 christian christian  183  t2.c
| improve this answer | |

On a GNU system, you can use the ' flag of GNU printf:

$ stat -c"%A %h %U %G %'s %n" /bin/foo  
-rw-r--r-- 1 root root 45,112 /bin/foo 

This is documented in man 3 pritnf:

'      For decimal conversion (i, d, u, f, F, g, G) the output is to be grouped
       with  thousands'  grouping  characters if the locale information indicates
       any. Note that many versions of gcc(1) cannot parse this option and will 
       issue a warning.  (SUSv2 did not include %'F, but SUSv3 added it.)

Alternatively, you can parse it in yourself:

$ stat --printf="%A\t%h\t%U\t%G\t%s\t%n\n" a | rev | 
    awk '{gsub(/.../,"&,",$2); print}' | rev
-rwxr-xr-x 2 terdon terdon 4,096 file
| improve this answer | |
  • Wow! I learnt something new today! – user86969 Jun 2 '15 at 9:23
  • Please replace 4,5112 by 45,112 - thousands are separated, not ten thousands. – Ned64 Jun 2 '15 at 11:49
  • @Ned64 thanks. Obviously, I wrote that one manually :) – terdon Jun 2 '15 at 11:52
  • @terdon It was also wrong in the original question, which I edited (might still be under review). – Ned64 Jun 2 '15 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.