LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   size of linux folder differs (https://www.linuxquestions.org/questions/linux-newbie-8/size-of-linux-folder-differs-871464/)

dinakumar12 03-28-2011 09:38 AM

size of linux folder differs
 
Hi all,

I checked the folder size in my machine by running " du -sh foldername"

in my terminal i got an output of 98M

i checked the folder size graphically by right clicking the folder and checked with properties.

it showed 83M which one is right.

I am confused. Your suggestions please.

tommylovell 03-28-2011 12:25 PM

I don't know the answer definitively, but since no one else has responded, here's my 2¢.

They are probably both right. It's just a definition of what "right" is.

Things to consider.

Is 1K equal to 1,000 or 1024? Is 1M equal to 1,000,000 or 1048576?
The answer is probably 1024 and 1048576. You see this nonsense mostly with disk sizes, not with files within filesystems.

If there are subdirectories, I would guess there is also directory overhead as well to account or not account for. This is probably negligible, and also probably not a factor.

Is the total the sum of the individual file sizes, or the total of each file's disk space usage?

A small example using a directory I have called "sparse" that contains sparse files.

Code:

[root@athlonz ~]# du -sh sparse
1.1G    sparse

[root@athlonz ~]# du -sh --apparent-size sparse
3.1G    sparse

[root@athlonz sparse]# ls -sl
total 1049720
    16 -rwxrwxr-x 1 root  root      15621 2010-09-27 22:44 ff
    12 -rw-r--r-- 1 root  root        9813 2010-09-27 22:44 ff.c
    16 -rwxrwxr-x 1 root  root      14802 2010-09-27 17:41 filefrag
    12 -rw-r--r-- 1 15806 15806      9676 2010-05-13 19:00 filefrag.c
      4 -rw-r--r-- 1 root  root        1383 2010-09-27 22:31 hexprint.h
1049604 -rw-r--r-- 1 root  root  1073741824 2010-09-27 17:46 nonsparsefile
    12 -rwxrwxr-x 1 root  root        8553 2010-09-23 15:55 sparse
      8 -rwxrwxr-x 1 root  root        8100 2010-09-23 16:05 sparse2
      4 -rw-r--r-- 1 root  root        1118 2010-09-23 16:05 sparse2.c
      4 -rw-r--r-- 1 root  root        2820 2010-09-23 15:55 sparse.c
    16 -rw-r--r-- 1 root  root  1073741824 2010-09-23 15:55 sparsefile
    12 -rw-r--r-- 1 root  root  1073741824 2010-09-23 16:05 sparsefile2

[root@athlonz sparse]# ls -sl --block-size=4096
total 262430
    4 -rwxrwxr-x 1 root  root      4 2010-09-27 22:44 ff
    3 -rw-r--r-- 1 root  root      3 2010-09-27 22:44 ff.c
    4 -rwxrwxr-x 1 root  root      4 2010-09-27 17:41 filefrag
    3 -rw-r--r-- 1 15806 15806      3 2010-05-13 19:00 filefrag.c
    1 -rw-r--r-- 1 root  root      1 2010-09-27 22:31 hexprint.h
262401 -rw-r--r-- 1 root  root  262144 2010-09-27 17:46 nonsparsefile
    3 -rwxrwxr-x 1 root  root      3 2010-09-23 15:55 sparse
    2 -rwxrwxr-x 1 root  root      2 2010-09-23 16:05 sparse2
    1 -rw-r--r-- 1 root  root      1 2010-09-23 16:05 sparse2.c
    1 -rw-r--r-- 1 root  root      1 2010-09-23 15:55 sparse.c
    4 -rw-r--r-- 1 root  root  262144 2010-09-23 15:55 sparsefile
    3 -rw-r--r-- 1 root  root  262144 2010-09-23 16:05 sparsefile2

If you totalled the file sizes it comes to 3,221,297,358.

If you got the properties of directory 'sparse' in Nautilus it says "Contents: 12 items, totalling 3.0 GB".

On disk it is 1.1GB. These two lines tell you a lot.
Code:

    16 -rw-r--r-- 1 root  root  1073741824 2010-09-23 15:55 sparsefile
    12 -rw-r--r-- 1 root  root  1073741824 2010-09-23 16:05 sparsefile2

Each of these files is logically 1GB, but they take up 16KB and 12KB respectively.

Since the Block Size of my filesystem is 4K, non-sparse files on disk are rounded up to a multiple of 4K; but on the other hand, if it is a sparse file, it can be smaller in size on disk than its apparent size as shown above.

So, which one is right?

toordog 03-28-2011 02:58 PM

DELETED.
My post was redundant and useless.

MTK358 03-28-2011 03:36 PM

Quote:

Originally Posted by toordog (Post 4306707)
My post is redundant in the end. I wanted to delete it but can't find how.

You cannot delete posts here. You can edit them to say "deleted" and/or to explain the reason for deletion, though.

dinakumar12 03-29-2011 06:20 AM

hi tommylovell,

Thanks for your reply.

My doubt is which value is the exact or the real one.

The one which we get by executing du -sh command or the value which got graphically by clicking on folder's properties.

toordog 03-29-2011 10:48 AM

Quote:

Originally Posted by dinakumar12 (Post 4307353)
hi tommylovell,

Thanks for your reply.

My doubt is which value is the exact or the real one.

The one which we get by executing du -sh command or the value which got graphically by clicking on folder's properties.


The both are valid and exact. It's always a matter of how the math is made to make it Human Readable. Human Readable should always be used only as reference. Human Readable is not the most exact. You always some digit when you read in G or in M or in K. The best way to know the size of a file is to look at it raw in bytes.

chrism01 03-29-2011 06:27 PM

Post #2 is a good explanation. As pointed out in other similar threads, manufacturers will usually express disk size in powers of 10 (1k = 1000) to make the disks look bigger, whereas computers use 1k=1024 (powers of 2).
The difference between these 2 scales becomes progressively larger as the values increase.
https://secure.wikimedia.org/wikiped...y_measurements
Also, Linux reserves an amt (5% default iirc) on each disk for root to use when the user's area becomes full.

If you REALLY want to understand this topic, read & digest the following

http://linux.die.net/man/8/mkfs
http://linux.die.net/man/8/tune2fs
http://linux.die.net/man/1/du
http://linux.die.net/man/1/df

:)

toordog 03-30-2011 09:18 AM

[QUOTE=chrism01;4307987]
Also, Linux reserves an amt (5% default iirc) on each disk for root to use when the user's area becomes full.
/QUOTE]

I didn't know that. Thanks for this info :)

tommylovell 03-30-2011 09:48 AM

Quote:

Also, Linux reserves an amt (5% default iirc) on each disk for root to use when the user's area becomes full.
Yup. Good thing to keep in mind if a non-root user (again, a default) can't use 100% of a filesystem.
The 5% is not taken out of the 'used' and still shows as 'free'.

For ext2/3/4, see the man page for 'tune2fs', the -r, -u and -g flags. And do a 'dumpe2fs -h /dev/<device>' to see what it is currently set to (and to see other interesting filesystem tidbits).

It would be a good idea if you set up a terabyte filesystem for a database that the whole terabyte could be used by the database uid. 'tune2fs' comes in handy for that. Why waste 5GB of space.


All times are GMT -5. The time now is 10:50 AM.