开发者

How can I count the number of bytes in a binary file in Bash?

开发者 https://www.devze.com 2023-01-24 15:09 出处:网络
In Bash, I can count the number of bytes in a text file like this: cat textfile.txt | wc -c However, I can’t cat the contents of a binary file, e.g., a PNG bitmap image file, to standard input.

In Bash, I can count the number of bytes in a text file like this:

cat textfile.txt | wc -c

However, I can’t cat the contents of a binary file, e.g., a PNG bitmap image file, to standard input.

How can I count the number of bytes in a bitmap image file?

I’d rather not count the number of bytes used to store it on disk, as I understand that this can differ between operating systems. Instead, I’m looking for a way to count the number of bytes that would be transferred if the file were served over HTTP (discoun开发者_如何学Cting HTTP headers, of course).


wc -c yourimg.png should do what you want, without a “useless use of cat”.

0

精彩评论

暂无评论...
验证码 换一张
取 消