LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-23-2009, 11:31 PM   #1
huyangyang
Member
 
Registered: Nov 2009
Posts: 38

Rep: Reputation: 15
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
 
Old 11-24-2009, 01:06 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
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?
 
Old 11-24-2009, 01:45 AM   #3
huyangyang
Member
 
Registered: Nov 2009
Posts: 38

Original Poster
Rep: Reputation: 15
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]#
 
Old 11-24-2009, 02:45 AM   #4
huyangyang
Member
 
Registered: Nov 2009
Posts: 38

Original Poster
Rep: Reputation: 15
dddddddddddd
 
Old 11-24-2009, 11:29 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
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.
 
Old 11-24-2009, 11:37 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
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
 
Old 11-24-2009, 11:40 PM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,330

Rep: Reputation: 227Reputation: 227Reputation: 227
why are you using
Code:
ll -sh joy
insted of
Code:
ls joy
?
 
0 members found this post helpful.
Old 11-25-2009, 12:37 AM   #8
huyangyang
Member
 
Registered: Nov 2009
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by i92guboj View Post
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.
 
Old 11-25-2009, 12:39 AM   #9
huyangyang
Member
 
Registered: Nov 2009
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by smeezekitty View Post
why are you using
Code:
ll -sh joy
insted of
Code:
ls joy
?
I want know length and size for the file
 
Old 11-25-2009, 01:03 AM   #10
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by huyangyang View Post
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.
 
Old 11-25-2009, 01:20 AM   #11
huyangyang
Member
 
Registered: Nov 2009
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by i92guboj View Post
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.
 
Old 11-25-2009, 01:21 AM   #12
huyangyang
Member
 
Registered: Nov 2009
Posts: 38

Original Poster
Rep: Reputation: 15
[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]#
 
Old 11-25-2009, 01:42 AM   #13
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,330

Rep: Reputation: 227Reputation: 227Reputation: 227
what about
Code:
ls -s -h joy
 
0 members found this post helpful.
Old 11-25-2009, 01:45 AM   #14
huyangyang
Member
 
Registered: Nov 2009
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by smeezekitty View Post
what about
Code:
ls -s -h joy
[root@WOLK-TECH tmp]# ls -s -h joy
4.0K joy
[root@WOLK-TECH tmp]#
 
Old 11-25-2009, 03:11 AM   #15
edwill
LQ Newbie
 
Registered: Nov 2009
Posts: 1

Rep: Reputation: 0
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.
  


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
Solaris 8 - file size and partition size discrepancy noir911 Solaris / OpenSolaris 1 02-10-2009 05:43 PM
[SOLVED] Questions about file size and dd djeikyb Linux - Software 3 10-15-2008 05:29 PM
Display by File Name, File Size, and File Owner using ls akeenabawa Linux - Newbie 9 08-15-2008 03:21 PM
any ideas to reduce log file size or make log file size managed? George2 Programming 2 08-13-2006 07:55 AM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 05:18 PM


All times are GMT -5. The time now is 07:33 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration