
我正在將 NTFS 磁碟附加到 RHEL。
要安裝它,我需要知道分割區名稱,稍後我將在mount
命令中使用它。
我需要取得一個帶有Device
名稱的字串,知道System
它屬於什麼。
fdisk -l
該命令返回:
Disk /dev/sdb: 15.0 GB, 15032385536 bytes, 29360128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0xdf77eb64
Device Boot Start End Blocks Id System
/dev/sdb1 128 29358079 14678976 83 Linux
Disk /dev/sda: 31.5 GB, 31457280000 bytes, 61440000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x000c46d3
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 61439999 30206976 83 Linux
Disk /dev/sdc: 1862 MB, 1862270976 bytes, 3637248 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0xf9fa7844
Device Boot Start End Blocks Id System
/dev/sdc1 128 3635199 1817536 7 HPFS/NTFS/exFAT
我很想得到一個字串/dev/sdc1
,因為它的系統是HPFS/NTFS/exFAT
我怎麼才能得到一個Device
字串,知道它應該被格式化為HPFS/NTFS/exFAT
?
答案1
好的,您想從命令的輸出中提取字串。以這種方式使用 UNIX 喜愛的小而簡單的命令鏈:
fdisk -l | grep NTFS | cut -f 1 -d " "
fdisk
輸出通常的資訊 - 如你所知。|
是管道符號,表示將輸出提供給下一個命令,而不是螢幕。grep
然後僅提取包含 NTFS 的行並cut
提取該行的第一個字段,在本例中列分隔符號為空格。