Reputation: 855
I want to get size of image. The image is in folder by name encodedImage.jpc
a="$(ls -s encodedImage.jpc | cut -d " " -f 1)"
temp="$(( $a*1024 * 8))"
echo "$a"
The output is not correct. How to get size? Thank You
Upvotes: 1
Views: 1991
Reputation: 185025
Better than parsing ls
output, the proper way is to use the command stat
like this :
stat -c '%s' file
Check
man stat | less +/'total size, in bytes'
Upvotes: 3
Reputation: 5867
If by size you mean bytes or pretty bytes can you just use
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.
I guess the more complete answer if you're just trying to tear off the file size alone (I added the file name as well you can remove ,$9
to drop it)
ls -lh | awk '{print $5,$9}'
Upvotes: 1