Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Shrek-Moscow

macrumors member
Original poster
Apr 11, 2008
68
0
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!

:):)
 
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.
 
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.

Force the locale by setting LANG to "":
Code:
LANG="" tr '\000' '\377' </dev/zero >test
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.