LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-10-2010, 02: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, 03: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, 04:21 PM   #3
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
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, 04:43 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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, 05:08 PM   #5
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
Quote:
Originally Posted by pixellany View Post
As can dd, n'est-ce pas?
Oui!
 
  


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
Create a file of a specified size Rettahdam Linux - Newbie 5 12-11-2011 03: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 08:47 AM
how to create file with a specific file size markraem Linux - Software 7 08-22-2007 06:38 PM
How tol limit the file to fixed size? sudevank Linux - General 4 03-13-2007 04:33 AM
jpg file lowercase with fixed size Whynot Linux - Software 5 12-13-2006 12:36 AM

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

All times are GMT -5. The time now is 01:08 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