LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Maintaining symbolic links (https://www.linuxquestions.org/questions/linux-general-1/maintaining-symbolic-links-927350/)

rpowell 02-03-2012 02:27 AM

Maintaining symbolic links
 
Hi,

I have the following:

/media/disk1/myPictures
/media/disk2/myPictures

What I want to do is to have a folder in my home dir with the contents of both folders sym-linked out to disk

i.e:

ln -s /media/disk1/myPictures/* /home/ryan/myPictures
ln -s /media/disk2/myPictures/* /home/ryan/myPictures


However is there a tool like rsync but for maintaing symbolic links. As in if the contents of the disks change, the symbolic links also change?

That or perhaps a better setup :)

Thanks,
Ryan

fukawi1 02-03-2012 02:38 AM

Manually create a fstab entry for the drives. Using the UUID rather than device name, so the right filesystem gets mounted to the right point (/home/ryan/myPictures).

Im not sure on mounting two filesystems to the same mount point though. I think that will break.

rpowell 02-03-2012 02:56 AM

Quote:

Originally Posted by fukawi1 (Post 4592603)
Manually create a fstab entry for the drives. Using the UUID rather than device name, so the right filesystem gets mounted to the right point (/home/ryan/myPictures).

Im not sure on mounting two filesystems to the same mount point though. I think that will break.

but the problem is that /home/ryan/myPictures will contain the contents of multiple folders (fstab wont fix this as my / disk isn't big enough to hold the contents of these disks)

Is there a program to maintain symlinks? Otherwise a crontab & repetitively removing all symlinks and re-establishing them is the only way I know how to

Dark_Helmet 02-03-2012 03:27 AM

What are these disks? Thumbdrives? Memory cards? In other words, drives that you will plug in to access? Or are they almost always plugged-in/mounted?

EDIT:
If they are removable, you might consider creating some udev rules. In a nutshell, a udev rule would allow you to launch an executable whenever a specific device is connected or removed. The idea would be that you run a script that creates symlinks when the device is connected, and then remove symlinks when the device is removed.

If they are always mounted... not sure if there's an easy solution. I know there has to be one or more filesystem-monitoring daemons out there. I say that because inotify exists. Unfortunately, I don't know the name of any of them. Though, such a daemon should be able to trigger a script/program whenever specific changes are detected.

EDIT2:
I found this page:
nixCraft: How To Track Changes in Your Linux Filesystem

It references a filesystem monitoring daemon. Two of the replies also refer to filesystem monitoring tools as well. Perhaps you could use one of them to help you write a script or something to add/modify/delete symbolic links in your "merged" pictures directory.

Shiba 02-03-2012 11:16 AM

I suggest that you create a symbolic link to the mount points, rather than the individual files:

ln -s /media/disk1/myPictures /home/ryan/myPictures/disk1
ln -s /media/disk2/myPictures /home/ryan/myPictures/disk2

However, the more modern distros will make the disks easily available from the GUI file browser. I suggest just using that instead of trying to maintain such symlinks.

rpowell 02-03-2012 11:45 AM

Thanks guys for the replies. I will look into the above three suggestions.

I did also stumble across mhddfs FYI
hxxp://romanrm.ru/en/mhddfs

Thanks,
Ryan

Dark_Helmet 02-03-2012 12:05 PM

Quote:

I suggest that you create a symbolic link to the mount points, rather than the individual files:

ln -s /media/disk1/myPictures /home/ryan/myPictures/disk1
ln -s /media/disk2/myPictures /home/ryan/myPictures/disk2
But that is not what the OP wants. The OP wants the contents of two separate directories to appear in a single, consolidated directory. If you notice, the original command places the symbolic links for both disk1 files and disk2 files into one directory. In effect, the commands "merge" the contents of the two disks.

Switching gears... back to the suggestions I made earlier. I think the only solution that will fit your needs would be a filesystem monitor--if you will be manipulating images and need the symbolic links updated as you work (e.g. creating new images, deleting images, etc.). The udev rule approach will work if the contents of the two disks are static. Otherwise, you'll need to disconnect-reconnect whenever you want the links updated.


All times are GMT -5. The time now is 12:30 AM.