Linux – How to show available disks on a Linux system

awklinux

If i run fdisk -l I get an output as:

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0003ad9d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        1306    10490413+  83  Linux
/dev/sda2            1307        2612    10490445   83  Linux

Disk /dev/sdb: 120.0 GB, 120034123776 bytes
        255 heads, 63 sectors/track, 14593 cylinders
        Units = cylinders of 16065 * 512 = 8225280 bytes
        Disk identifier: 0x0003ad9d

       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1        1306    10490413+  83  Linux
    /dev/sdb2            1307        2612    10490445   83  Linux

How can I just show the disks available on system such that they may with a space between them as:

/dev/sda /dev/sdb /dev/sdc

Best Answer

You can use pipes to redirect the output

 fdisk -l | grep ^Disk | awk -F:  '{ print $1 }' |  awk -F" "  '{ print $2 }'
  • fisk -l: get the full disk output
  • grep Disk: filter the line starting with Disk
  • awk -F: '{ print $1 }': get first part where the separator is ":"
  • awk -F" " '{ print $2 }': get the second part where the separator is space
Related Topic