LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 10-26-2012, 07:40 AM   #1
sluge
Member
 
Registered: Dec 2006
Location: Russia,52
Posts: 128

Rep: Reputation: 6
Question Sizes of file


Hello!
I created two files

1) # dd if=/dev/zero of=disk.image bs=1M seek=30000 count=1
2) # truncate -s 30G disk.image1

# ls -lh disk*
-rw-r--r--. 1 root root 30G Oct 26 14:27 disk.image
-rw-r--r--. 1 root root 30G Oct 26 14:27 disk.image1

# du -h disk*
1.0M disk.image
0 disk.image1

Why is shows that size of disk* files is 30 MB but du shows other value?
 
Old 10-26-2012, 10:15 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The first command actually writes a single block (count = 1) of size 1 Mb and skip 30000 blocks of the same size, that is 30 Gb. In practice it allocates 30.001 Gb on the filesystem, but the actual disk space used is only 1 Mb. The result is a sparse file.

The second command creates an empty file, as stated in the man page of truncate:
Quote:
Shrink or extend the size of each FILE to the specified size

A FILE argument that does not exist is created.

If a FILE is larger than the specified size, the extra data is lost. If a FILE is shorter, it is extended and the extended part (hole) reads as zero bytes.
In this case the original size was 0 bytes (since it was a non existent file) and being shorter than 30 Gb the extended part is 0 bytes long. The difference is between the ls and du commands: the former reads the information in the inode, therefore it reports the allocated space; the latter reports the actual physical space used. If you use the option --apparent-size of the du command, you should see 30 Gb as reported by ls.

Last edited by colucix; 10-26-2012 at 10:26 AM.
 
1 members found this post helpful.
  


Reply



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
ls -l and large file sizes. stf92 Linux - Newbie 2 06-07-2010 06:45 AM
define different physical sizes on Multiple Monitors of different sizes MasterC Linux - Desktop 2 03-18-2008 04:24 PM
LL and DU reporting different file sizes trewsfan Linux - General 5 07-20-2006 05:56 PM
reiserfs file sizes doralsoral Linux - Software 1 01-19-2005 03:52 PM
DVD File Sizes Maestro485 Linux - Software 1 12-21-2004 07:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:34 AM.

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
Open Source Consulting | Domain Registration