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..
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.
Works for me:
Are you using an old version of busybox, possibly on a 64 bit OS? I'm using
In my case,
stat
is missing from thebusybox
(embedded system). For me, performance isn't an issue, so I ended up withfile_size="$(wc -c ./this-file)"
.You can also use
du
to check file size.du -h
will provide you with a "human readable" output.