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
57.9k27 gold badges154 silver badges236 bronze badges
asked Nov 20, 2017 at 23:55
2

1 Answer 1

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

answered Nov 21, 2017 at 0:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.