I am running Ubuntu 11.04 and I am wondering how to find the size of the size of the allocation unit ? Is there a command in Ubuntu to find this? Also depending on the size of the allocation unit does the total amount of hard disk space used a file change? I have checked the file sizes using ls and du -b and in both the cases I am getting the same values.

Including data:

 sudo tune2fs -l <file system> 
  Block count:              8052736
  Reserved block count:     402636
  Free blocks:              2797402
  First block:              0
  Block size:               4096
  Reserved GDT blocks:      1022
  Blocks per group:         32768
   Inode blocks per group:   512
  Flex block group size:    16
  Reserved blocks uid:      0 (user root)
  Reserved blocks gid:      0 (group root)
  Journal backup:           inode blocks

So, if the block size is 4096 bytes, files which are smaller than 4096 occupy 4096 bytes of storage on the hard disk, what about files which are larger than 4096 bytes how much space do they occupy? Is there a command to find the same?

  • 1
    Do you mean the block size? If so, this command will give it to you: tune2fs -l /dev/sda1 | grep Block... Replace /dev/sda1 with the appropriate partition identifier, of course.
    – SirCharlo
    Commented Mar 15, 2012 at 14:38
  • @SirCharlo Yes, it was the block size that I was looking for and I found that using the tune2fs command, but what i am wondering is since the block size is 4096 bytes, files which are smaller than 4096 bytes will occupy 4096 bytes of space on the hard disk, but what about file sizes which are greater than this?
    – bhavs
    Commented Mar 15, 2012 at 14:45
  • @aking1012 any way for me to find out exactly how much of space ?
    – bhavs
    Commented Mar 15, 2012 at 14:49

2 Answers 2


Top post edit:
Pre-emptively find size:

temp = int(size/block)  
if mod(size/block) != 0:  
    temp += 1
temp = temp*block
print temp

to know how many blocks a file has on disk:

ls -s

where block-size is the partition block size
and size on disk is block-size * number of blocks

Explanation about block size terminology differences
sudo fdisk -l /dev/sda
where /dev/sda is the hard disk in question

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c1f6b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63      498014      248976   83  Linux
/dev/sda2          498015   976768064   488135025    5  Extended
/dev/sda5          498078   976768064   488134993+  83  Linux
This tells you several things. Somebody else already said it better so blockquote:

The problem with this is that there are four distinct units that you must be keeping in mind. To make things even worse, two of these units bear the same name. These are the different units:

  1. Hardware block size, "sector size"
  2. Filesystem block size, "block size"
  3. Kernel buffer cache block size, "block size"
  4. Partition table block size, "cylinder size"

To differentiate between the filesystem block size and the buffer cache block size, I will follow FAT terminology and use "cluster size" for the filesystem block size.

The sector size is the units that the hardware deals with. This ranges between different hardware types, but most PC-style hardware (floppies, IDE disks, etc.) use 512 byte sectors.

The cluster size is the allocation unit that the filesystem uses, and is what causes fragmentation - I'm sure you know about that. On a moderately sized ext3 filesystem, this is usually 4096 bytes, but you can check that with dumpe2fs. Remember that these are also usually called "blocks", only that I refer to them as clusters here.

The cluster size is what gets returned in st_blksize in the stat buffer, in order for programs to be able to calculate the actual disk usage of a file.

The block size is the size of the buffers that the kernel uses internally when it caches sectors that have been read from storage devices (hence the name "block device"). Since this is the most primitive form of storage in the kernel, all filesystem cluster sizes must be multiples of this. This block size is also what is almost always referred to by userspace programs. For example, when you run "du" without the -h or -H options, it will return how many of these blocks a file takes up. df will also report sizes in these blocks, the "Blocks" column in the fdisk -l output is of this type, and so on. It is what is most commonly referred to as a "block". Two disk sectors fit into each block.

The cylinder size is only used in the partition table and by the BIOS (and the BIOS isn't used by Linux).

"df" only operates on filesystems, so, no, it can't be used without a filesystem - without a filesystem, the data that it would return doesn't exist. "du" operates on individual files.

from here.

  • thanks for the wonderful explanation, I would then like to understand the difference between the ls -l and du output because both of them return the same numbers?
    – bhavs
    Commented Mar 15, 2012 at 14:53
  • I'm pretty sure this has gone long enough. You have an answer to your original query Commented Mar 15, 2012 at 15:12
  • well it is clear that i am supposed to use du, shall go ahead and use that thanks for all ur help but was wondering a loud if ls and du display different data or the same data, shall raise another question for this if need be
    – bhavs
    Commented Mar 15, 2012 at 16:13
  • 1
    @bhavs - not trying to be ugly, but it's a Q&A board, not a discussion forum. you asked a load of questions, I more than answered. in fact, in the FAQ askubuntu.com/faq it tells you very specifically one question at a time. Commented Mar 15, 2012 at 18:07
  • thanks will remember just got carried away with the information exchange !!
    – bhavs
    Commented Mar 16, 2012 at 3:38

stat command executed with a mount point as a parameter, shows filesystem's cluster size under IO Block property

stat /dev/shm/minifs-mounted

will show

  File: /dev/shm/minifs-mounted
  Size: 1024            Blocks: 2          IO Block: 1024   directory
Device: 709h/1801d      Inode: 2           Links: 3
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-12-27 14:03:15.000000000 -0300
Modify: 2022-12-27 14:01:50.000000000 -0300
Change: 2022-12-27 14:01:50.000000000 -0300
 Birth: -

above info belongs to a filesystem created with

cd /dev/shm
dd if=/dev/zero bs=1M count=100 of=minifs.img
mkfs.ext4 -b 1024 ./minifs.img
mount -o loop minifs.img minifs-mounted

forcing 1024 bytes long cluster

You must log in to answer this question.

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