M BUZZ CRAZE NEWS
// news

Different metric of file size as output of ls command

By John Parsons

Why is ls command yielding different metric of file size? Example:

haniya@r079008:~/data$ ls -l
total 3948604
-rwxrwxrwx 1 haniya haniya 21254426 Mei 24 19:34 cliente_tabla.csv
-rw-rw-r-- 1 haniya haniya 6167128 Jul 2 02:03 cliente_tabla.csv.zip

If I assume the size is displayed in Byte, why total is given in KB.

While

haniya@r079008:~/data$ ls -s cliente_tabla.csv
20760 cliente_tabla.csv

Now the size is in KB. That makes the information unclear (inconsistent). Is there any way to 'regularize' the metric?

2 Answers

total and ls -s by default print the number of blocks of 1024 bytes or the size defined in BLOCKSIZE or BLOCK_SIZE environment variables.

To "regularize" the units for ls -l output add --block-size argument, for example:

  • for KiB (2^10):

    ls -l --block-size=K
  • for MB (10^6):

    ls -l --block-size=MB
  • You can also specify 1M to display only numbers and skip the unit.

For all units and options refer to the Block Size chapter of GNU docs.

ls -lh

Will list file sizes in human readable format (e.g., 1K 234M 2G)

-rw-r----- 1 syslog adm 68K Aug 19 19:30 syslog

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy