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 01-16-2008, 04:07 PM   #1
Rettahdam
LQ Newbie
 
Registered: Nov 2007
Location: Chicago, IL
Distribution: Fedora, Debian
Posts: 2

Rep: Reputation: 0
Create a file of a specified size


Hey all,

Can anyone tell me if it is possible to create a file that is a certain size. I need to create a 50k and 200k file for testing and I can not for the life of me find a way to do it.

Thank ya-
 
Old 01-16-2008, 04:14 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi,

and welcome to LQ!


Like so?
Code:
dd if=/dev/zero of=50k_file bs=1024 count=50


Cheers,
Tink

Last edited by Tinkster; 01-16-2008 at 04:16 PM. Reason: changed blocksize and count :} ... prettier
 
1 members found this post helpful.
Old 01-16-2008, 04:20 PM   #3
Rettahdam
LQ Newbie
 
Registered: Nov 2007
Location: Chicago, IL
Distribution: Fedora, Debian
Posts: 2

Original Poster
Rep: Reputation: 0
Exactly like that.. Many thanks
 
Old 12-10-2011, 06:56 PM   #4
Lsatenstein
Member
 
Registered: Jul 2005
Location: Montreal Canada
Distribution: Fedora 25 (Chapeau Remix/Korora Project Remix)
Posts: 286
Blog Entries: 1

Rep: Reputation: 50
Quote:
Originally Posted by Rettahdam View Post
Hey all,

Can anyone tell me if it is possible to create a file that is a certain size. I need to create a 50k and 200k file for testing and I can not for the life of me find a way to do it.

Thank ya-
Here it is in 2011.

truncate -s the_size_you_want_to_the_very_byte filename

SIZE may be (or may be an integer optionally followed by) one of following:
KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on
for G, T, P, E, Z, Y.

Do man truncate.
 
Old 12-10-2011, 11:44 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Quote:
Originally Posted by Rettahdam
I need to create a 50k and 200k file for testing
Tinkster's command is fine, but I would suggest an only slightly-modified version:
Code:
dd if=/dev/random of=50k_file bs=1024 count=50
The only difference is the use of /dev/random in place of /dev/zero. And the only reason I suggest that is because you want the file for testing.

Depending on the test, an all-zeroes file may not provide accurate results. For instance, compression algorithm tests would have an absolute field day "compressing" all zeroes.

So a random data file might be more to your liking.

And to be thorough, I don't know how truncate handles the data when a file is grown. The man page does not mention whether the new space is all-zeroes, randomized, or "whatever was written at those particular sectors last time they were used."
 
Old 12-11-2011, 04:57 AM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831
Quote:
Originally Posted by Dark_Helmet View Post
Tinkster's command is fine, but I would suggest an only slightly-modified version:
Code:
dd if=/dev/random of=50k_file bs=1024 count=50
The only difference is the use of /dev/random in place of /dev/zero. And the only reason I suggest that is because you want the file for testing.
May I suggest to use /dev/urandom instead, /dev/random is pretty slow, especially when you want to create larger files.
 
  


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
how to create file with a specific file size markraem Linux - Software 7 08-22-2007 07:38 PM
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 09:15 PM
any ideas to reduce log file size or make log file size managed? George2 Programming 2 08-13-2006 07:55 AM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 05:18 PM
how can i default the max folder file size when it create inside a folder antony_csf Linux - Software 1 06-17-2004 03:26 AM


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