簡體   English   中英

獲取bash中圖像的大小

[英]Get size of image in bash

我想獲取圖像的大小。 圖像位於文件夾中,名稱為encodedImage.jpc

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

輸出不正確。 如何獲得尺寸? 謝謝

比解析ls輸出更好 ,正確的方法是使用如下命令stat

stat -c '%s' file

校驗

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

如果按大小表示字節或漂亮字節,則可以使用

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}'

你可以使用這個命令

du -sh your_file

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM