Most users rely on external peripherals like USB drives, wireless keyboards, mice, disk drive, and more to use their computers.
Sure, if the disk is mounted, it can easily be retrieved with the file manager or by listing the disks of the system but what about the connected keyboard or mouse or other interfaces that are not mounted on the file system?
Well, that’s what I’m going to cover in this tutorial.
1. List mounted USB drives using df command
Contents
Whenever you plug the disk drive into your system, it will be automatically mounted in the /media
directory. So if you are looking for a way to list disk drives, you can use the df command as shown:
df -Th | grep media
And as you can see, it listed all the drives that are mounted at the /media
directory.
2. See mounted USB disk names using lsblk
The lsblk command will give you a similar result to the df command that I explained above. But without any options, it will list all the disk blocks.
So what you can do is use the grep command to list drives mounted to the /media
directory:
lsblk | grep media
3. List USB devices using the fdisk command
If you’ve been using Linux for a while, then, you must have come across the fdisk utility which is used to get detailed info on every disk partition on the system.
And to list details, all you have to do is execute the fdisk command with the -l
flag:
sudo fdisk -l
But that’s not the best part!
With the fdisk command, you can grep the disk name as shown here:
sudo fdisk -l | grep "Disk_name"
For example, here, I was looking for a USB drive manufactured by SanDisk
, then, I can simply grep it:
sudo fdisk -l | grep "SanDisk"
Pretty cool. Right?
4. List USB ports and other peripheral devices with lsusb
The earlier methods only gave information about the USB disk drives but what about those peripherals that you’re using via USB?
Well, in that case, you can use the lsusb command as shown:
lsusb
The entries with Linux Foundation are for the unused USB ports.
💡
As you can see, it listed all the ports including my USB keyboard, USB mouse, and USB disk drive. So it is not exclusive to actual USB drive ports.
5. Using the usb-devices command
📋
Remember, it is mainly used to get technical details like manufacture and may not print the hardware name and generally uses the device ID. So if you only want to know the names, then you can use the lsusb command.
The usb-devices is a script that is used to print the details of the USB controllers of your system so the output is more technical.
And to use the usb-devices
command, all you have to do is simply execute the command as shown:
usb-devices
Here’s how you list mounted drives
There are multiple ways to list mounted drives in Linux and to make things easy to understand, we made a dedicated tutorial on how to list mounted drives in Linux:
I hope you will find this guide helpful.