LinuxQuestions.org
Review your favorite Linux distribution.
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 06-10-2010, 03:57 PM   #1
rguy
LQ Newbie
 
Registered: Jun 2010
Posts: 1

Rep: Reputation: 0
create file - fixed size


Hi,

I want to create a file, say example.txt of 5MB.

I use dd to create a file of 5MB, but when I start
pushing more data into the file, the file size keeps increasing.

I want to have file of 5MB, and when I direct data to it should overwrite
the existing data and the file size should be fixed to 5MB.

Thanks
 
Old 06-10-2010, 04:33 PM   #2
nuwen52
Member
 
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
I have not seen something like this for normal/generic files. But, under FreeBSD, there is a circular log file implementation for syslogd. Something like this might exist for other purposes, so it might be a place to start looking. Google "freebsd clog" for more info.
 
Old 06-10-2010, 05:21 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Hi and welcome to LinuxQuestions!

You may want to create a sparse file of fixed (apparent) size, for example using the seek operand of the dd command:
Code:
dd if=/dev/zero of=this_is_a_sparse_file bs=1K count=0 seek=5120
In this way you can allocate a fixed amount of disk space, without actually store any data on it. See this page on Arch wiki for an introduction to sparse files (plenty of them out there). The problem could be how to write data into the sparse file: you need a software that is able to write data at specific positions. For example a C program or Python can do that.
 
Old 06-10-2010, 05:43 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
you need a software that is able to write data at specific positions. For example a C program or Python can do that.
As can dd, n'est-ce pas?
 
Old 06-10-2010, 06:08 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by pixellany View Post
As can dd, n'est-ce pas?
Oui!
 
  


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
Create a file of a specified size Rettahdam Linux - Newbie 5 12-11-2011 04:57 AM
How to create a "fixed-space"-a folder that is EXT2 inside and whatever size-50MB? linus72 Linux - Newbie 3 04-08-2009 09:47 AM
how to create file with a specific file size markraem Linux - Software 7 08-22-2007 07:38 PM
How tol limit the file to fixed size? sudevank Linux - General 4 03-13-2007 05:33 AM
jpg file lowercase with fixed size Whynot Linux - Software 5 12-13-2006 01:36 AM


All times are GMT -5. The time now is 06:14 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration