Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to pad a file with 0xFF using dd?

This command will pad the output file with zeroes until the file size reaches 100 KB:

dd if=inputFile.bin ibs=1k count=100 of=paddedFile.bin conv=sync

However, I want to pad a file with 0xFFs instead of 0x00s.

share|improve this question

2 Answers

up vote 7 down vote accepted

You can first create paddedFile.bin filled with 0xFF. Then insert the content of inputFile.bin.

$ tr "\000" "\377" < /dev/zero | dd ibs=1k count=100 of=paddedFile.bin
100+0 records in
200+0 records out
102400 bytes (102 kB) copied, 0,0114595 s, 8,9 MB/s

$ hexdump -C paddedFile.bin 
00000000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00019000

$ hexdump -C inputFile.bin 
00000000  66 6f 6f 0a 62 61 72 0a                           |foo.bar.|
00000008

$ dd if=inputFile.bin of=paddedFile.bin conv=notrunc
0+1 records in
0+1 records out
8 bytes (8 B) copied, 7,4311e-05 s, 108 kB/s

$ hexdump -C paddedFile.bin 
00000000  66 6f 6f 0a 62 61 72 0a  ff ff ff ff ff ff ff ff  |foo.bar.........|
00000010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00019000

In the second dd invocation you have to use conv=notrunc so the output file does not get truncated.

see also: http://www.commandlinefu.com/commands/view/6483/fill-a-hard-drive-with-ones-like-zero-fill-but-the-opposite-

share|improve this answer

i found a solution on comandlinefu, it involves tr to change the zeros to ones.

http://www.commandlinefu.com/commands/view/6483/fill-a-hard-drive-with-ones-like-zero-fill-but-the-opposite-

Good Luck

share|improve this answer
How do you prevent it from changing the actual data of inputFile.bin? – Daniel Beck Apr 25 '11 at 6:28
I don't know, just found that command by googling for /dev/zero opposite :) – kev Apr 25 '11 at 6:36
Well, it converts zeros to ones, but not only in the padding area. He doesn't end up with a lot of the data from inputFile.bin, does he? – Daniel Beck Apr 25 '11 at 6:38
Right, didnt read the question very well. – kev Apr 25 '11 at 6:41

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.