How do I create 1 GB or 10 GB image file instantly with dd command under UNIX / Linux / BSD operating systems using a shell prompt?
You can use dd command to create image files for network or file system testing. First, make sure you've sufficient disk space to create a image file using dd:
$ df -H
To create 1MB file (1024kb), enter:
$ dd if=/dev/zero of=test.img bs=1024 count=0 seek=1024
To create 10MB file , enter:
$ dd if=/dev/zero of=test.img bs=1024 count=0 seek=$[1024*10]
To create 100MB file , enter:
$ dd if=/dev/zero of=test.img bs=1024 count=0 seek=$[1024*100]
$ ls -lh test.img
To create 10GB, file:
$ dd if=/dev/zero of=10g.img bs=1000 count=0 seek=$[1000*1000*10]
Sample output:
0+0 records in 0+0 records out 0 bytes transferred in 0.000014 secs (0 bytes/sec)
Verify file size (note bs factor in original dd command):
$ ls -lh 10g
-rw-r--r-- 1 root wheel 9.3G Jun 2 12:07 10g.img
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 6 comments… read them below or add one }
I don’t think this works correctly unless the “count” argument is changed to something greater than 0.
Try something like this:
dd if=/dev/zero of=10Gtest bs=1M count=10000
can I supress the output of dd command?
Yes, send it to /dev/null.
dd args >/dev/nullOR
dd args >/dev/null 2>&1Slightly easier version is to use a suffix for the size instead of trying to do the maths.
to create a 1G file.
Yes this is work but there is concern !!!
When do ls -lh disk.img file its showing as 1G size but when u run the command
du -h disk.img it shows 0 bytes of size…..
Which one we can believe…i dont know…please clarify if you know about this…
Jai
The ls command will tell you the size of the file while du will tell you the Disk Usage. When you create the empty disk image with the above command it doesn’t write any data so it doesn’t actually allocate any blocks to the file.
If you type “stat disk.img” you’ll see that it’s using 0 blocks and thus no disk space is being consumed by the file, it’s only when you then write data to it that the blocks will then be allocated.