Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


I want to write a file at various offsets into the partition

Partition /dev/part2 is mounted at /mypart

I tried the command below:

dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=0 count=15000
dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=15000 count=15000
dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=30000 count=15000

Are they doing what I want to do? Are they writing a file to the partition at offset 0, 15000K and 30000K?

At what offset is the file written if I omit seek from dd

dd if=/dev/urandom of=/mypart/aaa bs=1024 count=15000
share|improve this question

migrated from stackoverflow.com Mar 7 '12 at 23:14

This question came from our site for professional and enthusiast programmers.

Why? What are you really trying to do? – psusi Mar 8 '12 at 1:11
up vote 6 down vote accepted

You can't "write a file" at an "offset into the partition" using dd this way -- you are just writing data into a file named "aaa" within the mounted file system on that partition.

"seek=" will indeed cause dd to lseek to the given position before beginning its writes -- that means that it will simply create a file called /mypart/aaa and lseek the given number of blocks into that file before writing.

If you omit "seek=", dd will write starting at the beginning of the file named "aaa".

share|improve this answer
I see. If I write directly to the device file at an offset, I basically destroy the filesystem on the partition. I tried that already. So how do I write data to a file at a particular offset in the file system? See my original requirement above. – abc Mar 7 '12 at 1:10
You're asking how to do something you can't do. Of course if you just write to some arbitrary location in the partition you will destroy it, and there is no API for telling a file system to write at an arbitrary location -- you don't even know if that location is available for data to be written in it and not, say, allocated for metadata. I must confess that I have no idea why you would want to be able to do this. – Perry Mar 7 '12 at 1:15
If you have a filesystem on a device (like partition), you should think that the fs "owns" that device and you shouldn't touch it except by going through the fs. – XTL Mar 7 '12 at 8:25

Re: "are they doing what I want to do"


strace dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=15000 count=15000

and see what system calls are being made.

share|improve this answer

Your Answer


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.