LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-22-2015, 11:03 AM   #1
Chojin
LQ Newbie
 
Registered: Dec 2005
Posts: 7

Rep: Reputation: 0
Magical mystery file on ext3 fs: file is 3.8Gb according to ls, 61M according to du


It has been long since Linux has flabbergasted me as much as it did today:

I found a normal ascii-text (log)file of 3.8G on an ext3 filesystem, however, df shows me only 512M of the 4.5G is actually used on the filesystem and du shows me the file is only 61M:
output of ls :
Code:
# ls -liah /var/log/jobscheduler/scheduler.out
41291 -rw------- 1 root root 3.8G Apr 22 17:09 /var/log/jobscheduler/scheduler.out
output of du :
Code:
# du -h /var/log/jobscheduler/scheduler.out
61M	/var/log/jobscheduler/scheduler.out
output of df :
Code:
Filesystem                                     Size  Used Avail Use% Mounted on
/dev/mapper/vgjobscheduler-lvjobscheduler_log  4.5G  521M  3.7G  13% /var/log/jobscheduler

I can copy the file using cp, multiple times on the same filesystem:

Code:
# cp /var/log/jobscheduler/scheduler.out /var/log/jobscheduler/scheduler.out.1
# cp /var/log/jobscheduler/scheduler.out /var/log/jobscheduler/scheduler.out.2
# cp /var/log/jobscheduler/scheduler.out /var/log/jobscheduler/scheduler.out.3
# ls -liah /var/log/jobscheduler/scheduler.out*
41291 -rw------- 1 root root  3.8G Apr 22 17:09 /var/log/jobscheduler/scheduler.out
41292 -rw------- 1 root root  3.8G Apr 22 17:28 /var/log/jobscheduler/scheduler.out.1
41293 -rw------- 1 root root  3.8G Apr 22 17:28 /var/log/jobscheduler/scheduler.out.2
41294 -rw------- 1 root root  3.8G Apr 22 17:28 /var/log/jobscheduler/scheduler.out.3
So now I have 15.2G on a 4.5G filesystem ..

OK, I though maybe the file has been allocated to 3.8G but actually uses only 61M which could explain this.. However:

When I cat the file to a new file, this new file actually does take 3.8G of diskspace:

Code:
# cat /var/log/jobscheduler/scheduler.out > /var/log/jobscheduler/scheduler.out.1
# ls -lia scheduler.out*
41291 -rw------- 1 root root  4045065364 Apr 22 17:09 scheduler.out
41292 -rw-r--r-- 1 root root  4045065364 Apr 22 17:34 scheduler.out.1
# du -h scheduler.out*
61M	scheduler.out
3.8G	scheduler.out.1
# df -h
Filesystem                                     Size  Used Avail Use% Mounted on
/dev/mapper/vgjobscheduler-lvjobscheduler_log  4.5G  4.3G     0 100% /var/log/jobscheduler
Also scp of the file to a remote machine gives me a full 3.8G file..

A line-count of the file shows me both files contain exactly the same amount of lines:
Code:
# cat scheduler.out | wc -l
294271
# cat scheduler.out.1 | wc -l
294271
and diff shows me there is absolutely no difference between those 2 files..


So the file actually contains 3.8G of data, but it only takes 61M on the filesystem.. as if it is compressed on FS-level.. but as far as I know, Ext3 doesn't support compression on filesystem level..

I checked for filesystem errors, but none where found..

With stat I found out that the original file actually takes a lot less blocks:
Code:
# stat scheduler.out
  File: `scheduler.out'
  Size: 4045065364	Blocks: 123472     IO Block: 4096   regular file
Device: fd06h/64774d	Inode: 41291       Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-04-22 17:10:10.000000000 +0200
Modify: 2015-04-22 17:09:42.000000000 +0200
Change: 2015-04-22 17:09:42.000000000 +0200
 Birth: -
than the 'catted' file:
Code:
# stat scheduler.out.1
  File: `scheduler.out.1'
  Size: 4045065364	Blocks: 7908248    IO Block: 4096   regular file
Device: fd06h/64774d	Inode: 41292       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-04-22 17:34:19.000000000 +0200
Modify: 2015-04-22 17:34:32.000000000 +0200
Change: 2015-04-22 17:34:32.000000000 +0200
 Birth: -
But where is then the 3.8G of data stored in this original file? ...
I manually checked the file contents of both files and verified that there are no blocks of zero's or so.. all looks like valid ascii log entries.. 294271 lines of ascii text..

Is anybody here that could explain what I am seeing here ?
 
Old 04-22-2015, 11:18 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
See sparse file.
 
2 members found this post helpful.
Old 04-24-2015, 03:54 AM   #3
Chojin
LQ Newbie
 
Registered: Dec 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by astrogeek View Post
Ofcourse... sparse files.. I forgot the existence of that.. Thanks for the hint ! Now I can sleep again :-)
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Advanced file attributes on file systems other than ext2 or ext3 gacanepa Linux - Newbie 1 11-25-2013 11:51 PM
Reading ext3 file system on Mac and overriding file permission moravveji Other *NIX 6 09-12-2011 02:25 AM
[SOLVED] Creating an 8GB file using mmap: error calling lseek() to stretch the file kvm1983 Programming 3 07-29-2009 03:10 PM
mount disk - corrupted file EXT3 file system RAFAL Linux - General 3 04-08-2009 03:27 PM
Large tar file taking huge disk space in ext3 file system pcwulf Linux - General 2 10-20-2003 07:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:03 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
Open Source Consulting | Domain Registration