Questions tagged [dd]

dd is a traditional utility for binary data copies

dd is a command to copy input to output, granting control over the block size and allowing partial copies and progress reports as well as endianness, case and ASCII/EBCDIC translations. It is a traditional Unix command, able from the start to cope with binary data.

A major limitation of dd is that it copies blocks, and does not count partial blocks specially, so it may copy less data than intended. dd is also not particularly fast.

Although dd is very often mentioned in tutorials as a way to copy disk images, all the “magic” is in fact in the /dev/ entries. For example, to make an image from a disk partition, you can use the command

cat /dev/sda1 >sda1.img

Further information

External links

Standards and implementation manuals

899 questions
84
votes
8 answers

Best way to remove bytes from the start of a file?

Today I had to remove the first 1131 bytes from an 800MB mixed text / binary file, a filtered subversion dump I'm hacking for a new repository. What's the best way to do this? To start with I tried dd bs=1 skip=1131 if=filtered.dump…
Rup
  • 943
44
votes
3 answers

What is the difference between 'bs', 'count' and 'seek' in dd command?

I've read many guides and forum posts describing how to use dd, but one thing I've noticed is that people always use different values for the bs=, count= and seek= switches. Please can someone explain what these switches do exactly (the man page…
Eric
  • 457
42
votes
4 answers

Is dd able to overwrite parts of a file?

I have a 1TB big file (disk-image from a damaged drive) and a 1.3MB small file (beginning of a disk-file). Using the contents of the small file, I want to overwrite portions of the big file. That is, I want to insert/overwrite the first 1.3MB of the…
bos
  • 887
32
votes
4 answers

'seek' argument in command dd

Can some explain me what is happening in the following lines? dd if=/dev/urandom bs=4096 seek=7 count=2 of=file_with_holes especially seek part is not clear Man pages says : seek=BLOCKS skip BLOCKS obs-sized blocks at start of…
user2799508
  • 1,712
25
votes
4 answers

What's the difference between these two dd commands?

What's the difference between two dd commands that have different bs and count values, as long as they multiply to the same? For example: dd if=/dev/random of=aa bs=1G count=2 dd if=/dev/random of=aa bs=2G count=1
Rocky
  • 1,599
  • 2
  • 15
  • 10
25
votes
6 answers

How to pad a file to a desired size?

I have a file that I want to pad until it reaches 16 MiB (16777216 bytes). Currently it is 16515072 bytes. The difference is 262144 bytes. How do I pad it? This doesn't seem to be working: cp smallfile.img largerfile.img dd if=/dev/zero…
tarabyte
  • 4,296
22
votes
3 answers

What does the two numbers mean respectively in dd's “a+b records” stats?

The first 2 lines in dd stats have the following format: a+b records in c+d records out Why 2 numeric values? What does this plus sign mean? It's usually a+0, but sometimes when I use bigger block size, dd prints 0+b records out
basin
  • 2,051
21
votes
3 answers

Use `dd` to cut file end part

There is probably simple trick to do this, but I can't figure from man page. How do I cut last 1MB from file with undetermined size for example, by using dd?
zetah
  • 2,057
15
votes
1 answer

dd command oflag direct and sync flags

I have the below shell script and I wonder whether oflag's direct does the syncing automatically or if it is explicitly required: dd bs=10M oflag=direct,sync of=ofile.bin Also what is the difference in saying oflag=sync and conv=sync and…
15
votes
5 answers

Resuming a DD of an entire disk

I'm overwriting my hard drive with random data using the good old dd: dd if=/dev/urandom of=/dev/disk/by-uuid/etc bs=512 It's a 2TB array and my MacBook (running Linux, ok?) can only write data at around 3.7MB/s, which is pretty pathetic as I've…
Naftuli Kay
  • 39,676
14
votes
2 answers

Why does dd from /dev/urandom stops early?

On my current Linux system (Debian Jessie amd64), I'm getting different behavior for dd using /dev/urandom (/dev/random behavior is properly documented). If I naively want 1G of random data: $ dd if=/dev/urandom of=random.raw bs=1G count=1 0+1…
malat
  • 3,032
14
votes
8 answers

how to use dd to fill drive with 1's

Filling a drive with /dev/urandom seems to be very slow, so I created a file filled with FF: dd if=/dev/zero ibs=1k count=1000 | tr "\000" "\377" >ff.bin I'd like to fill the drive with copies of this file but the following command only writes…
linuxfix
  • 381
12
votes
4 answers

How to prevent dd's progress from being meaningless on Linux?

When running dd command to copy an ISO on Linux, I get a single progress print that stays open for a long time (many minutes). Then another at the end. The problem seems to be that a very large cache is being used which confuses dd 's output. sudo…
ideasman42
  • 1,211
12
votes
3 answers

Using DD to copy only half (part) of removable device

I had a 32GB SD Card with this structure (or very close): luis@Fresoncio:~$ sudo fdisk -l Disk /dev/mmcblk0: 29.2 GiB, 31393316864 bytes, 61315072 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512…
11
votes
2 answers

dd command bs option at end of disk

If I were to use the dd command as follows: dd if=/dev/zero of=/dev/sdX bs=16M What happens at the end of the disk if it is not an exact multiple of 16M? Does that mean the last remaining portion of the disk is not zeroed? I noticed in…
user281193
1
2 3 4