How do I find which disk/partition current directory is on?

pwd -P will give you the physical directory you are in, i.e. the pathname of the current working directory with the symbolic links resolved.

Using df . would give you the df output for whatever partition the current directory is residing on.

Example (on an OpenBSD machine):

$ pwd
/usr/ports
$ pwd -P
/extra/ports
$ df .
Filesystem  512-blocks      Used     Avail Capacity  Mounted on
/dev/sd3a    103196440  55987080  42049540    57%    /extra

To parse out the mountpoint from this output, you may use something like

$ df -P . | sed -n '$s/[^%]*%[[:blank:]]*//p'
/extra

To parse out the filesystem device used, use

$ df -P . | sed -n '$s/[[:blank:]].*//p'
/dev/sd3a

I believe some Linux systems also supports

findmnt --target .

(where --target . can be replaced by -T .) or, for more terse output,

findmnt --output target --noheadings --target .

(where --noheadings may be replaced by -n, and --output target may be replaced by -o target) to get the mountpoint holding the filesystem that the current directory is located on.

Use --output source to get the mounted device node.

Tags:

Shell