Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What other tools should I use to read and write files with truncation, seeking and skipping. dd's command line options seem inconvenient and foreign and I don't like choosing between slow, but precise seeking mode (bs=1) and fast, but inflexible mode (bs=4k or whatever).

Are there more modern tools to read 555 bytes from one file (or pipe or socket or dev) from position 31337 and write them to the other file at position 128205 (using blocks 512+43), with or without truncation?

share|improve this question
2  
I still don't see what is wrong with dd. You could always put a shell script wrapper around it if you don't like the interface. dd is in the POSIX standard, which is a huge plus. –  jw013 Jul 31 '12 at 18:55
1  
The main wrong thing is inability to seek to or skip fractional blocks. Second wrong thing that status=noxfer is not default and is broken and that I need iflag=fullblock (omit in some script => broken data). –  Vi. Jul 31 '12 at 20:25
    
You can combine fast-inflexible with slow-precise, e.g. like so: dd bs=1M skip=TO_CHUNK count=1 | dd bs=1 skip=OFFSET. It takes some arithmetic but a wrapper script can deal with that. –  Thor Jul 31 '12 at 20:42
1  
1. bs=1 => the whole pipeline is slow. For example I may want to dump video file starting from some exact frame. 2. "It takes some arithmetic" => not very suitable for oneliners and routine shell commands. –  Vi. Jul 31 '12 at 20:58
    
possible duplicate of dd vs cat -- is dd still relevant these days? –  Gilles Jul 31 '12 at 23:06

1 Answer 1

There is the tool ddrescue (watch out, there is also dd_rescue which is a different program with almost the same functionality). It uses the more familiar syntax with the single dash for short or double dash for long options. From the man page:

   -i, --input-position=<bytes>
          starting position in input file [0]

   -K, --skip-size=<bytes>
          initial size to skip on read error [64 KiB]

   -M, --retrim
          mark all failed blocks as non-trimmed

   -o, --output-position=<bytes>
          starting position in output file [ipos]
share|improve this answer
1  
ddrescue - - -> Infile and outfile are the same., ddrescue /dev/stdin /dev/stdout -> Infile and outfile are the same.. Bad beginning of the story... –  Vi. Jul 31 '12 at 20:59
    
I just tried with dd_rescue. It throws a warning that the file (stdin) is not seekable, but proceeds. You can give it a try. However, ddrescue feels more full-featured and mature. –  Marco Jul 31 '12 at 21:32
    
@Vi.: Don't shoot the messenger. ddrescue is right, pipes aren't seekable. If you want to start reading at a specific point in a file, you need to give it access to the file in question, not data piped from another program. Also beware that using pipes fights against this wish of yours for ultimate speed, since the only way to emulate seeking in a pipe is to read and throw away the parts you don't want to process. Seeking within an actual file is far more efficient. –  Warren Young Aug 1 '12 at 10:53

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.