I am trying to use a USB PENDRIVE to increase my current path for building a large library.

So, I have this idea of creating a symlink in my program to a folder in the Pendrive. So that it uses the space in the Pen Drive instead of my main storage.

/home/me/opencv/ <-- this is the product I want to build /home/me/opencv/build/ <-- this is the build folder.

At this point there is not enough memory to build it there, so I created this symlink in /home/me/opencv/

mkdir /media/me/pendrive/opencv/build/

ln -s /media/me/pendrive/opencv/build/  /home/me/opencv/ -s

this created a link "build" under /home/me/opencv/ folder that points to my pen drive.

The problem here is that directory traversal points to the pen drive too.

cd /home/me/opencv

this renders a number of folders and files inside opencv folder

But if I do...

cd /home/me/opencv/build
ls ..

this renders an empty opencv folder with an only folder named build.


You can try a bind mount, assuming you can use sudo or have root rights. For example,

mkdir /home/me/opencv/build
mkdir -p /media/me/pendrive/opencv/build
sudo mount -o bind /home/me/opencv/build /media/me/pendrive/opencv/build

Then, when in /home/me/opencv/build, you should see in .. the contents of /home/me/opencv/. Use sudo umount /home/me/opencv/build to undo the mount.


There's a difference between logical and physical directory paths that you've run into.

cd /home/me/opencv/build

This will place you in the logical directory /home/me/opencv/build, but physically, you're actually in /media/me/pendrive/opencv/build, thanks to the symbolic link.

ls .. will show you the contents of the physical parent directory /media/me/pendrive/opencv.

A physical directory path is a logical directory path with all its symbolic links resolved. They are the same if the logical directory path does not contain only symbolic links.

See also the difference between pwd -L and pwd -P while in that build directory (and read the pwd manual).

cd also has -L and -P flags (and -L is the default).

  • Thanks for your quick response. It sounds to me that there is no way to create a symlink that works the way I want (where ls .. will list the contents of /home/me/opencv/ folder) – diy_nunez Sep 19 '17 at 16:22

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.