Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux command to lookup total disk and harddrive numbers [closed]

Tags:

linux

bash

redhat

is there a command in bash that can give you the total number of disk space/harddrive numbers.

I know the df command is very helpful 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 '16TB' in the end, is there a command handy or I have to write some program to calculate the total disk based on the output from df.

like image 898
B.Mr.W. Avatar asked Dec 15 '14 19:12

B.Mr.W.


People also ask

How do I find the size of a hard drive in Linux?

I recommend hdparm command, which provides a command-line interface to various hard disk ioctls supported by the stock Linux ATA/IDE device driver subsystem. This command reads/request identification information such as disk size, description, and much more directly from the drive, which is displayed in a new expanded format.

How to list all disks and their names in Linux?

Another option is to run the following command to list all disks and their names: # ls -lF /dev/disk/by-id/ Linux show block device such as hard disk drive attributes Open the terminal app and then type the blkid command:

How do I check disk space in Linux terminal?

Check Linux Disk Space Using df Command. You can check your disk space simply by opening a terminal window and entering the following: df. The df command stands for disk free, and it shows you the amount of space taken up by different drives. By default, df displays values in 1-kilobyte blocks.

How to find hard drive serial number in Linux?

There are several tools to retrieve the hard drive info in Linux. From GUI-based ones to command line-based tools like hwinfo. However, not all tools display the serial number of the hard drive installed on your Linux system, including hwinfo which only displays the hard drive model and vendor.


2 Answers

What about:

df --total

Hint: first look to the manual page: man df. I find it hard these days to find aspects for a program that have not been implemented by some nice flag. Linux people simply seem to know what programmers want/need.

Or if you only want the total:

df --total | tail -n 1

And if you want to specify it in a special blocksize (like TB), you can set the -B flag:

df --total -BT | tail -n 1

And in case you are only interested in the total size (for instance, you wish to use the result in another bash program):

df --total -BT | tail -n 1 | sed -E 's/total *([^ ]*).*/\1/'
like image 177
Willem Van Onsem Avatar answered Nov 13 '22 07:11

Willem Van Onsem


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

df --total -h | awk '!/^\//'
  • awk command will print all lines except those who start with character /.
  • df with -h or --human-readable print sizes in powers of 1024 (e.g., 1023M).

The result will looks like the following:

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

As Mounted on field is useless, you can remove it by adding a 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%
like image 34
jherran Avatar answered Nov 13 '22 05:11

jherran