4

Output of

sudo df -h

is

Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                  9.2G  5.7G  3.1G  65% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                   357M  720K  356M   1% /run
/dev/disk/by-uuid/13605893-3936-4fd6-a7f5-e249f16c3f72  9.2G  5.7G  3.1G  65% /
tmpfs                                                   5.0M  4.0K  5.0M   1% /run/lock
tmpfs                                                   2.2G  2.5M  2.2G   1% /run/shm
/dev/sda6 

                                          278G   12G  252G   5% /home

whereas

sudo du -sh /dev/sd*

gives

0   /dev/sda
0   /dev/sda1
0   /dev/sda2
0   /dev/sda5
0   /dev/sda6

o_O

4 Answers 4

4

Your raw devices are listed in /dev/, but that's not where the file system lives. Once the device is mounted it's available in the mount point, as listed in the "Mounted on" column.

You should run du on or somewhere in a mount point to count the usage on the file system. E.g.:

sudo du -sh /home

What you were doing is asking how much space the device listing is using in the virtual file system /dev. This is nothing, as it's purely virtual.

2

A device like /dev/sda is a special kind of file that can be used to access some kernel functions. You can create devices using mknod.

du treats devices just like any other file and shows the size they are using in the file system which is always 0.

2

I stumbled upon this old thread and for anyone looking for a solution to list the file sizes when "du" gives a 0 size output on a mounted virtual filesystem, just add the "-b" flag. Like so:

du -sbh <path>

The following will also work (which is included in the "-b" flag):

du -sh --apparent-size <path>
1

Well there is a known difference between the free space shown by df vs the amount of drive space minus the space used in du (because of block sizes and overheads and things like that), but that's not what you're asking here...

du works on mounted filesystems. You're trying to get it to work on devices and partitions. If you want to see what the space on a free particular device, loop through its partitions, mount them and then run du with its --one-file-system (aka -x) argument.

Eg:

sudo mount /dev/sda1 /mnt
sudo du -shx /mnt/
sudo umount /mnt/
# repeat for sda2, sdb1, etc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .