You can use

dd if=/dev/zero of=file count=1024 bs=1024 

to zero fill a file.

Instead of that I want to one fill a file. How do I do that?

There is no /dev/one file, so how can I simulate that effect via on bash shell?

share|improve this question
    
Write a C program to do it, should be trivial. – Peter V Jun 5 '12 at 21:16
up vote 10 down vote accepted

Try this:

dd if=<(yes $'\01' | tr -d "\n") of=file count=1024 bs=1024

Substitute $'\377' or $'\xFF' if you want all the bits to be ones.

share|improve this answer
pv /dev/zero |tr \\000 \\377 >targetfile

...where \377 is the octal representation of 255 (a byte with all bits set to one). Why tr only works with octal numbers, I don't know -- but be careful not to subconsciously translate this to 3FF.


The syntax for using tr is error prone. I recommend verifying that it is making the desired translation...

cat /dev/zero |tr \\000 \\377 |hexdump -C

Note: pv is a nice utility that replaces cat and adds a progress/rate display.

share|improve this answer
1  
Note: If you are trying to fill an entire device, it's probably better to avoid dd since that will slow things down (by a lot) if you don't manually select an optimum bs value. – nobar Oct 15 '16 at 20:59
    
pv will also give an estimate of time remaining if it has enough information to do so. – nobar Oct 15 '16 at 21:23
    
While you're at it, maybe prefix with time and nice. – nobar Oct 16 '16 at 23:25
tr '\0' '\377' < /dev/zero | dd bs=64K of=/dev/sdx

This should be much faster. Choose your blocksizes (or add counts) like you need at. Writing ones to a SSD-Disk till full with a blocksize of 99M gave me 350M/s write performance.

share|improve this answer
    
I confirm this is at least twice as fast as the accepted solution. However I didn't notice any noticeable performance improvement from varying the blocksize (though there is a huge decrease of performance without the bs argument). – Skippy le Grand Gourou Oct 29 '13 at 17:40

Well, you could do this:

dd if=/dev/zero count=1024 bs=1024 |
  tr '\000' '\001' > file
share|improve this answer
    
One fill would be '\377', no? – Neil Jun 5 '12 at 21:24
    
Hmm, I guess it depends on what you want. This will fill a file with bytes of value 1 (01 01 01 01 ...). Using \377 gets you all bits set to 1 (so FF FF FF FF ...). Depends on the OP's requirements. – larsks Jun 5 '12 at 21:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.