LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1178|回复: 4

请问如何用Shell判断一个盘符是不是U盘?

[复制链接]
发表于 2010-5-13 19:48:32 | 显示全部楼层 |阅读模式
就是U盘还没挂载之前,用什么方法可以判断是不是U盘呢?
先谢谢各位!
发表于 2010-5-13 22:24:51 | 显示全部楼层
简单的方法我不知道,对于一下pci id还是可以看出来的

$ ll /dev/disk/by-id/
总用量 0
lrwxrwxrwx 1 root root  9  5月 13 19:15 ata-ST9500325AS_5VE14VT4 -> ../../sda
lrwxrwxrwx 1 root root 10  5月 13 19:15 ata-ST9500325AS_5VE14VT4-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10  5月 13 19:15 ata-ST9500325AS_5VE14VT4-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10  5月 13 19:15 ata-ST9500325AS_5VE14VT4-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10  5月 13 19:15 ata-ST9500325AS_5VE14VT4-part6 -> ../../sda6
lrwxrwxrwx 1 root root  9  5月 13 19:15 scsi-SATA_ST9500325AS_5VE14VT4 -> ../../sda
lrwxrwxrwx 1 root root 10  5月 13 19:15 scsi-SATA_ST9500325AS_5VE14VT4-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10  5月 13 19:15 scsi-SATA_ST9500325AS_5VE14VT4-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10  5月 13 19:15 scsi-SATA_ST9500325AS_5VE14VT4-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10  5月 13 19:15 scsi-SATA_ST9500325AS_5VE14VT4-part6 -> ../../sda6
lrwxrwxrwx 1 root root  9  5月 13 19:15 wwn-0x5000c50014248d32 -> ../../sda
lrwxrwxrwx 1 root root 10  5月 13 19:15 wwn-0x5000c50014248d32-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10  5月 13 19:15 wwn-0x5000c50014248d32-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10  5月 13 19:15 wwn-0x5000c50014248d32-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10  5月 13 19:15 wwn-0x5000c50014248d32-part6 -> ../../sda6

$ ll /dev/disk/by-path/
总用量 0
lrwxrwxrwx 1 root root  9  5月 13 19:15 pci-0000:00:1f.2-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10  5月 13 19:15 pci-0000:00:1f.2-scsi-0:0:0:0-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10  5月 13 19:15 pci-0000:00:1f.2-scsi-0:0:0:0-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10  5月 13 19:15 pci-0000:00:1f.2-scsi-0:0:0:0-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10  5月 13 19:15 pci-0000:00:1f.2-scsi-0:0:0:0-part6 -> ../../sda6
lrwxrwxrwx 1 root root  9  5月 13 19:15 pci-0000:00:1f.2-scsi-1:0:0:0 -> ../../sr0
回复 支持 反对

使用道具 举报

发表于 2010-5-13 23:02:04 | 显示全部楼层
1,根据容量大小,现在的硬盘通常都是几百个G了,而U盘才4-8G,所以,看它们的容量:
# fdisk -l

2,根据文件系统,通常U盘的文件系统都是FAT的(因为同时在windows和Linux下通用的U盘格式也只有FAT和NTFS,而4G的U盘大都是FAT的)
# fdisk -l

===============我的分区========

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000572f6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1           42683       60801   145540867+  83  Linux
/dev/sda2   *           1          24      192748+  83  Linux
/dev/sda3              25       13990   112181895    5  Extended
/dev/sda5              25        3671    29294496   83  Linux
/dev/sda6            3672        4157     3903763+  82  Linux swap / Solaris
/dev/sda7            4158       10236    48829536   83  Linux
/dev/sda8           10237       13990    30153973+  83  Linux

Partition table entries are not in disk order

Disk /dev/sdb: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xc001c001

   Device Boot      Start         End      Blocks   Id  System

Disk /dev/sdc: 4038 MB, 4038066176 bytes
125 heads, 62 sectors/track, 1017 cylinders
Units = cylinders of 7750 * 512 = 3968000 bytes
Disk identifier: 0x00045357

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        1017     3940844    c  W95 FAT32 (LBA)
回复 支持 反对

使用道具 举报

发表于 2010-5-14 05:22:02 | 显示全部楼层
Post by tocai;2089875
简单的方法我不知道,对于一下pci id还是可以看出来的

$ ll /dev/disk/by-id/

方法不错;我一直用磁盘容量
有时间就把脚本改了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-5-17 17:46:17 | 显示全部楼层
谢谢大家,还是 tocai 的比较好,我的U盘会显示USB-Kingston
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表