Need help with du output interpretation

On Ubuntu 18.04 I was checking on my log sizes using du -sh and I can't quite understand what du tells me, please see my screen snippet below:

# I am in the logs directory and show total number of bytes (5th column in my ls-l output is file size in bytes)
logs$ ls -l |awk '{tot+=$5;} END{ print tot}'  
8333848518
# I moved one level up and use du -s feature to show total disk space occupied by logs directory (slight discrepancy with above as the logs are being written into all the time):
logs$ cd ..
service$ du -sb logs
8334585063      logs
# the same but in "humanly readable" format, which I tend to use most often
service$ du -sh logs
1.4G    logs
# or in megabytes:
service$ du -sm logs
1381    logs

I'd expect to see 7.75G, why du shows me this number?

man du refers to several environment variables it depends on, none of them are set:

service$ echo $DU_BLOCK_SIZE, $BLOCK_SIZE, $BLOCKSIZE, $POSIXLY_CORRECT  
, , ,

Any pointers would be appreciated.

But it does:

[~] 0 $ echo 8333848518 | awk '{print ($1 / 1024 / 1024 / 1024)}'
7.7615

Hope this helps :slight_smile:

EDIT:

The only coherent output is between -m and -h, with -b beeing WAY more...

EDIT 2:

On second thought... filesize and used diskspace are 2 incredible different things!
If you have say a (ok i might fail on the proper terminology) cluster size of 64kb, and say 10 logfiles of 1kb each.. each uses a 'full' cluster.

So they have only a size of 10kb, but use diskpace of 640kb.

Then again... it was 'proper' using -sb, so I dont know..

Well, I'm sorry but gn8, its 2am here :wink: :stuck_out_tongue:

man du says -b is apparent size that can differ from the block size.
Do you have a "core" file or other sparse file there?

No core files, only plain textual log files created by out application using log4j

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.