Recently I tried to find out the size of a file using various command and it showed huge differences.
ls -ltr
showed its size around 34GB (bytes rounded off by me ) while
du -sh filename showed it to be around 11GB. while
stat command showed the same to be around 34GB .
Any idea which is the most reliable command to find actual size of the file ?
There was some copy operation performed on it and we are unsure of if this was appropriately done as after a certain time source file from where copy was being performed was removed by a job of ours.
Using the ls Command –l – displays a list of files and directories in long format and shows the sizes in bytes. –h – scales file sizes and directory sizes into KB, MB, GB, or TB when the file or directory size is larger than 1024 bytes. –s – displays a list of the files and directories and shows the sizes in blocks.
Click the file or folder. Press Command + I on your keyboard. A window opens and shows the size of the file or folder.
The size command in Linux is a very important command that will allow to list the section size and the total size of the object files or the archived files in its argument list. When we do not specify the object file in the parameter list, then by default, 'a. out' file is used.
don't worry we have a got a UNIX command to do that for you and command is "df" which displays the size of the file system in UNIX. You can run "df" UNIX command with the current directory or any specified directory.
There is no inaccuracy or reliability issue here, you're just comparing two different numbers: logical size vs physical size.
Here's Wikipedia's illustration for sparse files:
ls
shows the gray+green areas, the logical length of the file. du
(without --apparent-size
) shows only the green areas, since those are the ones that take up space.
You can create a sparse file with dd count=0 bs=1M seek=100 of=myfile
.
ls
shows 100MiB because that's how long the file is:
$ ls -lh myfile
-rw-r----- 1 me me 100M Jul 15 10:57 myfile
du
shows 0, because that's how much data it's allocated:
$ du myfile
0 myfile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With