Find files without a number

filenamesfindwildcards

I am trying to write a simple script that will iterate through all drives except sda. Right now I have this

for i in $(find /dev/ -name "sd*" ! -name "sda*")
do
        echo $i
done

However this includes partitions like /dev/sdb1, whereas I only want the root drive like /dev/sdb.

How do I modify the find statement to guarantee I don't get any of the numbered files?

Best Answer

Don't use command substition in that manner, you'll end up with problems when word splitting is applied. Just do

find /dev/ -regex '/dev/sd[a-z]+' ! -name 'sda'

If your true objective is to show base block devices, just look in /sys/block.

Related Question