Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to write a shell script in busybox to check the filesize of a file. Having read that stat is more reliable then ls, I decided to use that, but somehow when using the following command:

stat -c %s filename

I get the following output: 559795. This goes for the following 2 files (shown using ls -la):

0 Jan 20 16:32 foo_empty
4 Jan 20 16:32 foo_not_empty

Anyone know what's happening there? I can just go back to using ls, but I'm not understanding what's happening here, and that's bothering me..

share|improve this question
cam you look at the full output of stat with stat foo_empty and verify that the 559795 number appears in the size field and not some other field? – stew Jan 20 '12 at 16:40
File: "foo_not_empty" Size: 559795 Blocks: 559795 IO Block: 4096 regular file Device: 98a7bh/559795d Inode: 559795 Links: 1 Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root) Access: Fri Jan 20 16:32:29 2012 Modify: Mon Jan 23 10:41:06 2012 Change: Mon Jan 23 10:41:06 2012 – datadevil Jan 23 '12 at 9:43

Works for me:

ls -l foo_*
-rw------- 1 fooo users    0 Jan 20 10:30 foo_empty
-rw------- 1 fooo users 3767 Jan 20 10:30 foo_not_empty

busybox stat -c %s foo_empty; busybox stat -c %s foo_not_empty 

Are you using an old version of busybox, possibly on a 64 bit OS? I'm using

BusyBox v1.19.3 (2012-01-03 13:39:53 PST) multi-call binary.
share|improve this answer
a lot older: BusyBox v1.1.1 (2009.12.24-08:39+0000) multi-call binary. Made the non-empty file a lot bigger, assuming that it was some kind of default filesize, but that does not make a difference. – datadevil Jan 23 '12 at 9:39

if stat is reporting the same odd number for filesize, number of blocks, inode, and device. I'd suspect filesystem corruption. You might try fsck and see if it finds/fixes problems.

share|improve this answer
This is over multiple disks, so that'd be very weird... – datadevil Jan 24 '12 at 8:27
not as weird as having 1 byte blocks and inode number that happens to exactly match the number of bytes – stew Jan 24 '12 at 14:23

You can also use du to check file size. du -h will provide you with a "human readable" output.

share|improve this answer
This is a good idea, but is not really answering the OP's question. – EEAA Jan 20 '12 at 16:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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