lsblk
can show you the connection type, and makes it easy to configure the output you want.
Use lsblk -O
to see it's full output, or check lsblk --help
to see the available output columns. Then use -o
(or --output
) to list the columns you want.
For example:
lsblk -o NAME,TYPE,FSTYPE,RM,TRAN,SIZE,MOUNTPOINT
This uses
TRAN
: the "device transport type". Usually "usb" or "sata".
RM
: "removable device".
SIZE
: to be able to exclude empty USB slots. These may show up but with a size of 0.
To use it in a script, there is the -P
option : "use key='value' output format".
So for example:
lsblk -P -b -o 'KNAME,TYPE,TRAN,RM,FSTYPE,SIZE,MOUNTPOINT' \
| while read -r vars; do
eval "$vars"
if ((SIZE)) && [ "$TRAN" = "usb" ]; then
echo "$KNAME is a USB disk: $vars"
fi
done