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.zipIf 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.csvNow 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=Kfor MB (10^6):
ls -l --block-size=MBYou can also specify
1Mto display only numbers and skip the unit.
For all units and options refer to the Block Size chapter of GNU docs.
ls -lhWill list file sizes in human readable format (e.g., 1K 234M 2G)
-rw-r----- 1 syslog adm 68K Aug 19 19:30 syslog