Linux list all usb device will

Listing all USB drives in Linux

How can I get a list of removable drives (plugged into USB) in Linux? I’m fine with using KDE, GNOME or other DE libraries if it would make things easier.

@Viswanathan: «Linux» isn’t Ubuntu (which is, of course, why having a separate askubuntu site at all is stupid, but I digress)

This is not an Ubuntu specific question. I was looking for a programming library solution, but I can use something like Python os module to list the devices with Ignacio Vazquez-Abrams solution anyway.

I’m am also writing a Python script that needs to find a particular USB drive. This seems like a perfectly reasonable place to ask and receive help on this matter.

5 Answers 5

I think a nice idea is to use udev interface from python.

Small example (of course in your case you have adjust some filtering):

In [1]: import pyudev In [2]: pyudev.Context() In [3]: ctx = pyudev.Context() In [4]: list(ctx.list_devices(subsystem='usb')) Out[4]: [Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb2'), Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb2/2-0:1.0'), Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb2/2-2'), 

It is a good way in most cases as new systems use udev.

After all this time the question got unlocked again…

In the end I used UDisks via the D‐Bus interface like shown here.

Sometime back i got this small script ( it’s not mine ) but it surely helped me alot putting just for reference

#!/usr/bin/python import sys import usb.core # find USB devices dev = usb.core.find(find_all=True) # loop through devices, printing vendor and product ids in decimal and hex for cfg in dev: try: #print dir(cfg) sys.stdout.write('Decimal VendorID=' + str(cfg.idVendor) + ' & ProductID=' + str(cfg.bDeviceClass) + ' ' + str(cfg.product) + ' ' + str(cfg.bDeviceSubClass)+ ' ' + str(cfg.manufacturer)+'\n') except: print 

Источник

How to Use the LSUSB Command

The lsusb command, commonly known as the “List USB” command, is one of the most commonly used commands in Linux. As the name implies, this command is used to list all the USB devices that are attached to your Linux system. When combined with different parameters or options, this command can also be used to serve other purposes. This article shows you how to use the lsusb command in Linux.

Note: Linux Mint 20 is used throughout this article to demonstrate the usage of this command. However, you can work with any Linux distribution of your choice.

Install usbutils Package

Before getting started with the lsusb command, install the usbutils package onto your Linux Mint 20 system. To install the package, follow the steps shown below:

Launch the terminal by clicking on the terminal icon, highlighted in the following image:

After you click on this icon, the terminal window will immediately pop up, as shown below:

Before installing the usbutils package, it is highly recommended to update your Linux Mint 20 system to avoid hindrances during the installation. This can be done by executing the update command in the following manner:

Читайте также:  Увеличить системный раздел linux

This command can be seen in the image shown below:

Once your system has been updated, you will see the following output, as mentioned in the image on your terminal:

After successfully updating your system, you can now run the following command without any worries:

This command will install the usbutils package on your Linux Mint 20 system.

The successful installation of the said package will render the following output on your terminal:

Using the lsusb Command

The lsusb command provides information about the USB devices attached to your Linux system. This command may either be used individually or combined with various choices. For this section, we are only interested in running the lsusb command independently, i.e., without any additional parameters or options. Simply run the following command in your Linux Mint 20 terminal to do so:

Upon successful execution of this command, you will see all the information related to any USB buses and devices connected to your system, as in the following image:

Options Used with the lsusb Command

As mentioned previously, the lsusb command can also be used in conjunction with different options. These options include the following:

  • -s: Displays information about any particular USB device, according to the device’s bus number and device number.
  • -v: Shows more detailed information about the USB devices connected to your system.
  • -D: Provides detailed information read from a specific USB device file.
  • -t: Displays all the connected USB devices in the form of a tree or hierarchy.

In the examples given below, you will learn more about the usage of these options.

Example 1: Display a Specific USB Device

To display a specific USB device, you need to know two things about the device: its bus number and its device number. These two items can be determined simply by running the lsusb command alone, as discussed above. Once you know the bus and device numbers of the USB device, run the following command on your terminal:

Replace the BusNum and DeviceNum with the device’s bus number and device number, respectively. For the sake of demonstrating this method, we have used bus number 1 and port number 1, which you can verify in the image below:

After running this command, you will see the USB device, along with the specified bus number and device number on your terminal, as shown in the following image:

Example 2: Display Detailed Information about All USB Devices

To display every detail about all the USB devices that are connected to your system, run the following command in your terminal:

You can also see this command in the image below, for more clarity:

After this command is executed successfully, you will be able to see more details about all the USB devices connected to your system, as seen in the image below:

Example 3: Display Information about a Specific USB Device

As you may have noticed, in the method above, the output with the –v option was quite long. In some situations, you might want to have detailed information only about a single device, instead of having it for all the USB devices attached to your system. If this is the goal, then a detailed output about a single USB device can be achieved by executing the following command in your terminal:

Читайте также:  Linux mint windows borders

Again, to run this command, you will need to know the bus number and device number of the specific USB device that you would like more information about from the device’s particular file. In this example, we have replaced the ‘BusNum’ with 001 and the ‘DeviceNum’ with 002, as shown in the image below:

After running this command, you will be able to see all the details about the specified USB device, read directly from the device’s file, as shown in the following image:

Example 4: Display All USB Devices in a Tree Structure

At times, you may also want to list down all the connected USB devices in the form of a hierarchy or a tree structure, for easier readability. This can be done by executing the following command in your terminal:

This command can also be seen in the image below:

Running this command will display all the USB devices that are connected to your system in the form of a tree structure, as shown in the following image:

Conclusion

This article gives you a detailed overview of the usage of the lsusb command in Linux Mint 20. Now, whenever you require more information about the USB devices attached to your system, you can conveniently make use of this command.

About the author

Aqsa Yasin

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.

Источник

How to List USB Devices Connected to Your Linux System

Mostly, people are interested in knowing what USB devices are connected to the system. This may help troubleshoot the USB devices.

The most reliable way is to use this command:

It shows the webcam, Bluetooth, and Ethernet ports along with the USB ports and mounted USB drives.

list usb with lsusb command linux

But understanding the output of lsusb is not easy and you may not need to complicate things when you just want to see and access the mounted USB drives.

I will show you various tools and commands you can use to list USB devices connected to your system.

I have connected a 2GB pen-drive, 1TB external HDD, Android smartphone via MTP and USB mouse in the examples unless stated otherwise.

Let me start with the simplest of the options for desktop users.

Check connected USB devices graphically

Your distribution file manager can be used to view USB storage devices connected to your computer. As you can see in the screenshot of Nautilus (GNOME File Manager) below.

The connected devices are shown in the sidebar (Only USB Storage devices are shown here).

Nautilus showing connected USB devices

You can also use GUI applications like GNOME Disks or Gparted to view, format, and partition the USB Storage devices connected to your computer. GNOME Disks is preinstalled in most distributions using GNOME Desktop Environment by default.

This app also works as a very good partition manager too.

Читайте также:  M2crypto python install kali linux

Use GNOME Disks to list mounted USB devices

Enough of the Graphical tools. Let us discuss the commands you can use for listing the USB devices.

Using the mount command to list the mounted USB devices

The mount command is used for mounting partitions in Linux. You can also list USB storage devices using the same command.

Generally, USB storage is mounted in the media directory. Thus, filtering the output of mount command on media will give you the desired result.

Using df command

df command is a standard UNIX command used to know the amount of available disk space. You can also use this command to list USB storage devices connected using the command below.

Use df command to list mounted USB drives

Using lsblk command

The lsblk command is used to list block devices in the terminal. So, here also by filtering the output containing media keyword, you can get the desired result as shown in the screenshot below.

Using lsblk to list connected USb devicesUsing blkid to list connected USb devices

If you are more curious, you can use the blkid command to know the UUID, Label, Block size etc.

This command gives more output as your internal drives are also listed. So, you have to take references from the above command to identify the device you wish to know about.

Using blkid to list connected USb devices

Using fdisk

fdisk, the good old command line partition manager, can also list the USB storage devices connected to your computer. The output of this command is also very long. So, usually, the connected devices get listed at the bottom as shown below.

Use fidsk to list usb devices

Inspecting /proc/mounts

By inspecting the /proc/mounts file, you can list the USB Storage devices. As you can notice, it shows you the mount options being used by filesystem along with the mount point.

cat /proc/mounts | grep media

Display all the USB devices with lsusb command

And we revisit the famed lsusb command.

Linux kernel developer Greg Kroah-Hartman developed this handy usbutils utility. This provides us with two commands i.e. lsusb and usb-devices to list USB devices in Linux.

The lsusb command lists all the information about the USB bus in the system.

As you can see this command also shows the Mouse and Smartphone I have connected, unlike other commands (which are capable of listing only USB storage devices).

The second command usb-devices gives more details as compared but fails to list all devices, as shown below.

Greg has also developed a small GTK application called Usbview. This application shows you the list of all the USB devices connected to your computer.

The application is available in the official repositories of most Linux distributions. You can install usbview package using your distribution’s package manager easily.

Once installed, you can launch it from the application menu. You can select any of the listed devices to get details, as shown in the screenshot below.

Conclusion

Most of the methods listed are limited to USB storage devices. There are only two methods which can list other peripherals also; usbview and usbutils. I guess we have one more reason to be grateful to the Linux Kernel developer Greg for developing these handy tools.

I am aware that there are many more ways to list USB devices connected to your system. Your suggestions are welcome.

Источник

Оцените статью
Adblock
detector