Does lsblk
always list disks in ascending order (each device letter increasing by one ) and sorted?
For example:
lsblk | awk '{print $1}'
NAME
fd0
sda
├─sda1
└─sda2
├─vg00-lv_root
├─vg00-lv_swap
└─vg00-lv_var
sdb
sdc
sdd
sde
sdf
sdg
sdh
sdi
sdj
sdk
We do not want to get it like the examples below
Example of non ordered disk list (output edited for the example )
lsblk | awk '{print $1}'
NAME
fd0
sda
├─sda1
└─sda2
├─vg00-lv_root
├─vg00-lv_swap
└─vg00-lv_var
sdb
sdc
sdd
sde
sdi
sdj
sdk
sdf
sdg
sdh
Example of disks starting with sdd
instead of sdb
(again, edited for the example )
lsblk | awk '{print $1}'
NAME
fd0
sda
├─sda1
└─sda2
├─vg00-lv_root
├─vg00-lv_swap
└─vg00-lv_var
sdd
sde
sdf
sdg
sdh
sdi
sdj
sdk
sdl
sdm
Best Answer
From the
lsblk(1)
manual page:If you require the output to be sorted, I'd suggest using the
-o
(output columns) and-x
(sort column) options. Uselsblk --help
to get a list of the column names.For example: