3

Here's the result of running ls -l in a directory

total 28
-rwxrw-r-- 1 pr3t3nd pr3t3nd  188 Nov 20 20:28 exo1.sh
-rwxrw-r-- 1 pr3t3nd pr3t3nd  202 Nov 20 20:52 exo2_fonction.sh
-rwxrw-r-- 1 pr3t3nd pr3t3nd  176 Nov 20 20:30 exo2.sh
-rw-rw-r-- 1 pr3t3nd pr3t3nd  364 Nov 20 22:24 file
-rw-rw-r-- 1 pr3t3nd pr3t3nd 2912 Nov 20 23:47 file2
drwxrwxr-x 2 pr3t3nd pr3t3nd 4096 Nov 20 23:35 rep
-rwxrw-r-- 1 pr3t3nd pr3t3nd  102 Nov 20 23:45 script.sh

Here's the result of running ls -s in the same directory

total 28
4 exo1.sh           4 exo2.sh  4 file2  4 script.sh
4 exo2_fonction.sh  4 file     4 rep

Why the size of all files is 4?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

5

ls -l displays the file size in the 5th column. ls -s does not display the file size. What it displays is the allocated size. That's not the same thing.

The size of a file is a property of the file. It's the number of bytes that constitute the file's content, no more, no less.

The allocated size of a file is a property of how the file is stored. In most cases, the allocated size is slightly larger than the size, because filesystems divide the space in blocks and the allocated size is the total size of the blocks that are used to store the file. Unless the size of the file is a multiple of the block size, there will be a block that is not used in full.

You're seeing files whose size is less than 4kB and whose allocated size is exactly 4kB. This is very common: you have a filesystem with a 4kB block size.

See also When does `ls -s` print "0" and file block size - difference between stat and ls