oflag option in GNU dd - equivalent in FreeBSD dd ?

Oliver Fromme olli at lurza.secnetix.de
Tue Oct 23 12:45:31 PDT 2007

Dan Nelson wrote:
 > Oliver Fromme wrote:
 > > Of course, the easiest way is to do this:
 > > 
 > > $ dd if=/blah >> /bleh

I still think the OP should prefer that solution.

 > > If you cannot do that, please explain why.  If you know
 > > your reason, there might be an alternative way to do it.
 > > 
 > > > dd if=/blah of=/bleh conv=notrunc seek=`ls -s /bleh | cut -f1 -d ' ' -`
 > > > 
 > > > I don't know if any simpler way is possible (anyone?).
 > > 
 > > $ dd if=/blah of=/bleh conv=notrunc seek=$(stat -f%z /bleh)
 > I don't think that will work, since seek's argument is in blocks.

Oops, you're right.  I forgot about that.

 > Even
 > if you divide by 512 (or whatever you decide to set bs=), if the file
 > you're appending do isn't a multiple of the blocksize, you'll end up
 > chopping part of the end off.

I wonder how GNU dd's "append" oflag behaves in that case.
It would also either have to chop some bytes off the end,
or leave a gap of zeros.  Either way could be emulated.

$ dd if=/blah of=/bleh conv=notrunc seek=$(( $(stat -f%z /bleh) / 512 ))

That one would chop some bytes of the end if the file size
isn't a multiple of 512 (the default block size).  To leave
a gap in that case, use this formula:

$ ... seek=$(( ($(stat -f%z /bleh) + 511) / 512 ))

Best regards

Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"Emacs ist für mich kein Editor. Für mich ist das genau das gleiche, als
wenn ich nach einem Fahrrad (für die Sonntagbrötchen) frage und einen
pangalaktischen Raumkreuzer mit 10 km Gesamtlänge bekomme. Ich weiß nicht,
was ich damit soll." -- Frank Klemm, de.comp.os.unix.discussion

More information about the freebsd-questions mailing list