I am handed a path of a directory or a file.Which utility/shell script will reliably give me the UUID of the file system on which is this directory/file located?By UUID of file system I mean the UUID=... entry as shown by e.g. blkidI'm using Redhat Linux.(someone suggested that I should ask this here at unix.stackexchange.com, so I moved it from the original stackexchange.com)
How to get UUID of filesystem given a path?
linux;shell;block device;uuid
One option is stat + findmnt combo:findmnt -n -o UUID $(stat -c '%m' $path)Here -n disables header, and -o UUID prints only UUID value. Option -c '%m' of stat is present to output only mountpoint of given path.