LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-07-2008, 06:38 AM   #1
livetoday
Member
 
Registered: Jun 2006
Location: India
Distribution: RHEL,Suse,Fedora
Posts: 106

Rep: Reputation: 15
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)

Last edited by livetoday; 04-07-2008 at 06:40 AM.
 
Old 04-07-2008, 06:53 AM   #2
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569

Rep: Reputation: 55
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.
 
Old 04-07-2008, 06:54 AM   #3
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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?
 
Old 04-07-2008, 07:11 AM   #4
livetoday
Member
 
Registered: Jun 2006
Location: India
Distribution: RHEL,Suse,Fedora
Posts: 106

Original Poster
Rep: Reputation: 15
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 View Post
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.
 
Old 04-07-2008, 07:15 AM   #5
livetoday
Member
 
Registered: Jun 2006
Location: India
Distribution: RHEL,Suse,Fedora
Posts: 106

Original Poster
Rep: Reputation: 15
@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 View Post

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

Last edited by livetoday; 04-07-2008 at 07:19 AM.
 
Old 04-07-2008, 07:38 AM   #6
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
Quote:
Originally Posted by livetoday View Post
@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.
 
Old 04-07-2008, 07:53 AM   #7
livetoday
Member
 
Registered: Jun 2006
Location: India
Distribution: RHEL,Suse,Fedora
Posts: 106

Original Poster
Rep: Reputation: 15
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 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Confusion regarding the TCP window size bzlaskar Linux - Networking 3 07-06-2007 02:52 PM
any ideas to reduce log file size or make log file size managed? George2 Programming 2 08-13-2006 06:55 AM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 04:18 PM
Hard Disk Size Confusion (RH7.2) Arot Linux - Newbie 1 09-01-2003 04:43 PM
File System confusion hotrodowner Linux - Software 1 07-04-2002 08:23 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration