Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-26-2012, 08:40 AM   #1
Registered: Dec 2006
Location: Russia,52
Posts: 116

Rep: Reputation: 6
Question Sizes of file

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, 11:15 AM   #2
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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:
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 11:26 AM.
1 members found this post helpful.


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

All times are GMT -5. The time now is 01:32 PM.

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