• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

can you symlink to a directory?

Brazen

Diamond Member
basically, when I browse to /home/user/web I want it to show me the files and directory under /var/www/html. So if there is a file /var/www/html/folder1/file1.htm then I can see it at /home/user/web/folder1/file1.htm.

I will be sharing the /home/user/web folder through Samba, and want to access these files that would not be under that path, but maybe there is a better way to do this with Samba, but I would prefer to not create additional shares.

Anyway, the man page for ln leads me to believe you can only symlink files but I want to symlink the directory and any existing or new files and folders under it.
 
You can certainly symlink directories, but I don't think Samba will follow symlinks outside of the path the share is defined on.
 
How about hardlinks? Can you even hardlink between different partitions (/home and /var are on seperate partitions) if the filesystem on both is ext3?

And what would be the syntax for doing the symlink? or the hardlink for that matter? I can do files but directories don't seem to work.
 
I think you can only hardlink files (not directories) on the same filesystem. Symlink syntax for directories is no different than anything else...

ln -s /path/to/target /path/to/symlink
 
Files are referenced by inodes on your file system.. A hardlink is like having 2 names for the same file. Instead of just having a pointer, the file has 2 names. A file always has one hardlink.

With a symbolic link you have the original hardlink and another symbolic link that just 'points' to the other one and says 'use that'.

Hardlinks only work on one file system. It can't spread between multiple file systems. A symbolic link doesn't have that problem and thus is used much more often.

Hardlinks also don't work for directories, at least not on ext3.

The syntax goes like this:
ln -s directoryname symlinkname

The paths can be relative or absolute. Depends on what you want to use them for weither or not they are absolute.

For excercise to see the difference between hardlinks and softlinks go:
mkdir ~/test
cd test
touch poo
ln -s poo poo2
ln poo poo3
ls -l

You should see a difference.

echo "cool" >> poo
cat poo
cat poo2
cat poo3
echo "cool2" >> poo2
echo "cool3" >> poo3
cat poo
cat poo2
cat poo3
ls -l
rm poo
ls -l
cat poo2
cat poo3


You should see that with the original hardlink to the file removed the 'poo3' hardlink should still work while the symbolic link will be broken.

Also there is a 'lndir' command for creating symbolic links of entire directory trees. It's usefull for when your compiling programs but don't want to have changes be made on the original source tree.
mkdir -p ~/test/test2/test3
mkdir ~/testlink
cd ~/testlink
lndir ../test

I don't know how samba will react to all that though. Hardlinks should work, but hardlinsk don't work accross multiple file systems. I don't know how smart samba is with symbolic links.
 
ugh, ok so I did "ln -s /var/www/html/ /home/user/web" and it worked. I thought I had already tried that, but I think what I did was used just "web" as the target since I was already in the /home/user/ directory. That's the only difference I can think of that I did. Oh well, it works now anyway. And it DOES work through Samba too, just how I wanted. thanks.
 
Here's what you should do...

mount --bind /home/user/web /var/www/html

You can play around with how you want it to appear, since this command will mount the html folder's contents in the web folder. It can be transversed via samba and ftp etc. There are probably some serious security concerns with circumventing your filesystem layout security, but as long as you are careful with your security setting and permission you should be ok. I use this all of the time to join directory structures from various devices. Links for some reason just don't work for me...I can never get them to work right. the issues with soft links and transversal made them useless for anything but linking apps and progs on my root dir....and as for hardlink...well...I could never gt them to work at all.

hope this help. BTW, the command is not persistent, and I'm not sure if there is a way to put this in fstab...I would just put the mounts in rc.local or some other boot script to be run at boot time.

C
 
Originally posted by: Cr0nJ0b
Here's what you should do...

mount --bind /home/user/web /var/www/html

You can play around with how you want it to appear, since this command will mount the html folder's contents in the web folder. It can be transversed via samba and ftp etc. There are probably some serious security concerns with circumventing your filesystem layout security, but as long as you are careful with your security setting and permission you should be ok. I use this all of the time to join directory structures from various devices. Links for some reason just don't work for me...I can never get them to work right. the issues with soft links and transversal made them useless for anything but linking apps and progs on my root dir....and as for hardlink...well...I could never gt them to work at all.

hope this help. BTW, the command is not persistent, and I'm not sure if there is a way to put this in fstab...I would just put the mounts in rc.local or some other boot script to be run at boot time.

C

Well Cr0n, if you saw from my previous post, the symlink worked, and I even included the command I used. It let me traverse through the link over a Samba share and the files have the same permissions as they do in their original place in the filesystem, which is read-only for the Samba user, so it's not really circumventing anything.
 
Sorry, I didn't see that...But you will probably find at some point that there are limitations with softlinks. The main ones for me were related to consolidating directories across filesytems and physical drives and transversal with SCP and FTP type apps. I'm glad you worked it out though...that's good news...but the mount --bind is a pretty nifty featue in some circumstanced.
 
Oh yeah, sorry I didn't mean to give the wrong impression... I'll keep the mount -bind command in mind.
 
Back
Top