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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
11-23-2009, 10:31 PM
|
#1
|
Member
Registered: Nov 2009
Posts: 38
Rep:
|
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
|
|
|
11-24-2009, 12:06 AM
|
#2
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083
|
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?
|
|
|
11-24-2009, 12:45 AM
|
#3
|
Member
Registered: Nov 2009
Posts: 38
Original Poster
Rep:
|
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]#
|
|
|
11-24-2009, 01:45 AM
|
#4
|
Member
Registered: Nov 2009
Posts: 38
Original Poster
Rep:
|
dddddddddddd
|
|
|
11-24-2009, 10:29 PM
|
#5
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,442
|
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.
|
|
|
11-24-2009, 10:37 PM
|
#6
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083
|
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
|
|
|
11-24-2009, 10:40 PM
|
#7
|
Senior Member
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
|
why are you using
insted of
?
|
|
0 members found this post helpful.
|
11-24-2009, 11:37 PM
|
#8
|
Member
Registered: Nov 2009
Posts: 38
Original Poster
Rep:
|
Quote:
Originally Posted by i92guboj
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.
|
|
|
11-24-2009, 11:39 PM
|
#9
|
Member
Registered: Nov 2009
Posts: 38
Original Poster
Rep:
|
Quote:
Originally Posted by smeezekitty
why are you using
insted of
?
|
I want know length and size for the file
|
|
|
11-25-2009, 12:03 AM
|
#10
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083
|
Quote:
Originally Posted by huyangyang
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.
|
|
|
11-25-2009, 12:20 AM
|
#11
|
Member
Registered: Nov 2009
Posts: 38
Original Poster
Rep:
|
Quote:
Originally Posted by i92guboj
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.
|
|
|
11-25-2009, 12:21 AM
|
#12
|
Member
Registered: Nov 2009
Posts: 38
Original Poster
Rep:
|
[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]#
|
|
|
11-25-2009, 12:42 AM
|
#13
|
Senior Member
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
|
|
|
0 members found this post helpful.
|
11-25-2009, 12:45 AM
|
#14
|
Member
Registered: Nov 2009
Posts: 38
Original Poster
Rep:
|
Quote:
Originally Posted by smeezekitty
|
[root@WOLK-TECH tmp]# ls -s -h joy
4.0K joy
[root@WOLK-TECH tmp]#
|
|
|
11-25-2009, 02:11 AM
|
#15
|
LQ Newbie
Registered: Nov 2009
Posts: 1
Rep:
|
because your system's the size of default block is 4K,every file will take up one block at least.
|
|
0 members found this post helpful.
|
All times are GMT -5. The time now is 01:50 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|