Translate

Image of Operating System Concepts
Image of Android Wireless Application Development
Image of RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)
Image of Linux Kernel Development (3rd Edition)

Write all 1s to file using dd

It is easy to create a file consisting of all zeros in Linux using dd and the /dev/zero device.

$ dd if=/dev/zero count=100 bs=1 > outfile


So how do you create a file consisting of all binary ones? There is no device to create binary ones so you have to do something like the following:

$ dd if=/dev/zero count=100 bs=1 | tr "00" "377" > outfile


You can use xxd to see the contents of the resultant file:

$ xxd -b outfile
0000000: 11111111 11111111 11111111 11111111 11111111 11111111  ......
0000006: 11111111 11111111 11111111 11111111 11111111 11111111  ......
000000c: 11111111 11111111 11111111 11111111 11111111 11111111  ......
0000012: 11111111 11111111 11111111 11111111 11111111 11111111  ......
0000018: 11111111 11111111 11111111 11111111 11111111 11111111  ......
000001e: 11111111 11111111 11111111 11111111 11111111 11111111  ......
0000024: 11111111 11111111 11111111 11111111 11111111 11111111  ......
000002a: 11111111 11111111 11111111 11111111 11111111 11111111  ......
0000030: 11111111 11111111 11111111 11111111 11111111 11111111  ......
0000036: 11111111 11111111 11111111 11111111 11111111 11111111  ......
000003c: 11111111 11111111 11111111 11111111 11111111 11111111  ......
0000042: 11111111 11111111 11111111 11111111 11111111 11111111  ......
0000048: 11111111 11111111 11111111 11111111 11111111 11111111  ......
000004e: 11111111 11111111 11111111 11111111 11111111 11111111  ......
0000054: 11111111 11111111 11111111 11111111 11111111 11111111  ......
000005a: 11111111 11111111 11111111 11111111 11111111 11111111  ......
0000060: 11111111 11111111 11111111 11111111                    ....
$

Comments are closed.