Is there a command to write random garbage bytes into a file?

Viewed 59346

I am now doing some tests of my application again corrupted files. But I found it is hard to find test files.

So I'm wondering whether there are some existing tools, which can write random/garbage bytes into a file of some format.

Basically, I need this tool to:

  1. It writes random garbage bytes into the file.
  2. It does not need to know the format of the file, just writing random bytes are OK for me.
  3. It is best to write at random positions of the target file.
  4. Batch processing is also a bonus.

Thanks.

4 Answers

You can also use cat and head. Both are usually installed.

# write 1024 random bytes to my-file-to-override
cat /dev/urandom | head -c 1024 > my-file-to-override
Related