You can directly read the device files in the /dev directory, then trim the output as required. For example, the HDD device files in my /dev directory -
Originally Posted by Artif
To get the device name (in case there are also sdb, sdc... etc. are present with valid partitions on them) -
~$ ls -1 /dev/sd??
You can also use "ls -1 /dev/sd? | cut -c 6-", but it will also list the devices which doesn't have a valid partition on it (e.g. - a modem's card reader with no card in it)
~$ ls -1 /dev/sd?? | cut -c 6-8 | sort -u
To parse the partition numbers -
$ ls -1 /dev/sd?? | cut -c 8-
..if only the last number is required. But that may be confusing if more than one device is present.
$ ls -1 /dev/sd?? | cut -c 9
But anyway, I hope it gives you an idea to parse the parts of interest, then use them as they are or further strip them as you wish.