繁体   English   中英

Linux Shell-检查并设置二进制文件的最后一个字节

[英]Linux shell - check and set last byte of a binary file

我有一组要处理的文件。 我无法控制文件的创建或删除。 但是我知道每个文件的最后一个字节始终是xFF,并且未使用。

我想处理文件并修改最后一个字节,这样我就可以知道它们已被处理。 我在Shell中找不到任何单字节操作的特定示例。

伪码

for file in *
do
if (lastbyteof($file) == xFF)
then
    # Process this file
    ...
    # Mark the file so we don't process it again
    lastbyteof($file) = xF0
fi

我将要求从最后一个字节更改为第四个字节,并像这样处理它。 任何改进或替代建议都非常欢迎。

for file in *.ts
do
    # Get the value of the fourth byte (skip the first 3)
    checkByte=`hexdump -n1 -s3 -e'"" 1/1 "%02xf"' "$file"`
    if [ $checkByte == "ff" ]
    then
        # Process this file

        # Change the fourth byte to 0xFE
        echo -ne \\xFE | dd conv=notrunc bs=1 count=1 seek=3 of="$file"
    fi
done

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM