How to generate test files of any length

Every now and then my fellow coworkers and me are faced with clients that mention problems uploading files of a specific size to web content management systems (CMS). While we are trying to solve the problem we need to test the upload ourselves. Now the filesize differs with every inquiry and we have to come up with files that extend this size. What to do in this case? Browsing the web for files of a specific length? Crawling through our media asset management system to fetch a file that fits in? No, there’s a better solution to that: the file generation tools of the operating system!

Files
Creative Commons License photo credit: Velo Steve

Microsoft Windows, Linux and Mac OS come with standard tools that allow file generation and manipulation. This article tells you how to use them to generate files of any length.

Generating files of any length on Windows

First open the command line interface by clicking Start > Run… and entering “cmd” (without the quotes) in the dialog form. By pressing Enter the command line interface will pop up and you can insert the following string to create a new file:

C:\>fsutil file createnew <filename> <filesize in bytes>

As you see you have to state the specific filesize in bytes! For a conversion of megabytes or kilobytes to bytes see this or this conversion tool.

For example this string creates a new file named testfile.txt sized 1 Kb located in the root directory of partition C:

C:\>fsutil file createnew C:\testfile.txt 1024

Generating files of any length on Linux

File generation with Linux is as easy as with Windows. The `dd` tool to (amongst others) create new files comes with virtually every distribution. Here is the example command, intended to be run from within a shell.

dd if=/dev/zero of=<filename> bs=<initial blocksize in bytes> count=<iterations of the blocksize>

The easiest way to create a file of specific length using `dd`is by utilizing suffixes like K (for Kilobytes) or M (for Megabytes) like this:

dd if=/dev/zero of=testfile.txt bs=1K count=1

The command above creates a file of 1KB size in the current working directory.

The man page of `dd`lists the suffixes you may utilize:

BLOCKS and BYTES may be followed by the following multiplicative suffixes: xM M, c 1, w 2, b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

As `dd` is available for all Linux/Unix distributions this applies to Unix Systems (e.g. Solaris) as well.

Generating files of any length on Mac OS

OSX provides a shell app that’s more convenient to use than `dd`. It’s called `mkfile`. Start it by firing up a Terminal window located here:

/Applications/Utilities/Terminal.app

Like `dd` the OSX pendant `mkfile` can be used with suffixes as well. Here you can use b for Bytes, k for Kilobytes, m for Megabytes and finally g for Gigabytes. See it in action:

mkfile 1k testfile.txt

As expected this creates a 1KB sized file in the current working directory.

Conclusion

As you can see, it is really easy to create test files of virtually any length on all major plattforms like Microsoft Windows, Linux and Mac OS. Try it out!

This entry was posted in the operating system and you and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany.