我的目标是在linux中使用C以编程方式确定已挂载的USB闪存驱动器的名称。
有人有什么建议吗?
发布于 2016-12-27 06:06:54
假设U盘注册为/dev/sdb (您可以使用sudo fdisk -l在/dev中确定哪个是U盘,或者在tail和grep中使用dmesg )
如果您想获得U盘的标签,您可以使用sudo mlabel -i /dev/sdb1 -s ::,然后使用grep、awk或sed提取标签
https://help.ubuntu.com/community/RenameUSBDrive
如果想要获取UUID,可以使用sudo blkid /dev/sdb1
-> <-
https://serverfault.com/questions/3132/how-do-i-find-the-uuid-of-a-filesystem
有关在C中执行blkid等linux命令的信息,请参阅下面的Execute a Linux command in the c program和how to execute a command as root
https://stackoverflow.com/questions/41328399
复制相似问题