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?
-
1Possibly related ls and actual file size without using 'long listing format'steeldriver– steeldriver11/21/2017 00:15:22Commented Nov 21, 2017 at 0:15
-
Related: How do I interpret "total 18" in the output of the "ls -l" command ...? (on Super User), but round up to a multiple of 4096 and divide by 1024.G-Man Says 'Reinstate Monica'– G-Man Says 'Reinstate Monica'11/14/2022 06:49:17Commented Nov 14, 2022 at 6:49
1 Answer 1
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