LinuxQuestions.org

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

huyangyang 11-23-2009 10:31 PM

file size questions
 
create a empty file,but this file size is 4k
[root@joy tmp]# touch joy
[root@joy tmp]# ll -sh joy
4.0K -rw-r--r-- 1 root root 0 Oct 30 17:23 joy
[root@joy tmp]# stat joy
File: `joy'
Size: 0 Blocks: 8 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 1421279 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2009-10-30 17:23:50.000000000 +0800
Modify: 2009-10-30 17:23:50.000000000 +0800
Change: 2009-10-30 17:23:50.000000000 +0800

i92guboj 11-24-2009 12:06 AM

As far as I know, no filesystem will take a block to store an empty file, are you sure you used touch and that you didn't edit the file and then saved it? If the file has a single byte inside, that's enough to make it significant, and hence, it will take a whole fs block (what stat calls IO Block).

What fs are you using?

huyangyang 11-24-2009 12:45 AM

no i don`t edit the file.i used ext3 fs.
[root@joy ~]# uname -r
2.6.18-92.el5
[root@joy ~]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 144 1052257+ 82 Linux swap / Solaris
/dev/sda3 145 1044 7229250 83 Linux
[root@joy ~]# cd /tmp/
[root@joy tmp]# rm joy
rm: remove regular empty file `joy'? y
[root@joy tmp]# touch joy
[root@joy tmp]# ll -sh joy
4.0K -rw-r--r-- 1 root root 0 Oct 30 17:46 joy
[root@joy tmp]# stat joy
File: `joy'
Size: 0 Blocks: 8 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 1421279 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2009-10-30 17:46:40.000000000 +0800
Modify: 2009-10-30 17:46:40.000000000 +0800
Change: 2009-10-30 17:46:40.000000000 +0800
[root@joy tmp]#

huyangyang 11-24-2009 01:45 AM

dddddddddddd

chrism01 11-24-2009 10:29 PM

I think the inode entry in the dir inode has to point to something(!), so it 'reserves' the initial (4k) file block, even if it's empty.

i92guboj 11-24-2009 10:37 PM

I tested this same stuff (also on ext3) and empty files take 0 bytes, as far as I know it has always been the same for me. So I am not sure what to think.

Code:

$ cd /home/i92guboj/media/conceptronic/
$ mount|grep concep
/dev/sdc1 on /mnt/conceptronic1 type ext3 (rw,noexec,nodev,noatime)
$ touch foo
$ ls -lsh foo
0 -rw-r--r-- 1 root root 0 Nov 25 05:36 foo
$ stat foo
  File: `foo'
  Size: 0              Blocks: 0          IO Block: 4096  regular empty file
Device: 821h/2081d      Inode: 8558        Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)  Gid: (    0/    root)
Access: 2009-11-25 05:36:07.000000000 +0100
Modify: 2009-11-25 05:36:07.000000000 +0100
Change: 2009-11-25 05:36:07.000000000 +0100


smeezekitty 11-24-2009 10:40 PM

why are you using
Code:

ll -sh joy
insted of
Code:

ls joy
?

huyangyang 11-24-2009 11:37 PM

Quote:

Originally Posted by i92guboj (Post 3768700)
I tested this same stuff (also on ext3) and empty files take 0 bytes, as far as I know it has always been the same for me. So I am not sure what to think.

Code:

$ cd /home/i92guboj/media/conceptronic/
$ mount|grep concep
/dev/sdc1 on /mnt/conceptronic1 type ext3 (rw,noexec,nodev,noatime)
$ touch foo
$ ls -lsh foo
0 -rw-r--r-- 1 root root 0 Nov 25 05:36 foo
$ stat foo
  File: `foo'
  Size: 0              Blocks: 0          IO Block: 4096  regular empty file
Device: 821h/2081d      Inode: 8558        Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)  Gid: (    0/    root)
Access: 2009-11-25 05:36:07.000000000 +0100
Modify: 2009-11-25 05:36:07.000000000 +0100
Change: 2009-11-25 05:36:07.000000000 +0100


you edit foo file.
$echo i > foo
and stat foo.

huyangyang 11-24-2009 11:39 PM

Quote:

Originally Posted by smeezekitty (Post 3768705)
why are you using
Code:

ll -sh joy
insted of
Code:

ls joy
?

I want know length and size for the file

i92guboj 11-25-2009 12:03 AM

Quote:

Originally Posted by huyangyang (Post 3768744)
you edit foo file.
$echo i > foo
and stat foo.

I don't understand what are you wanting to say with that.

If you edit the file then the file length might not be zero anymore, it depends on what your editor is doing. "touch" by default creates an zero-length file which shouldn't take any block in your disk.

huyangyang 11-25-2009 12:20 AM

Quote:

Originally Posted by i92guboj (Post 3768761)
I don't understand what are you wanting to say with that.

If you edit the file then the file length might not be zero anymore, it depends on what your editor is doing. "touch" by default creates an zero-length file which shouldn't take any block in your disk.

i think so.but my system create a empty file take 8 block in my disk.

huyangyang 11-25-2009 12:21 AM

[root@joy tmp]# touch joy
[root@joy tmp]# ll -sh joy
4.0K -rw-r--r-- 1 root root 0 Oct 30 17:46 joy
[root@joy tmp]# stat joy
File: `joy'
Size: 0 Blocks: 8 IO Block: 4096 regular empty file
Device: 803h/2051d Inode: 1421279 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2009-10-30 17:46:40.000000000 +0800
Modify: 2009-10-30 17:46:40.000000000 +0800
Change: 2009-10-30 17:46:40.000000000 +0800
[root@joy tmp]#

smeezekitty 11-25-2009 12:42 AM

what about
Code:

ls -s -h joy

huyangyang 11-25-2009 12:45 AM

Quote:

Originally Posted by smeezekitty (Post 3768787)
what about
Code:

ls -s -h joy

[root@WOLK-TECH tmp]# ls -s -h joy
4.0K joy
[root@WOLK-TECH tmp]#

edwill 11-25-2009 02:11 AM

because your system's the size of default block is 4K,every file will take up one block at least.


All times are GMT -5. The time now is 01:19 AM.