Super User is a question and answer site for computer enthusiasts and power users. 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 have a 512G disk and I want to clear the last 512k bytes at the end of the disk.

I usually clear it by dd if=/dev/zero of=/dev/da0 the whole disk.

Which way is the fastest to do this operation?

share|improve this question

migrated from Apr 8 '10 at 16:16

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

up vote 6 down vote accepted

As already pointed out, dd accepts the seek=BLOCKS parameter, which skips BLOCKS blocks in the output file.

Now you need to know the exact size of the disk, if you want to write the last 512kB. On linux, you can use the blockdev --getsz DEVICE command to get the size, in units of 512B.

So the command-line becomes something like:

dd if=/dev/zero of=$YOUR_DEV bs=512 seek=$(( $(blockdev --getsz $YOUR_DEV) - 1 )) count=1
share|improve this answer
This accepted (?) answer blanks the last 512 bytes of the file while the question was about 512 kilobytes, which is quite larger. The command should be: dd if=/dev/zero of=$YOUR_DEV bs=512 seek=$(( $(blockdev --getsz $YOUR_DEV) - 1024 )) count=1024 – jlliagre Aug 29 '13 at 22:47

Use the seek predicate to go to the end of the disk.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .