
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
行の最初のフィールドを抽出します。この場合、列区切り文字は空白です。