ash shell list disks code example
Example 1: list all hard drives linux
user@system:~$ fdisk -l
Disk /dev/loop0: 7.5 MiB, 7811072 bytes, 15256 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop1: 89.5 MiB, 93818880 bytes, 183240 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop2: 4.9 MiB, 5148672 bytes, 10056 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop3: 4.7 MiB, 4919296 bytes, 9608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop4: 89.5 MiB, 93835264 bytes, 183272 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop5: 88.2 MiB, 92483584 bytes, 180632 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 477 GiB, 512110190592 bytes, 1000215216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 129F4EE6-2A54-4639-BFCA-2CC09DFC8566
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 1000214527 999163904 476.4G Linux filesystem
Example 2: list all hard drives linux
user@system:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 3.5M 1.6G 1% /run
/dev/sda2 468G 204G 242G 46% /
tmpfs 7.8G 109M 7.7G 2% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/loop0 7.5M 7.5M 0 100% /snap/canonical-livepatch/54
/dev/loop1 90M 90M 0 100% /snap/core/6034
/dev/loop2 5.0M 5.0M 0 100% /snap/canonical-livepatch/50
/dev/loop4 90M 90M 0 100% /snap/core/6130
/dev/loop3 4.8M 4.8M 0 100% /snap/canonical-livepatch/49
/dev/loop5 89M 89M 0 100% /snap/core/5897
/dev/sda1 511M 6.1M 505M 2% /boot/efi
tmpfs 1.6G 16K 1.6G 1% /run/user/121
tmpfs 1.6G 44K 1.6G 1% /run/user/1000