Monday, January 3, 2011

Making A Fixed Size File

If you have ever wanted to know how to make a fixed size file, here are a few methods that you can use to create a 1GB file.

1GB Empty (all zeros) File
You can use mkfile or dd to create an empty file.  See the following examples for creating an empty 1GB file.

# mkfile 1g myfile

# dd if=/dev/zero of=myfile bs=1k count=1m


1GB Scrambled File
You can use openssl, dd, and ksh93 to create a file that is populated with random/scrambled data.  See the following examples for each method.

Write random bytes of base64-encoded data to stdout
# openssl rand -base64 -out myfile $((1024*1024*1000)) 

Write binary random data to a file
# openssl rand -out myfile $((1024*1024*1000)) 

# dd if=/dev/urandom of=myfile bs=1k count=1m

# ksh93 "head -c $((1024*1024*1000)) /dev/urandom" > myfile

Hope that was helpful!

Have a great day!


Brad
If this information has helped you, please consider helping me through investing in your health and in the health of those you love through purchasing Mannatech wellness products. Ambrotose is the key ingredient of all Mannatech Wellness products.  Place your order at my Mannatech Web Store today.

2 comments:

David Esquivel said...

Hello, have you ever send the signal USR1 to a running dd command??? :D kill -USR1 PID ... or try: while true; do kill -USR1 PID ; sleep 1; done

Brad Diggs said...

I can't say that I have done that to stop dd. However, it should work.