command line - How to check whether a partition is mounted by UUID? - Ask Ubuntu
if have uuid of drive partition, how go finding out whether mounted or not, using command line?
lsblk
might help. can print uuid , mount point, so, given uuid, see if mount point not empty:
uuid=foo lsblk -o uuid,mountpoint | awk -v u="$uuid" '$1 == u {print $2}'
so:
uuid=foo mountpoint=$(lsblk -o uuid,mountpoint | awk -v u="$uuid" '$1 == u {print $2}') if [[ -n $mountpoint ]] echo mounted else echo not mounted fi
since lbslk
can act on specific devices, can do:
mountpoint=$(lsblk -o mountpoint "/dev/disk/by-uuid/$uuid" | awk 'nr==2')
with first method, there won't error if uuid isn't connected disk. second method, lsblk
error out if /dev/disk/by-uuid/$uuid
doesn't exist.
Comments
Post a Comment