[problem]
You want to generate 512 bytes of random data, using UNIX dd (disk to disk) command.
[/problem]
[solution]
Using /dev/random blocks waiting for truly random data, whereas /dev/urandom just pumps out whatever is available.
You need to escape the control characters, or else it will trash your screen. cat -ve escapes these control characters for you.
See examples
[/solution]
[example]
dd bs=1 count=512 if=/dev/urandom | cat -ve
dd is a very powerful command, that can be used to read files, data, tapes, even disks, etc – varying the number of blocks with count and block size with bs.
if is the input device and of can be used to designate an output device.
dd bs=1 count=512 if=/dev/urandom | openssl base64
Also it can convert to upper and lower case, with conv=ucase, etc.
If you have an extremely large file, it can open at an offset – via the skip option, for example to skip the first 1k of the file and read 100 bytes:
dd if=access_log.techieblogs bs=1 skip=1024 count=1000
- - [04/Jun/2006:00:13:10 +0800] "GET /mysqldemo/run_q.php?database=mysql HTTP/1.1" 200 1364
[/example]
[reference]
[tags]dd, pseudo random data, cat, Unix Coding School[/tags]
[/reference]
If you have found my website useful, please consider buying me a coffee below 😉