Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
Find external and internal devices attached to a system in Linux

How can i find through terminal that which devices are external and which are internal.

By external i mean devices attached to USB port. For Example, USB Drive, Portable USB HardDrive etc

By internal i mean devices attached internally. For Example, SATA Harddisk etc.

Thanks

share|improve this question
    
exact duplicate (user crossposted): superuser.com/questions/113086/… –  quack quixote Feb 25 '10 at 9:28
add comment

migrated from stackoverflow.com Feb 25 '10 at 8:11

This question came from our site for professional and enthusiast programmers.

marked as duplicate by quack quixote, Diago Feb 25 '10 at 9:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4 Answers

up vote 2 down vote accepted

You can use lsusb to list USB devices, lspci to list PCI devices, and lspcmcia to list PCMCIA devices.

If you only care about disk-type devices, you can also look into /dev/disk/by-id. The link name of the device start with the connection type (usb, ata, scsi-sata, etc.)

share|improve this answer
    
I'm lazy, so I always look into /proc/partitions to get an idea of any attached and usable block devices. –  ypnos Feb 24 '10 at 23:45
add comment

This isn't in general possible - lots of machines have internal USB devices (things like Bluetooth interfaces and fingerprint readers are often implemented in this way), and it's possible to have external SATA devices (the laptop I'm using now has an eSATA port). SCSI devices can also be internal or external.

share|improve this answer
add comment

Block devices have a "removable" attribute. While this does not exactly correspond to internal/external (e.g. an internal CDROM is "removable" and an eSATA drive may be misclassified), it may be close enough for your purposes.

$ cd /sys/block/
$ grep ^ */removable
dm-0/removable:0
dm-1/removable:0
dm-2/removable:0
dm-3/removable:0
dm-4/removable:0
dm-5/removable:0
dm-6/removable:0
dm-7/removable:0
dm-8/removable:0
fd0/removable:1
hdc/removable:1
loop0/removable:0
loop1/removable:0
loop2/removable:0
loop3/removable:0
loop4/removable:0
loop5/removable:0
loop6/removable:0
loop7/removable:0
md0/removable:0
md1/removable:0
sda/removable:0
sdb/removable:0
sdc/removable:0
sdd/removable:0
sde/removable:1
sdf/removable:1
sdg/removable:1
sdh/removable:1
sdi/removable:1
share|improve this answer
add comment

here's a small script example using HAL , if you have it.

store=$(hal-find-by-capability --capability "storage")
for s in $store
do
  r=$(hal-get-property --udi ${s} --key storage.removable)
  if [ $r = "true" ]; then
    hal-get-property --udi ${s} --key info.product
    prod=$(hal-get-property --udi ${s} --key info.product)
    type=$(hal-get-property --udi ${s} --key storage.drive_type)
    device=$(hal-get-property --udi ${s} --key block.device)
    mdir=$(awk -vdev="$device" '$0~dev{print $2}' /etc/mtab)
    echo Product: ${prod}
    echo Type: ${type}
    echo Mounted on: ${mdir}
  fi
done

vol=$(hal-find-by-capability --capability "volume")
for v in $vol
do
   mountpt=$(hal-get-property --udi ${v} --key volume.mount_point)
   blk=$( hal-get-property --udi ${v} --key block.device )
   echo "mount point: $mountpt"
   echo "device: $blk"
done

Use hal-device command to show HAL devices.

share|improve this answer
    
Yay. Now, any idea how to do this with freedesktop.org/wiki/Software/DeviceKit HAL's replacement? :-/ –  ephemient Feb 25 '10 at 5:05
    
I looked at the page, its new i guess. no idea how. –  user31894 Feb 25 '10 at 5:18
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.