LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-22-2007, 10:21 AM   #1
markraem
Member
 
Registered: Nov 2003
Posts: 82

Rep: Reputation: 15
how to create file with a specific file size


I am looking for a tool that can create a file with a specific file size. The content of the file does not matter.

for instance :

[root]#tool-i-am-looking-for filename 567

will create a file called filename with size = 567 bytes.


I know that via touch you can create a file, but it will only create a file with zero bytes length.

does a tool like that exist in linux ?
 
Old 08-22-2007, 10:24 AM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
dd if=/dev/zero of=filename bs=567 count=1
 
Old 08-22-2007, 10:31 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
dd if=/dev/zero of=newfile bs=1 count=567

"dd" is the ultimate power tool--use with caution!!

Edit--now you have 2 very different methods!!! (We did NOT rehearse this....)

Last edited by pixellany; 08-22-2007 at 10:32 AM.
 
Old 08-22-2007, 10:47 AM   #4
markraem
Member
 
Registered: Nov 2003
Posts: 82

Original Poster
Rep: Reputation: 15
Many thanks !
 
Old 08-22-2007, 11:46 AM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by pixellany View Post
dd if=/dev/zero of=newfile bs=1 count=567

"dd" is the ultimate power tool--use with caution!!

Edit--now you have 2 very different methods!!! (We did NOT rehearse this....)
LOL. Not sure, but I think the way I wrote it would be faster.
 
Old 08-22-2007, 12:31 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by jiml8 View Post
LOL. Not sure, but I think the way I wrote it would be faster.
I expect you are right--although mine took less than 1 second.

I did it that way because I had first attempted to use /dev/random and was getting strange results---It **appeared** that maybe dd did not like off-beat block sizes.
 
Old 08-22-2007, 04:04 PM   #7
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
jiml@Dadsbox:jiml> time dd if=/dev/zero of=newfile bs=1 count=567
567+0 records in
567+0 records out
567 bytes (567 B) copied, 0.001906 seconds, 297 kB/s
0.00user 0.00system 0:00.04elapsed 20%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (1major+264minor)pagefaults 0swaps
jiml@Dadsbox:jiml> time dd if=/dev/zero of=newfile bs=567 count=1
1+0 records in
1+0 records out
567 bytes (567 B) copied, 8.4e-05 seconds, 6.8 MB/s
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+266minor)pagefaults 0swaps


Actually, I had wondered what it would do with the "odd sized block" as well, but it didn't seem to care in this case.
 
Old 08-22-2007, 06:38 PM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I agree---84 microseconds is a lot faster than 1900 microseconds!!! Doing something like this all day using my method could have cost someone a coffee break......

All seriousness aside, there's no question that the larger block size is the right answer....
 
  


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
Can you write a script to display file name, Inode, and size of any file? JaxsunApex Linux - Newbie 3 01-30-2007 08:39 AM
Create a script to display file name, Inode, and size of any file. Has to be a script JaxsunApex Linux - Newbie 7 01-29-2007 08:15 PM
any ideas to reduce log file size or make log file size managed? George2 Programming 2 08-13-2006 06:55 AM
how can i default the max folder file size when it create inside a folder antony_csf Linux - Software 1 06-17-2004 02:26 AM
How to limit the size of a specific file ericthyred Linux - Software 1 04-15-2004 11:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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