how to generate huge files containing all bit set to 1... ?

Discussion in 'Mac Programming' started by Shrek-Moscow, Dec 16, 2009.

  1. Shrek-Moscow macrumors member

    Apr 11, 2008
    On another 3d I was asking about a simple solution to create a single file that will fill up completely the free space of a given disk writing all bits to 1.

    Someone has suggested to write the following command line on terminal:

    tr '\000' '\3ff' < /dev/zero | dd of=zero.bin bs=1k count=10

    The problem is that it is working on Linux but in Mac OS X (SL) his output is not all '1'.. does anyone know a solution?

    And that's not all.. in fact I'd like to write this file in blocks of 4k, not 1K.. is it enough to change bs=1k to bs=4k? what about the tr command in such case?

    Well, my only aim is to fill up the free space with all bits written to 1, if some of you know a better solution or find easier to write a simple program.. everything is welcome!

  2. Detrius macrumors 68000

    Sep 10, 2008
    Asheville, NC
    Well, the reason it doesn't work is because this doesn't work:

    tr '\000' '\3ff' < /dev/zero

    At least, it *appears* to do nothing. This works wonders:

    tr '\000' '\3ff' < /dev/zero >> test

    I opened the file with a hex editor, and it was full of 0x03, so I don't think the tr command is doing what you think, especially since "F" is not valid octal.

    Try this:

    tr '\000' '\177' < /dev/zero > test

    It gets you pretty darn close, but anything beyond seven bits causes more than one byte to be written to your output file. tr deals with strings--not binary.

    Note: 0xED makes a great hex editor.
  3. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Force the locale by setting LANG to "":
    LANG="" tr '\000' '\377' </dev/zero >test

Share This Page