I need a large number of damaged .png files in order to test my project. To that end, I need to set all bytes from the 0x054-th to the  0xa00-th to 0..png files contain chunks with checksums, I want to alter the image data chunk (IDAT), without updating the checksum. Furthermore, I want to damage a lot of bytes, so that a visible (black) area appears when displaying the image (provided the viewing program ignores the checksum mismatch).Here is what I have got so far:#!/bin/sh# This script reads all .png or .PNG files in the current folder,# sets all bytes at offsets [0x054, 0xa00] to 0# and overwrites the files back.temp_file_ascii=outfile.txttemp_file_bin=outfile.pngtarget_dir=.start_bytes=0x054stop_bytes=0xa00len_bytes=$stop_bytes-$start_bytesfor file in $(find $target_dir -name *.png)         #TODO: -name *.PNG)do    # Copy first part of the file unchanged.    xxd -p -s $start_bytes $file > $temp_file_ascii    # Create some zero bytes, followed by 'a',    # because I don't know how to add just zeroes.    echo $len_bytes: 41 | xxd -r >> $temp_file_ascii    # Copy the rest of the input file.    # ??    mv outfile.png $filedoneEDIT: the finished script, using the accepted answer:#!/bin/shif [ $# != 3 ]then    echo Usage:     echo break_png.sh <target_dir> <start_offset> <num_zeroed_bytes>    exitfifor file in $(find $1 -name *.png)do    dd if=/dev/zero of=$file bs=1 seek=$(($2)) count=$(($3)) conv=notruncdone
Alter certain bytes in many files
bash;shell script;files;binary
You can do something much simpler with dd:dd if=/dev/zero \   of=$your_target_file \   bs=1 \   seek=$((start_offset)) \   count=$((num_zeros)) \   conv=notruncWith $start_offset being the start of your range of bytes to zero out (zero-based, as in to erase from the nth byte, use n-1), and $num_zeros the length of that range. The $((...)) will take care of converting hexadecimal to decimal.(Other tests you could run would be to set if to /dev/urandom rather than /dev/zero, or overwrite the checksums with random data too.)