Sorting a device list

Peter Steele psteele at maxiscale.com
Sat Nov 28 17:48:22 UTC 2009


Can anyone recommend a quick and dirty way to sort a device list? For example, if I do this:

ls /dev/ad* | sort

I get something like this:

/dev/ad10
/dev/ad4
/dev/ad6
/dev/ad8

I can add -g, but it doesn't help:

ls /dev/ad* | sort -g

/dev/ad10
/dev/ad4
/dev/ad6
/dev/ad8

I need to skip the device prefix before applying the -g option. Something like this works:

ls /dev/ad*|sort -g -k 1.8

/dev/ad4
/dev/ad6
/dev/ad8
/dev/ad10

but this assumes the device name is just two characters long. I want a quick way to sort a generic device list like this, considering only the numeric part of the device for the key. Is there a quick and dirty way to do this or do I need to pipe it into a perl script or something?



More information about the freebsd-questions mailing list