ogham / exa

A modern replacement for ‘ls’.
https://the.exa.website/
MIT License
23.54k stars 664 forks source link

file size is different from du or ls #1108

Closed Dantesferio closed 2 years ago

Dantesferio commented 2 years ago

when using exa with -l flag it show the file sizes but the sizes are different from output of lsor du commands: version: v0.10.1 [-git] OS: ubuntu 22.04.1 arch: x86_64

exa output: ➜ /backup exa -l .rw-rw-r-- 900M rebin-sama 15:22 Config_Backup_2022-08-17.tar.gz .rw-rw-r-- 2.4G rebin-sama 01:45 fonts.tar.gz .rw-rw-r-- 6.7k rebin-sama 21:25 nvim-config-backup.tar.gz

ls output: ➜ /backup /bin/ls -l -h total 3.1G -rw-rw-r-- 1 rebin-sama rebin-sama 859M 15:22 Config_Backup_2022-08-17.tar.gz -rw-rw-r-- 1 rebin-sama rebin-sama 2.2G 01:45 fonts.tar.gz -rw-rw-r-- 1 rebin-sama rebin-sama 6.6K 21:25 nvim-config-backup.tar.gz

du output: ➜ /backup du -a -h 2.2G ./fonts.tar.gz 8.0K ./nvim-config-backup.tar.gz 859M ./Config_Backup_2022-08-17.tar.gz 3.1G .

eggbean commented 2 years ago

exa is using decimal prefixes by default. To use SI unit prefixes correctly, a kilobyte (KB) is actually 1,000 bytes, a megabyte (MB) is 1,000 kilobytes and a gigabyte (GB) is 1,000 megabytes, etc.

Hard disk drives were/are measured this way which caused increasing confusion as they got larger. In networking megabits is often used, which is 1,000 bits, not 1024.

ls uses binary prefixes by default, but to be more accurate, they should be called kibibyte (KiB), mebibyte (MiB), gibibyte (GiB), etc. exa calls them what they really are in modern, accurate engineering terms.

To have exa use binary units, add the -b switch and to have ls use decimal units, use the --si switch.

Most people are actually unaware of this or don't care, but for serious and accurate engineering it's better to use the proper units when it's important to get things right.

https://en.wikipedia.org/wiki/Binary_prefix