0

I set up a file server with samba and I'm copying files to it from another computer under the same LAN. I set up SSH server and connected to it with my phone to monitor the process.

This is what I run on my phone in OpenSSH client (the server has GNU Core Utilities installed):

# while :; do du -sh /media/samba; sleep 1; done
288M    /media/samba
289M    /media/samba
290M    /media/samba
...
^C
# while :; do du -sb /media/samba; sleep 1; done
328267292       /media/samba
328267292       /media/samba
328267292       /media/samba
... ...
(repeated ~30 times)
361334588       /media/samba
361334588       /media/samba
... ...
(repeated ~30 times)
403280532       /media/samba
403280532       /media/samba
^C
#

The computer (running Windows 10) reports a transfer speed of approx. 1000KB/s and all files are 30~35 MB in size.

From my observation, du is reporting file size with -h, but "occupied space" with -b.

So why does du report different sizes when a file is growing?
How does du handle options -h and -b?

0

The difference is the flag

-h is for human readable output which is going use megabytes -bis using bytes. And of course -s is for summarize

From the du man page

-b --bytes Print sizes in bytes, overriding the default block size (*note Block size::).

-h --human-readable Append a size letter such as 'M' for megabytes to each size. Powers of 1024 are used, not 1000; 'M' stands for 1,048,576 bytes. Use the '-H' or '--si' option if you prefer powers of 1000.

-s --summarize Display only a total for each argument.

So in your first call du -sh it it summarizing the total in a human readable form using megabytes to the power of 1024.

In your second call du -sb it is summarizing the argument using bytes.

  • Sorry but my question is not that. I'll update it. – iBug Jul 9 '17 at 3:31
  • I guess I'm not understanding your question. Assuming /media/samba is a folder, du is reporting the size of the folder every time it's ran, if you are transferring files to the folder, it is growing, which is why du is reporting the size increasing. There's no difference in the outputs other than one is in megabytes and one is in bytes. And for "why does it report different sizes while it's growing" why wouldn't it? It's growing, if you add a 35 mb file it's going to reflect the extra 35mb. File size and occupied space are one in the same. The size of the file is occupying x amount of space. – nullmeta Jul 9 '17 at 5:18
  • I mean, du -sh reports a growing size when a file is being written to, but du -sb reports grows only when a new file is created and started writing. – iBug Jul 9 '17 at 5:43

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.