I'm attempting to symlink files to a mirrored directory tree. Both directories (source and desired destination of symlinks) are on separate mountpoints inside a FreeBSD jail.

Source directory: /mnt/tank/media/storage/vids/foo/. foo has several levels of nested hierarchy below from which files need to be symlinked from.

Desired destination directory /mnt/tank/media/videos/foo/, under which the proper directory structure has been created using the following command, executed from the source directory foo:

find . -type d | cpio -dmp -R user:group /mnt/tank/media/video/foo

This command did what I need, which was create the mirrored directory structure, sans files. I now need to symlink all the files from source foo into destination foo, in the proper directory structure.

I've tried various find commands with xargs and -exec, but the issue I have is that I need the destination argument in the ln -s source destination command to be different than what the find command will return.

I'm sure there is some relative path usage of find that I can use or something, I just am not knowledgeable enough to know the right way to do this.

Thanks!

  • 1
    I am a little confused on what you are trying to do here, can you maybe elaborate more on what you are trying to achieve? For instance, why are you creating all the folders in another location and then symlinking the files into those folders? Why not just symlink the entire directory so you don't have to do this? Creating many symlinks is normally a bad practice as it then creates a big cleanup mess later on. – devnull Dec 29 '15 at 20:19
  • I want to rename some of the files and organize them differently in their symlinked versions, the originals need to stay where they are, and I'd like to avoid creating two copies of a large set of files. – Bryce Dec 29 '15 at 21:22
  • Ok, I still advise against this but, is the only thing changing the file name type or is the directory/location also different as well? How do you expect the output to be? – devnull Dec 29 '15 at 21:33
  • I will change the the file names and locations of the symlinked versions, but I'd like to start with the same directory structure as the source. I'll edit the files names and locations after the fact. Similar to what was asked here unix.stackexchange.com/questions/74721/…, but I was unable to make this work (FreeBSD cp doesn't have the -l option, and I wasn't smart enough to make the script option work for me (yet...)). – Bryce Dec 29 '15 at 21:37

Symlinks have the problem that they need to be resolved to access the files. This means that the files need to be available in the jail.

When I need files in a jail I mount the directory with nullfs.

  • Yup, nullfs is the way to go. For Linux, this would be a bind mount. – GROND Aug 30 '16 at 20:49

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.