I have mounted a directory to another directory using mount --bind so that an sftp user of my server can access this directory.

mount --bind /path/share /path/home/user/stuff

I have put this in /etc/fstab and it is working great.

If I cd into the mounted directory and do pwd, it seems as if the directory is actually, physically there:


Is there a command that shows where the 'original' directory is located (just as symlinks: when you do ls -fsl you see the original path)?

  • I'm fairly sure no. A mount point isn't a symlink. – Shadur Sep 5 '12 at 9:55

I think you're looking for mount -l.


Yes, the directory is there, because you mounted it there. mount --bind tells the kernel to use an existing mount and attach it to another mount point. As far as the kernel is concerned,

mount /dev/something /path/share
mount --bind /path/share /path/home/user/stuff


mount /dev/something /path/home/user/stuff
mount --bind /path/share /path/home/user/stuff

are the same thing. There are two ways to distinguish them:

  • If /path/share is not a mount point (i.e. it's part of a larger filesystem mounted at /path or /), you can tell the bind mount because it's not at the root of the filesystem.
  • The mount program records its actions in /etc/mtab.

The df command reads /etc/mtab, so if a directory is on a filesystem that's been mounted with the bind option, you can see what the original path was with

df -P /path/to/file | awk 'NR==2 {print $1}'

(first field of the second line). Note that this information isn't always reliable, for example it's possible that the original filesystem has been unmounted and nothing, or something else, is now mounted at this location, as in

mount /dev/something /path/share
mount --bind /path/share /path/home/user/stuff
unmount /dev/something
mount /dev/somethingelse /path/share

I checked source code of df, and made a similar script that will find the original path,

e.g you bind /tmp/a to /tmp/b,

And you launch my script with perl script.pl /tmp/b/what/ever/deep/inside, you will find /tmp/a


use strict;
use warnings;
use File::Basename;

sub findmnt
    my $path = shift or die;

    open my $fh, 'mount|' or die;
    while (<$fh>)
        return $1 if ($_ =~ qq{(.*) on $path type })

if ($#ARGV lt 0)
    die 'Usage: ', $0, ' /path/to/dir', "\n";

my $mntpath = $ARGV[0];
while ($mntpath ne '/')
    my $origpath = findmnt $mntpath;
    if ($origpath ne '')
        print 'Original path: ', $origpath, "\n";

    $mntpath = dirname ($mntpath);

On Linux, you can now use findmnt (from util-linux) for that:

~$ sudo mount --bind /usr/local mnt
~$ cd mnt/bin
~/mnt/bin$ pwd
~/mnt/bin$ findmnt -T .
TARGET             SOURCE                             FSTYPE OPTIONS
/home/stephane/mnt /dev/mapper/VG-LV[/usr/local]      ext4   rw,noatime,discard,errors=remount-ro,data=ordered

Based on daisy's response, how about...

use strict;
use warnings;
use File::Basename;

my $mntpath = $ARGV[0] or die "Missing required parameter <pathname>\n";
$mntpath = dirname ($mntpath) while (! grep / on $mntpath type /, `mount`);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.