Question

I made a script to create files with random data in them (mostly based on dd) in order to do performance testing of a caching server. I need to periodically update these files. The cache server will read the first 1000 bytes of a file and if it recognize it, it will serve the content from the cache instead of some server far away on the internet.

It order to speed up the recreation of the new files, I need to simply update the first 1000 bytes. How can I open a file and update the first 1000 bytes with random data? I want to avoid creating a chunk of 1000 random bytes and append the rest of the original file. This means rewriting the original file on the disk and it's too slow.

I don't think it's possible to use dd for that. It looks like dd is going to write a new file anyway. Correct me if I am wrong.

What are my options? I wouldn't mind doing this in Python but I am a beginner... not sure this is the easiest to start with.

Was it helpful?

Solution

You can use dd for this by adding "conv=notrunc", e.g.

dd if=/dev/urandom of=myrandom bs=100 count=10 conv=notrunc

This will tell dd not to eliminate the rest of the file when overwriting the first 1000 bytes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top