I use lsblk -o MOUNTPOINT,PKNAME | grep '^/ ' | awk '{print $2}'
to find root disk.
How can I check if path (/home/sun
for example) is on disk found using previous command?
Thanks for helping out!
CodePudding user response:
The following will resolve symbolic link such as /dev/root, if present:
realpath $(df --output=source $DIR |tail -n 1)
CodePudding user response:
You can get the disk of any file/path with df. for example:
df /home/sun
will result point to the filesystem used for this path. We can use this in combination with your oneliner:
df /home/sun 2> /dev/null | grep $(lsblk -o MOUNTPOINT,PKNAME | grep '^/ ' | awk '{print $2}')
We then use /dev/null to remove all non existent directory errors.
CodePudding user response:
Try this :
#!/bin/bash
path="$(realpath "$1")"
awk '{ if (NR==FNR) {
map[$1] = $2
} else if ($NF in map) {
print map[$NF]
}
}' <(lsblk -o MOUNTPOINT,PKNAME) <(df "$path")