Sunday, August 15, 2010

How to create dummy files in Linux

If your test case requires you to create a large dummy file or many dummy files in linux and Google or Yahoo landed you here, then you have come to the right place.

In Linux you can create a large file with just a one line command. Here's how.
Creating one large file

dd if=/dev/zero of=/home/1GBtestfile.img count=1000000 bs=1024
This will create a 1GB file named 1GBtestfile.img in the home directory

dd if=/dev/zero of=/50GBtestfile.img count=50000000 bs=1024
This will create a 50GB file named 50GBtestfile.img in the / or root directory

To check the size of the file which is being created, in a new ssh session type
du -hs /home/1GBtestfile.img

Creating many dummy files

Create a shell script named filecreator
# vi filecreator

Paste the following to create 10 files in the same directory
    for i in $(seq 0 10);
        echo -n "file${i} ";
        dd if=/dev/zero of=file${i} bs=1024 count=2 2>&1;

Wright and Quit by typing wq

Rename the file to a .sh file
# mv filecreator

Run the script

To count the number of files in a directory
# ls -l | wc -l

Happy Testing!!

No comments:

Post a Comment