It is often useful when testing file transfers to have a file of a particular size. Rather than hunting around for a file of the required size why not simply create one of the desired size.
Generating files of any length in 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 file size 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 in 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.
Leave a Reply