Create test files on the fly

In many cases test files are needed for software tester. Partially with specified file size. With a small set of commands, it is very easy to create these files. In order to check the generated file(s), you can use the following:

# Check file size
$ ls -lh test-file

# Determine file type
$ file test-file

# Display output one screen
$ less test-file

# or
$ hexdump test-file

Perl

# Example for 1.0K
$ perl -e 'print "a" x 1024' > test-file

# Example for 1.0M
$ perl -e 'print "a" x 1048576' > test-file

mkfile

# Example for 1.0K
$ mkfile 1k test-file

# Example for 1.0M
$ mkfile 1m test-file

dd

# Example for 1.0K
$ dd if=/dev/zero of=test-file bs=1k count=1

# Example for 1.0M
$ dd if=/dev/zero of=test-file bs=1m count=1

base64

# Example for 1.0K
$ base64 /dev/urandom | head -c 1024 > test-file

# Example for 1.0M
$ base64 /dev/urandom | head -c 1048576 > test-file