Get simple list of all disks
ls (shows individual partitions though)
# ls /dev/sd*
/dev/sda /dev/sda1
ls (just disks, ignore partitions)
# ls /dev/sd*[a-z]
/dev/sda
fdisk
# fdisk -l 2>/dev/null |awk '/^Disk \//{print substr($2,0,length($2)-1)}'
/dev/xvda
You can use df
to list all mounted partitions, the command will output something like
$ df
/dev/sda1 230467740 37314652 181422912 18% /
udev 10240 0 10240 0% /dev
tmpfs 5599420 0 5599420 0% /sys/fs/cgroup
/dev/sdb1 961303548 130106540 782342500 15% /media/Data
..
If you want to list only your mounted disks, you can filter the output with grep, for example
$ df | grep '^/dev'
/dev/sda1 230467740 37314752 181422812 18% /
/dev/sdb1 961303548 130106540 782342500 15% /media/Data
which matches lines starting with /dev
, or, if you want only the names
df | grep -o '^/dev[^ ]*'
/dev/sda1
/dev/sdb1
which will match strings starting with /dev
up to the first white space character, and output only the match (option -o, --only-matching
),
Edit
The above will list all partitions, if you need to list the disks, use lsblk
instead, with the following options (pattern matching as above)
$ lsblk -dp | grep -o '^/dev[^ ]*'
/dev/sda
/dev/sdb
-d
lists only the device, without partitions-p
outputs the whole path
Edit 2
As pointed out below, lsblk -dpno name
will give the same result, no need for grep
.