Skip to content

symbolic links and directories

I have ubuntu 11.10. I'd like to create a symbolic link from my ~/Video directory to another partition's directory (/media/other_partition/videos). So if I do:

cd ~/Videos;ls

the terminal should spit out the contents of /media/other_partition/videos.

I've done some researching, and I'm pretty sure that the command I'm looking for is:

ln input/path output/path

or

link input/path output/path

I just don't know how to make it so it links the two directories.

Is this even possible?

The reason for doing this is that I want to keep my valuables in another partition so my dual-boot windows and linux can share them, for productivity and space efficiency.

Thanks a bunch in advance r/linuxquestion. You've been a goldmine of information and without you I probably would've gotten frustrated with my ignorance and reverted to windows.

9 points18 comments
Open on Reddit
About this post
Posted
Archived
Score
9 · 100% up
Kind
Text
ID
mopen

Author

11
posts
24
comments
1
media
View profile

19 comments

You'll want a soft/symbolic link instead of a hard link (almost always, but especially for directories and stuff on different volumes/partitions):

ln -s /media/other_partition/videos ~/Videos

Should work.

You could also just mount the partition in ~/Videos instead of /media/other_partition/videos.

5 points

mount also has the --bind option,

mount --bind olddir newdir
6 points

Thanks!

Could you tell me a little more about the mount --bind option?

1 points

I'm glad you mentioned bind mounts.

My philosophy is to never symlink. If it's a file, hardlink. If it's a directory or if it's on another partition, bind mount. symlinks are ugly and they're not always handled very elegantly. Especially since it doesn't traverse filesystem permission and thus you have less control over filesystem permissions.

You also have the ability to create read-only bind mounts so it works as an easy way to give limited read only access to a directory or what have you.

1 points

If I did:

ln -s /media/other_partition/videos ~/Videos

would the sym link stay forever? if i move one of the directories will the link follow?

Also:

If I mount the partition in ~/Videos, is the command

mount --bind olddir newdir?
1 points

this also drives me crazy .. i link to a directory and end up in a loop or have another directory

2 points

Yeah it's a bit perplexing.

Especially for me, because I won't use anything until I know exactly how everything works :P

1 points

A symlink (ln -s) just creates a reference object (i.e. similar to a file) which points to another file or directory. A symlink lives in the file system, so it's permanent. But it has no way of tracking it's target, so if you move the target, the symlink will just point to (i.e. reference) a non-existent file/dir; it's generally best to avoid doing that. Also, it's best to avoid creating loops with symlinks. Use ls -l to see the symlink values.

A bind mount must be re-created, as all mounts are, each time you boot, because it's not a separate file type. I think mounts are overkill for what you want. Mounting generally requires root (sudo), but any user can create symlinks.

I use symlinks similarly to you, in order to store my data physically in one location, but access it logically from another location. For example, my ~/Videos is a symlink into my data partition.

3 points

Thanks so much everybody that helped out. I got it working! Without you guys I know I wouldn't have seen this one through. Thanks!

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.