Linux command to find the total number of disks and hard drives

There is a command in bash that can give you the total number of disk spaces / hard disk numbers.

I know that the df command is very useful, but the output is too verbose:

# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda4 721G 192G 492G 29% / tmpfs 129G 112K 129G 1% /dev/shm /dev/sda1 194M 92M 93M 50% /boot /dev/sdj1 917G 547M 870G 1% /data10 /dev/sdk1 917G 214G 657G 25% /data11 /dev/sdl1 917G 200M 871G 1% /data12 /dev/sdm1 917G 200M 871G 1% /data13 /dev/sdn1 917G 200M 871G 1% /data14 /dev/sdo1 917G 200M 871G 1% /data15 /dev/sdp1 917G 16G 855G 2% /data16 /dev/sdb1 917G 4.6G 866G 1% /data2 /dev/sdc1 917G 74G 797G 9% /data3 /dev/sdd1 917G 200M 871G 1% /data4 /dev/sde1 917G 200M 871G 1% /data5 /dev/sdf1 917G 200M 871G 1% /data6 /dev/sdg1 917G 764G 107G 88% /data7 /dev/sdh1 917G 51G 820G 6% /data8 /dev/sdi1 917G 19G 853G 3% /data9 /dev/sda2 193G 53G 130G 30% /home cm_processes 129G 46M 129G 1% /var/run/cloudera-scm-agent/process 

I basically want "16 TB", after all, is there a command, or do I need to write some program to calculate the total disk based on the output from df.

+6
source share
3 answers

What about:

 df --total 

Hint: first look at the man df page: man df . It’s hard for me these days to find aspects for the program that have not been implemented by some good flag. Linux people just seem to know what programmers want / need.

Or if you want everything in all:

 df --total | tail -n 1 

And if you want to specify it in a special block format (for example, TB ), you can set the -B flag:

 df --total -BT | tail -n 1 

And in case you are only interested in the overall size (for example, you want to use the result in another bash program):

 df --total -BT | tail -n 1 | sed -E 's/total *([^ ]*).*/\1/' 
+4
source

CommuSoft's answer is nicer, but here is another solution using awk:

 df -m | awk '{ SUM += $2} END { print SUM/1024/1024"TB" }' 

Using the -m option, you can display the results from df in the same block (MB). Simple separation can easily convert the result to TB.

+2
source

Another solution using awk . This will print the header and general lines:

 df --total -h | awk '!/^\//' 
  • Command
  • awk will print all lines except those starting with the / character.
  • df with -h or --human-readable print sizes of 1024 (e.g. 1023M).

The result will look like this:

 Filesystem Size Used Avail Use% Mounted on total 3.9T 1.7T 2.3T 42% - 

Since the Mounted on field is useless, you can remove it by adding sed to the previous command:

 $ df --total -h | awk '!/^\//' | sed -E 's/Mounted on|\s-//' Filesystem Size Used Avail Use% total 3.9T 1.7T 2.3T 42% 
+2
source

Source: https://habr.com/ru/post/979656/


All Articles