Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is the output of `du` often so different from `du -b`

why is the output of du often so different from du -b? -b is shorthand for --apparent-size --block-size=1. only using --apparent-size gives me the same result most of the time, but --block-size=1 seems to do the trick. i wonder if the output is then correct even, and which numbers are the ones i want? (i.e. actual filesize, if copied to another storage device)

like image 994
knittl Avatar asked Apr 17 '11 16:04

knittl


People also ask

Why du and df show different results?

The result of the command du doesn't include the size of the deleting file. But the result of the command df includes the size of the deleting file due to its disk space is not released immediately. So after deleting the file, the results of df and du are different until the disk space is released.

What is the output of du?

To utilize the basic usage of the du command, simply open a terminal window, type du, and hit Enter. The output displays each directory's disk usage and path, along with the total disk usage of the parent directory.

What is the purpose of du and df commands and how they are different from each other?

The (very complicated) answer can be best summarized like this: The df command provides a sweeping ballpark figure for how much space is being utilized on your filesystem as a whole. The du command is a much more accurate snapshot of a given directory or subdirectory.

Why does df show bigger disk usage than du?

Details. What is most likely happening is that a process is running which is holding open a file which has been deleted. df thinks that the partition is full since the inodes are all taken up by that process. This often happens when a service such as samba has filled up the log file.


1 Answers

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. It's also the result of cat theFile | wc -c, and the amount of address space that the file would take up if you loaded the whole thing using mmap.

Disk usage is the amount of space that can't be used for something else because your file is occupying that space.

In most cases, the apparent size is smaller than the disk usage because the disk usage counts the full size of the last (partial) block of the file, and apparent size only counts the data that's in that last block. However, apparent size is larger when you have a sparse file (sparse files are created when you seek somewhere past the end of the file, and then write something there -- the OS doesn't bother to create lots of blocks filled with zeros -- it only creates a block for the part of the file you decided to write to).

like image 174
Ken Bloom Avatar answered Oct 20 '22 22:10

Ken Bloom