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
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 10 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
I don’t think you have read and tested this yourself.
If using “count=0″, as the article suggests, you will still have the file of the specified size.
However, the output will show something like “0+0 records in” and “0+0 records out”.
Then if you check the file size:
it should show the proper size.
It’s even easier, using the format that the commenter Indie suggest:
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.
I have 2 tb harddrive and i want to clone only 1 tb to my other drive?
what command should i do
How to check if the created file is empty, is there a way to check that?
ls -l