Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is du command showing double size when h flag is sent?

Tags:

shell

unix

du

I want to check the total size of a git repository. Is funny that du is giving me two different kind of sizes when the -h flag is sent. It is actually giving double size.

Why is this? What is the correct size?

MyMac:~/repositories/my-repo.git davidrod$ du -h
  0B    ./branches
 64K    ./hooks
4.0K    ./info
  0B    ./objects/info
3.3M    ./objects/pack
3.3M    ./objects
4.0K    ./refs/heads
8.0K    ./refs/tags
 12K    ./refs
3.3M    .
MyMac:~/repositories/my-repo.git davidrod$ du 
0   ./branches
128 ./hooks
8   ./info
0   ./objects/info
6672    ./objects/pack
6672    ./objects
8   ./refs/heads
16  ./refs/tags
24  ./refs
6856    .
like image 767
David Rz Ayala Avatar asked May 11 '14 23:05

David Rz Ayala


People also ask

How do you sort the output of du by size?

How can I sort du outputs by size on macOS or FreeBSD? You can pass the -h or --human-numeric-sort option to the sort command to sort and compare human readable numbers such as 2K, 300M, 1G and more. This is a new option added the gnu/sort command.

What size does du output?

du computes file space in units of 512 bytes. The actual disk space used by files and directories may be more, since some systems allocate space in units of some multiple of a sector. On UNIX System V, it is usually two sectors; on UNIX Version 7, it is one sector.

What is du apparent size?

Apparent size is the number of bytes your applications think are in the file. It's the amount of data that would be transferred over the network (not counting protocol headers) if you decided to send the file over FTP or HTTP.

How does du command work?

The du command is a standard Linux/Unix command that allows a user to gain disk usage information quickly. It is best applied to specific directories and allows many variations for customizing the output to meet your needs. As with most commands, the user can take advantage of many options or flags.


1 Answers

The size on OSX (which I assume you have from the computer name) is calculated on 512-byte blocks because the BSD version of du is used (other versions, like the Cygwin's one I am using now on Windows, behave differently).

So for every 1K you get two blocks, apparently doubling the value of every size.

like image 144
Cranio Avatar answered Oct 21 '22 20:10

Cranio