Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #7872 > unrolled thread

may i have a soft link poiting to two directories at the same time?

Started bywww <xsli2@yahoo.com>
First post2013-04-17 11:23 -0700
Last post2013-04-24 06:42 -0400
Articles 8 — 7 participants

Back to article view | Back to comp.os.linux.misc


Contents

  may i have a soft link poiting to two directories at the same time? www <xsli2@yahoo.com> - 2013-04-17 11:23 -0700
    Re: may i have a soft link poiting to two directories at the same time? Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> - 2013-04-17 11:45 -0700
      Re: may i have a soft link poiting to two directories at the same time? Rui Maciel <rui.maciel@gmail.com> - 2013-04-17 22:34 +0100
        Re: may i have a soft link poiting to two directories at the same time? Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> - 2013-04-17 15:03 -0700
          Re: may i have a soft link poiting to two directories at the same time? David Brown <david.brown@removethis.hesbynett.no> - 2013-04-20 19:44 +0200
    Re: may i have a soft link poiting to two directories at the same time? Aragorn <stryder@telenet.be.invalid> - 2013-04-17 20:51 +0200
    Re: may i have a soft link poiting to two directories at the same time? J G Miller <miller@yoyo.ORG> - 2013-04-17 20:27 +0000
    Re: may i have a soft link poiting to two directories at the same time? Bill Marcum <bill@nowhere.invalid> - 2013-04-24 06:42 -0400

#7872 — may i have a soft link poiting to two directories at the same time?

Fromwww <xsli2@yahoo.com>
Date2013-04-17 11:23 -0700
Subjectmay i have a soft link poiting to two directories at the same time?
Message-ID<5d6a6b03-844d-4fca-9e92-afdea3231b4b@googlegroups.com>
Hi:

I have two real directories. I need to create 3rd directory and copy all the files from the two directories to the 3rd directory. Then I will create a soft link pointing to the 3rd directory. My program needs this soft link. The program will find its needed files in THE directory(the soft link directory).

I am just wondering if I can skip creating 3rd directory and skip copying all the files from the two dirs into the 3rd directory(a lot of file copying, time consuming). Is that possible that I create a soft link pointing to the two directories at the same time? So the program will go into THE directory(superficially it is one directory, but in fact it is two directories).

Thank you.

[toc] | [next] | [standalone]


#7877

FromKeith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Date2013-04-17 11:45 -0700
Message-ID<e6734axjqb.ln2@goaway.wombat.san-francisco.ca.us>
In reply to#7872
On 2013-04-17, www <xsli2@yahoo.com> wrote:
>
> I have two real directories. I need to create 3rd directory and copy all the files from the two directories to the 3rd directory. Then I will create a soft link pointing to the 3rd directory. My program needs this soft link. The program will find its needed files in THE directory(the soft link directory).
>
> I am just wondering if I can skip creating 3rd directory and skip copying all the files from the two dirs into the 3rd directory(a lot of file copying, time consuming). Is that possible that I create a soft link pointing to the two directories at the same time? So the program will go into THE directory(superficially it is one directory, but in fact it is two directories).

Your initial proposal, pointing one symlink to two different places, is
unfortunately not possible.  However, you can still use symlinks to
avoid the copying step.  See if this works for your purposes:

mkdir targetDir
cd targetDir
ln -s /path/to/dir1/* .
ln -s /path/to/dir2/* .

This creates symlinks in targetDir (which you'd pass to your program) to
the files in both dir1 and dir2.  So your program thinks all the files
it needs are in targetDir, which should be sufficient for your purposes.

--keith


-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

[toc] | [prev] | [next] | [standalone]


#7888

FromRui Maciel <rui.maciel@gmail.com>
Date2013-04-17 22:34 +0100
Message-ID<kkn4bn$cjo$1@dont-email.me>
In reply to#7877
Keith Keller wrote:

> Your initial proposal, pointing one symlink to two different places, is
> unfortunately not possible.  However, you can still use symlinks to
> avoid the copying step.  See if this works for your purposes:
> 
> mkdir targetDir
> cd targetDir
> ln -s /path/to/dir1/* .
> ln -s /path/to/dir2/* .

I would add that if all files are stored in the same file system then 
instead of creating symlinks for the files, hard links should be used 
instead.  In fact, this is exactly what they were created to accomplish.


Rui Maciel

[toc] | [prev] | [next] | [standalone]


#7889

FromKeith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Date2013-04-17 15:03 -0700
Message-ID<hqi34axcud.ln2@goaway.wombat.san-francisco.ca.us>
In reply to#7888
On 2013-04-17, Rui Maciel <rui.maciel@gmail.com> wrote:
> Keith Keller wrote:
>
>> Your initial proposal, pointing one symlink to two different places, is
>> unfortunately not possible.  However, you can still use symlinks to
>> avoid the copying step.  See if this works for your purposes:
>> 
>> mkdir targetDir
>> cd targetDir
>> ln -s /path/to/dir1/* .
>> ln -s /path/to/dir2/* .
>
> I would add that if all files are stored in the same file system then 
> instead of creating symlinks for the files, hard links should be used 
> instead.  In fact, this is exactly what they were created to accomplish.

It depends on what the OP wants from the links after he's done with
them.  If targetDir is simply an organizational tool, and he doesn't want
those files to consume disk space if he ever deletes the contents of
dir1 and dir2, then symlinks are better.  If he wants the files in
targetDir to be able to survive deletions of dir1 and dir2, then hard
links are better.

In general, I use symlinks (and tell others to use symlinks) unless I
know I have a specific purpose for which I need hard links.  One side
effect is that I don't have to worry about explaining to people why
making a hard link for a directory doesn't work, or why making a hard
link across filesystems doesn't work--if they always use symlinks, these
questions never arise.

--keith


-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

[toc] | [prev] | [next] | [standalone]


#7940

FromDavid Brown <david.brown@removethis.hesbynett.no>
Date2013-04-20 19:44 +0200
Message-ID<Y--dnWxlp8NxTu_MnZ2dnUVZ8k6dnZ2d@lyse.net>
In reply to#7889
On 18/04/13 00:03, Keith Keller wrote:
> On 2013-04-17, Rui Maciel <rui.maciel@gmail.com> wrote:
>> Keith Keller wrote:
>>
>>> Your initial proposal, pointing one symlink to two different places, is
>>> unfortunately not possible.  However, you can still use symlinks to
>>> avoid the copying step.  See if this works for your purposes:
>>>
>>> mkdir targetDir
>>> cd targetDir
>>> ln -s /path/to/dir1/* .
>>> ln -s /path/to/dir2/* .
>>
>> I would add that if all files are stored in the same file system then
>> instead of creating symlinks for the files, hard links should be used
>> instead.  In fact, this is exactly what they were created to accomplish.
>
> It depends on what the OP wants from the links after he's done with
> them.  If targetDir is simply an organizational tool, and he doesn't want
> those files to consume disk space if he ever deletes the contents of
> dir1 and dir2, then symlinks are better.  If he wants the files in
> targetDir to be able to survive deletions of dir1 and dir2, then hard
> links are better.
>
> In general, I use symlinks (and tell others to use symlinks) unless I
> know I have a specific purpose for which I need hard links.  One side
> effect is that I don't have to worry about explaining to people why
> making a hard link for a directory doesn't work, or why making a hard
> link across filesystems doesn't work--if they always use symlinks, these
> questions never arise.
>

In a situation like this, hardlinks are more likely to be the better 
solution.  They are more efficient, both in terms of disk space (a 
symlink is a small file - a hardlink is just a name in a directory) and 
usage (a symlink means an extra layer of indirection, while a hardlink 
is the file itself).  And because a hardlink /is/ the file, it is safe 
from deletion of dir1 and dir2 - with a softlink, the deletions can be 
done and leave a dangling softlink which is worse than useless.

Of course, it's important that the OP knows that with either kind of 
link, any changes made through the link affect the original file.

[toc] | [prev] | [next] | [standalone]


#7878

FromAragorn <stryder@telenet.be.invalid>
Date2013-04-17 20:51 +0200
Message-ID<kkmqqd$s5c$1@dont-email.me>
In reply to#7872
On Wednesday 17 April 2013 20:23, www conveyed the following to 
comp.os.linux.misc...

> Hi:
> 
> I have two real directories. I need to create 3rd directory and copy
> all the files from the two directories to the 3rd directory. Then I
> will create a soft link pointing to the 3rd directory. My program
> needs this soft link. The program will find its needed files in THE
> directory(the soft link directory).
> 
> I am just wondering if I can skip creating 3rd directory and skip
> copying all the files from the two dirs into the 3rd directory(a lot
> of file copying, time consuming). Is that possible that I create a
> soft link pointing to the two directories at the same time? So the
> program will go into THE directory(superficially it is one directory,
> but in fact it is two directories).

A symbolic link can only point to one target at the same time, but 
perhaps you should look into unionfs.

     http://en.wikipedia.org/wiki/Unionfs

-- 
= Aragorn =
  GNU/Linux user #223157 - http://www.linuxcounter.net

[toc] | [prev] | [next] | [standalone]


#7883

FromJ G Miller <miller@yoyo.ORG>
Date2013-04-17 20:27 +0000
Message-ID<kkn0k8$b9g$3@dont-email.me>
In reply to#7872
On Wednesday, April 17th, 2013, at 11:23:52h -0700, WWW explained:

> I have two real directories. I need to create 3rd directory and
> copy all the files from the two directories to the 3rd directory.

How about using mount -o bind?

Because I compile and install quite a number of software packages
from source, I keep the tar.bz2 archives in a hierarchy (applications,
multimedia, network, utilities, etc) under /srv/archive/Source

But to make these available at other points in the directory tree,
I use the bind feature of mount, eg in fstab

/srv/archive/Source     /usr/local/src                  none    bind    0 0

/srv/archive/Source     /mnt/export/Source              none    bind    0 0
/srv/archive/Source     /mnt/export/usr/local/src       none    bind    0 0

where the purpose of /mnt/export is a directory tree for
NFS v4 exports and SAMBA/CIFS exports to other machines
on the LAN.

[toc] | [prev] | [next] | [standalone]


#7973

FromBill Marcum <bill@nowhere.invalid>
Date2013-04-24 06:42 -0400
Message-ID<kl8cus$c1c$1@speranza.aioe.org>
In reply to#7872
On 04/17/2013 02:23 PM, www wrote:
> Hi:
>
> I have two real directories. I need to create 3rd directory and copy
> all the files from the two directories to the 3rd directory. Then I
> will create a soft link pointing to the 3rd directory. My program
> needs this soft link. The program will find its needed files in THE
> directory(the soft link directory).
>
> I am just wondering if I can skip creating 3rd directory and skip
> copying all the files from the two dirs into the 3rd directory(a lot
> of file copying, time consuming). Is that possible that I create a
> soft link pointing to the two directories at the same time? So the
> program will go into THE directory(superficially it is one directory,
> but in fact it is two directories).
>
> Thank you.
>

You could install unionfs-fuse, which allows two or more directories to 
be mounted at one point.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.os.linux.misc


csiph-web