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
#!/bin/bash
    for i in $(seq 0 10);
    do
        echo -n "file${i} ";
        dd if=/dev/zero of=file${i} bs=1024 count=2 2>&1;
    done

Wright and Quit by typing wq

Rename the file to a .sh file
# mv filecreator filecreator.sh

Run the script
./filecreator.sh
 

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

Happy Testing!!

No comments:

Post a Comment