72

I wanted to know what the unit (bytes, bits, kb) of the output of the ls -l command in Linux is.

Here is an example of what I've got:

-rw-rw-r--    1 guest    guest       39870 Feb 14 19:41 ser_cat
-rw-r--r--    1 guest    guest       19935 Feb 14 19:35 ser_cp
-rw-rw-r--    1 guest    guest       19935 Feb 14 19:29 ser_more

What is the unit of 39870 (the size of ser_cat)?

Matthias Braun
  • 1,162
  • 1
  • 17
  • 29
anonymite
  • 834
  • 1
  • 6
  • 10

2 Answers2

101

That size is in bytes.

You can use ls -lh to print the long listing with human readable file sizes.

juil
  • 477
  • 2
  • 5
  • 12
ThePosey
  • 1,156
  • 1
  • 8
  • 4
  • 22
    Just a note on the units: ls -h gives 1K (1024 bytes). ls --si gives 1k (1000 bytes). – Thomas Bratt May 29 '15 at 13:37
  • @ThomasBratt Are you sure? On Debian 10 here, `-h` seems to give decimal SI units (Gigabytes, Megabytes and Kilobytes). `exa` shows the same figures/units by default and I get the binary units (Gibibytes, Mebibytes and Kibibytes), resulting in smaller integers, using the `-b` switch. – paradroid May 12 '20 at 13:18
4

We need to add l (long listing option) to show human-readable file sizes (ls -lh). In your case, size of file ser_cat is in 39870 bytes.

-rw-rw-r--    1 guest    guest       39870 Feb 14 19:41 ser_cat
-rw-r--r--    1 guest    guest       19935 Feb 14 19:35 ser_cp
-rw-rw-r--    1 guest    guest       19935 Feb 14 19:29 ser_more

ls -lh command shows all file size information as K for Kibibyte (KiB), M for Mebibyte (MiB) and so on. See this for the difference between kibi and kilo.

Instead of bits they show information in bytes.

ls -lh shows unit (size) information using single character instead of two characters. If no unit information is there, then it means bytes.

Baha
  • 153
  • 1
  • 4
  • 3
    The units for -h are actually Kibibytes and Mebibytes, not Kilobytes and Megabytes. If you want Kilobytes and Megabytes, use `--si` instead. – Ajedi32 May 16 '16 at 21:28
  • Updated post to reflect @Ajedi32 point. , Refer [http://superuser.com/questions/287498/what-is-the-difference-between-a-kibibyte-a-kilobit-and-a-kilobyte][post] to understand Differences between KiB and KB – Baha Oct 04 '16 at 07:41