Press "Enter" to skip to content

Linux get DevName of a directory

Linux系统下, 获得某一个子目录(例如/data/home/release )对应的DevName(如sdb等). 现在的情况是

有些机器是这样的

Filesystem      Size  Used Avail Use% Mounted on
......
/dev/sda5       1.6T  343G  1.2T  23% /data

而有些机器是这样的

Filesystem      Size  Used Avail Use% Mounted on
......
/dev/sda5       1.6T  343G  1.2T  23% /data
/dev/sdb        488M   56M  408M  12% /data/home/release

解决办法

part=`df -P /data/home/release | awk 'END{print $1}'`    #得到一个诸如/dev/sda3的字符串
devname=${part:5:3}             #切割上面的字符串,从第5位开始,取3位
echo $devname

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *