Sunday, May 5, 2024
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 46426  / 2 Years ago, sun, january 30, 2022, 4:01:37

I try to find the size of my disk, so i runned the below command



$ sudo fdisk -s /dev/sda
976762584


It shows like above. I think the size(976762584) of the disk is shown in kilobytes. How do i convert the value to megabytes or gigabytes through terminal for better understanding?


More From » command-line

 Answers
5

The shell does fixed-width integer arithmetic with no check for overflow. So, when doing a calculation that might involve either large numbers or fractions, bc is a good choice. To get megabytes:



$ echo "scale=2; $(sudo fdisk -s /dev/sda6) / 1024" | bc
13641.75


To get gigabytes:



$ echo "scale=2; $(sudo fdisk -s /dev/sda6) / 1024^2" | bc
12.70


The assignment scale=2 tells bc to display two decimal places.


[#25685] Tuesday, February 1, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
urvedcaly

Total Points: 171
Total Questions: 118
Total Answers: 124

Location: Cape Verde
Member since Fri, Nov 27, 2020
4 Years ago
;