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.
About this post
- Posted
- Archived
- Score
- 9 · 100% up
- Kind
- Text
- ID
- mopen
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):
Should work.
You could also just mount the partition in ~/Videos instead of /media/other_partition/videos.
mount also has the --bind option,
would i have to do that every time i reboot? or does that bind it forever?
thanks
Thanks!
Could you tell me a little more about the mount --bind option?
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.
If I did:
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
this also drives me crazy .. i link to a directory and end up in a loop or have another directory
Yeah it's a bit perplexing.
Especially for me, because I won't use anything until I know exactly how everything works :P
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.
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!