Creating Dummy Files with a specified size under Linux

07 09 2009
Today I was asked how to automatically create multiple non-empty dummy files under linux with just one command. Here is a small bash script. To adjust the number of files to be created, adjust the "10" in "$(seq 0 10)" to a number of your choice. To adjust the file size to be created, change "count=2" to anything you like. The "bs" parameter defines the base for the count parameter. bs=1024 means that 1024 bytes * "count" is the file size. In this case it's 2kilobyte. To have 1MB files you could either write "bs=1024 count=1024" or "bs=$((1024*1024)) count=2" or "bs=1024 count=$((1024*1))".



PS: there seems to be a problem with the bash highlighter of dp.SyntaxHighlighter: on line 4 the first "if" after dd is one if too much. The line should be "dd if=/dev/zero of=file${i} bs=1024 count=2 2>&1;"

Bookmark Creating Dummy Files with a specified size under Linux  at del.icio.us Digg Creating Dummy Files with a specified size under Linux Mixx Creating Dummy Files with a specified size under Linux Bloglines Creating Dummy Files with a specified size under Linux Technorati Creating Dummy Files with a specified size under Linux Bookmark Creating Dummy Files with a specified size under Linux  at Furl.net Bookmark Creating Dummy Files with a specified size under Linux  at blogmarks Bookmark Creating Dummy Files with a specified size under Linux  at Ma.gnolia.com wong it! Stumble It!

Trackbacks


No Trackbacks

Comments

Display comments as (Linear | Threaded)
07 09 2009
#1 Treibholz (Reply)

Treibholzif you use

dd if=/dev/zero of=file${i} bs=1 seek=2048 count=0

the files have the size of 2048, but don't need the space on the harddisk (sparse-files)
12 07 2010
#2 IceMan (Reply)

IceManThanks for this useful post..

@Treibholz, how do we use your command to generate multiple files. I changed the count=20 but still only one file was created

Add Comment


Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA