LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   file size confusion !! (https://www.linuxquestions.org/questions/linux-newbie-8/file-size-confusion-633630/)

livetoday 04-07-2008 06:38 AM

file size confusion !!
 
I came in to this issue while trying to locate empty files ( zero byte). I used find command

Code:

find . -size 0c

./.gconf/apps/ggv/%gconf.xml
./.gconf/apps/%gconf.xml
./.gconf/apps/panel/objects/%gconf.xml

but when I piped the output to du command, it shows

Code:

find . -size 0c | xargs du

0      ./.gconf/apps/ggv/%gconf.xml
4      ./.gconf/apps/%gconf.xml
4      ./.gconf/apps/panel/objects/%gconf.xml

Though ls -l shows that files are zero byte.

-rw------- 1 root root 0 Mar 11 10:50 ./.gconf/apps/%gconf.xml
-rw------- 1 root root 0 Apr 6 09:50 ./.gconf/apps/ggv/%gconf.xml
-rw------- 1 root root 0 Mar 11 10:51 ./.gconf/apps/panel/objects/%gconf.xml

when I copy the %gconf.file, the output file shows the zero size (using du) but original file remains same (4k)....isnt it confusing ?

additonal info: uname -a
Linux ldsqd.sun 2.6.21 #3 SMP Tue Apr 1 04:19:45 EDT 2008 i686 i686 i386 GNU/Linux

cat /etc/redhat-release

Red Hat Desktop release 4 (Nahant Update 2)

blacky_5251 04-07-2008 06:53 AM

The files showing as 4k have probably contained data at one point, even though they are now empty.

Use "tune2fs -l /dev/yourdisk" and you will see that the block-size for the file system on that partition is 4096 bytes, or 4k. So even if you put 1 byte in the file, it takes up 4k on disk. When the file grows from 4096 bytes to 4097, it pushes into the second block, and so takes up 8192 on disk.

Hope this explains it for you.

jtshaw 04-07-2008 06:54 AM

This is a total shot in the dark but it *could* be a function of file system blocks being allocated because du's intention is to show you the effect on the file system the file is causing... if that makes any sense.

If you add the -b switch to du (find . -size 0c | xargs du -b) do they all show up as 0 now?

livetoday 04-07-2008 07:11 AM

Code:

tune2fs -l /dev/mapper/VolGroup00-LogVol00

Block size:              4096

I begin to understand that if a file conatains data less than anything less than, then du will show it 4k. But if file does not contain anything then it should be in zero byte category not in 4k....

and also if I copy the file, then how the output file size becomes zero, it should also say the same thing 4k....


Quote:

Originally Posted by blacky_5251 (Post 3113389)
The files showing as 4k have probably contained data at one point, even though they are now empty.

Use "tune2fs -l /dev/yourdisk" and you will see that the block-size for the file system on that partition is 4096 bytes, or 4k. So even if you put 1 byte in the file, it takes up 4k on disk. When the file grows from 4096 bytes to 4097, it pushes into the second block, and so takes up 8192 on disk.

Hope this explains it for you.


livetoday 04-07-2008 07:15 AM

@jtshaw

Yeah...now it is showing correct output..... but I don't think I understood the concept completely....can you explain a bit the difference ....?

Code:

find . -size 0b | xargs du -b

0      ./.gconf/apps/ggv/%gconf.xml
0  ./.gconf/apps/%gconf.xml
0    ./.gconf/apps/panel/objects/%gconf.xml

Quote:

Originally Posted by jtshaw (Post 3113390)

If you add the -b switch to du (find . -size 0c | xargs du -b) do they all show up as 0 now?


jtshaw 04-07-2008 07:38 AM

Quote:

Originally Posted by livetoday (Post 3113409)
@jtshaw

Yeah...now it is showing correct output..... but I don't think I understood the concept completely....can you explain a bit the difference ....?

Code:

find . -size 0b | xargs du -b

0      ./.gconf/apps/ggv/%gconf.xml
0  ./.gconf/apps/%gconf.xml
0    ./.gconf/apps/panel/objects/%gconf.xml


Well, as I understand it... du with no options tells you the impact the file has on the file system. A file can take up more space on the fs then its actual size for a number of reasons depending on the file system layout. Du -b tells you the actual number of bytes the file contains.

livetoday 04-07-2008 07:53 AM

thank you for the explanation...now I understood, why the different commands showing different output...Now I will try to dig deeper in to the file system knowldege base to get an idea about some of those reasons which are making the du command confuse....Thanks again....

Quote:

Originally Posted by jtshaw (Post 3113424)
Well, as I understand it... du with no options tells you the impact the file has on the file system. A file can take up more space on the fs then its actual size for a number of reasons depending on the file system layout. Du -b tells you the actual number of bytes the file contains.



All times are GMT -5. The time now is 11:29 PM.