What's the command for terminal to find the usb information?
There's several commands for that actually. One can always filter out the output, using text processing tools, generally their output is small enough to read in one screenfull.
blkid
This neat command by itself , as the name suggests, shows info about block devices. With -L
you can search for specific device with a label (name).
$ blkid -L DTSE9
/dev/sdb1
df
This neat command is part of coreutils
package, shows the block size and usage of the "device files". It shows only informations about those devices that are mounted ( in other words, linked to a folder somewhere ). For instance,
/dev/sdb5 115247656 84753976 24616332 78% /media/WINDOWS
Tells me that my windows partition on the second hard drive is linked to /media/WINDOWS
partition.
udisksctl
$ udisksctl status
MODEL REVISION SERIAL DEVICE
--------------------------------------------------------------------------
Radeon R7 1.01 A22MD061520000172 sda
TSSTcorp CDDVDW SU-208GB TF01 S16T6YEFB00NKH sr0
Very convenient command that lists models and device file to which a disk is linked. In the example above my Radeon R7 SSD is linked to /dev/sda
device.
If we go into more details, udisksctl info -b /dev/sda
will list lots of additional info , including size and symlinks.
If we wanna go wild, udisksctl dump
will produce verbose output on all the disks.
parted
and fdisk
Both commands are disks utilities, used for partitioning, resizing, and many more other fun things. Both however, require use of sudo
. Both output great verbose information
find
This is a more "hands on" approach. All the devices have a special device file under Linux ( remember Unix philosophy that says everything is a file ? It applies here the best ). Knowing that there are files /dev/disk/by-label
we could search that directory, or we could just search /dev/disk
in general. Definitely a tool that more advanced users can appreciate
$ find -L /dev/disk/by-label/ -name "DTSE9" -exec readlink -e {} \;
/dev/sdb1
lsblk
Already covered by Jacob.
mount
$ mount | grep "DTSE9"
/dev/sdb1 on /media/xieerqi/DTSE9 type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks2)
Lists all mounted filesystems. Can be filtered with grep
to look for specific filesystem. It's analogous to doing grep 'DISKNAME OR UUID' /proc/mounts
lshw
This command provides info about all the hardware on the system. In particular, you can view info about disks using lshw -c disk
for whole device, or lshw -c volume
for partitions,
and you should see output with lines something like this:
logical name: /dev/sdc1
logical name: /media/xieerqi/BA02-AF80
You can simply use:
lsblk | grep <flashdrive>
This will output in my situation, running
$ lsblk | grep Passport
└─sdb1 8:17 0 1,8T 0 part /media/jacob/My Passport1
└─sdc1 8:33 0 698,6G 0 part /media/jacob/My Passport
where you can see both the device and the mount point. As you can see, I have two usb drives named My Passport
Only get the device
$ lsblk | grep Passport | awk '{ print $1 }'
└─sdb1
└─sdc1
The same, but with a more precise output:
$ lsblk | grep Passport | awk -F'[─ ]' '{ print $2 }'
sdb1
sdc1
Or, as suggested by @kos (thanks!) even simpler, using lsblk
with the -l
option (which will leave out the └─
in the output, before the devices):
$ lsblk -l | grep Passport | awk '{ print $1 }'
sdb1
sdc1
Or (also as suggested by @kos), you could do without the grep
command, only using lsblk
and awk
:
$ lsblk -l | awk '/Passport/{ print $1 }'
sdb1
sdc1
Explanation
-
lsblk
will list all your mounted devices -
grep <flashdrive>
will only list the line(s), matching with your device name, looking like:└─sdc1 8:33 0 698,6G 0 part /media/jacob/My Passport
-
awk -F'[─ ]' '{ print $2 }'
will split the line by two delimiters:─
(which is the second character from └─)
and a space.
Subsequently, we can easily get the section we need.