What is the most reliable command to find the actual linux file size

I recently tried to figure out the file size using various commands, and it showed huge differences.

ls -ltrshowed a size of about 34 GB (bytes rounded by me), while du -sh filename showed that it was about 11 GB. while the stat command showed that it is about 34 GB. Any idea which is the most reliable team for finding the actual file size?

Some copy operation was performed, and we are not sure that this was done properly, because after a certain time source file from which the copy was executed was deleted by our work.

+4
source share
3 answers

, : .

:

Sparse files

ls + , . du ( --apparent-size) , , .

dd count=0 bs=1M seek=100 of=myfile.

ls 100MiB, , :

$ ls -lh myfile
-rw-r----- 1 me me 100M Jul 15 10:57 myfile

du 0, :

$ du myfile
0 myfile
+10

, guiy wikipage .

ls (1) stat (1).

C, stat (2) lseek (2) syscalls.

. .

+2
ls -l --block-size=M

( ) MiB.

MB (10 ^ 6 ), MiB (2 ^ 20 ), --block-size=MB.

, M, , - --block-size=1M. Stéphane Chazelas .

This is described on the manual page for ls; man lsand find SIZE. It also allows you to use units other than MB/MiB, and from the appearance (I also haven’t tried) of arbitrary block sizes (so you could see the file size as the number of blocks 412 bytes in size if you want to).

Note that the parameter --block-sizeis a GNU extension on top of the Open Group ls, so this may not work if you do not have a custom GNU field (which most Linux installations do). Ls from GNU coreutils 8.5 supports --block-sizeas described above.

+1
source

Source: https://habr.com/ru/post/1598086/


All Articles