在bash中获取图像大小

时间:2018-02-20 16:03:51

标签: linux bash

我想获得图片大小。图像位于文件夹中,名称为encodedImage.jpc

a="$(ls -s encodedImage.jpc | cut -d " " -f 1)"
temp="$(( $a*1024 * 8))"
echo "$a"

输出不正确。如何获得尺寸?谢谢

3 个答案:

答案 0 :(得分:3)

Better than parsing ls output,正确的方法是使用命令stat,如下所示:

stat -c '%s' file

检查

man stat | less +/'total size, in bytes'

答案 1 :(得分:1)

如果按大小表示字节或漂亮的字节,你可以使用

ls -lh

 -h      When used with the -l option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to three or less using base 2 for sizes.

如果您只是试图单独删除文件大小,我想更完整的答案(我添加了文件名,您可以删除,$9以删除它)

ls -lh | awk '{print $5,$9}'

答案 2 :(得分:0)

你可以使用这个命令

du -sh your_file
相关问题