Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I attempt to mount a folder that already has files in it, does linux give me an error message or go ahead and show both the mounted filesystem and the files that were already in the folder?

share|improve this question
Could always try it out with some test files, no? – Chris Oct 18 '10 at 14:35
I would of if I could. It just worked out that I didn't have anything to test with. I tried unmounting and mounting the drive in question but the results were inconclusive because they both had the same files. – shady Oct 18 '10 at 14:39
up vote 23 down vote accepted

It will just be mounted, and the files disappear, coming back when the folder is umounted.

share|improve this answer
What do you mean by disappear? They continue to exist on the server and are just not shown or are the deleted? – shady Oct 18 '10 at 14:08
I'll go have a quick check, but I think they are deleted. – Azz Oct 18 '10 at 14:10
+1 The files are simply invisible while the directory is mounted "over" them. They never really go away, the are just inaccessible... – sleske Oct 18 '10 at 14:50
It works like a stack, if you mount something else, it hides the previous content. When you unmount, the previous stuff becomes visible again. – vtest Oct 18 '10 at 15:09
I'm confused by how someone who said "coming back when the folder is unmounted" was able to say 3 minutes later "I think they are deleted". Thankfully for everyone else, the former is the reality here. – underscore_d Oct 6 '15 at 0:24

When you mount a filesystem on a directory /mount-point, you can no longer access files under /mount-point directly. They still exist, but /mount-point now refers to the root of the mounted filesystem, not to the directory that served as a mount point, so the contents of this directory cannot be accessed, at least in this way. For example:

# touch /mount-point/somefile
# ls /mount-point/somefile
# mount /dev/something /mount-point
# ls /mount-point/somefile
ls: cannot access /mount-point/somefile: No such file or directory

There are ways to get a merged view of the mounted filesystem and the data that was already present, but you need an extra layer called a union filesystem.

Under Linux, there is a way to see the hidden files. You can use mount --bind to get another view of the filesystem where the mount point is. For example

mount --bind / /other-root-view

You'll see all the files in the root filesystem under /other-root-view.

# cat /other-root-view/etc/hostname 

In particular, /mount-point will now be accessible as /other-root-view/mount-point, and since /other-root-view/mount-point is not a mount point, you can see its contents there:

# ls /mount-point/somefile
ls: cannot access /mount-point/somefile: No such file or directory
# ls /other-root-view/mount-point/somefile
share|improve this answer
Gilles, this answer just saved my butt when I needed to get some asterisk recordings that got saved underneath an NSF mount point! I always thought --bind had the same perspective as the user. Thank you! – andyortlieb Jul 19 '11 at 14:55
Best and most thorough explanation :) – matiu Jan 30 '14 at 5:25
What about directories? If I mounted at /mount-point/1/ then mounted another filesystem on /mount-point/, can I still access /mount-point/1/? – CMCDragonkai Nov 18 '15 at 12:57
@CMCDragonkai Yes, indirectly by using a bind mount as described in my answer. – Gilles Nov 18 '15 at 17:46
Giles, this is a brilliant technique and has helped me analyze what’s on my own system. It has also helped with another question, which is how to check usage of all of the root directories without traversing mount points. Solution: mkdir /r; mount --bind / /r; du -sh /r/*. Thanks – Manngo May 31 at 23:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .