Re: Finding all the links in a Unix file/directory path




Quoth Jürgen Exner <jurgenex@xxxxxxxxxxx>:
John <freesoft12@xxxxxxxxx> wrote:
Looks like my question was not clear:

In my logfile, i see the following path: /tmp/test_hier/b/f/of3.cpp.
Since directory 'f' is a symbolic link to directory 'c', the actual
path is /tmp/test_hier/b/c/of3.cpp.

I want to copy the orig path /tmp/test_hier/b/f/of3.cpp to my target
directory: /tmp/copy/ . here is what I want to do:

1) Copy the actual file /tmp/test_hier/b/c/of3.cpp as /tmp/copy/tmp/
test_hier/b/c/of3.cpp
2) Create a link: /tmp/copy/tmp/test_hier/b/f -> /tmp/copy/tmp/
test_hier/b/c

So, if I understand correctly you want to copy the complete _structure_
of the the file tree, i.e. if a directory entry was a symlink in the
original then it should become a symlink in the copy, too.

No, AIUI he doesn't want to copy the whole tree, just one file and all
symlinks required to resolve that. So if he starts with

/a/b -> /c
/c/d -> /e
/e/f
/g -> /a/b/d/f

and copys /g to /tmp/copy he wants to end up with

/tmp/copy/
a/
b -> /tmp/copy/c
c/
d -> /tmp/copy/e
e/
f
g -> /tmp/copy/a/b/d/f

In particular, he seems to want to follow and copy links that point
anywhere on the filesystem, without copying the whole disk. This is not
straightforward, but can be done with -l, readlink,
File::Basename::dirname, and a little care.

Ben

.



Relevant Pages

  • Re: diff mishandling symlinks
    ... |> BTW, a symlink reference to a non-existant file, that may, or may not, ... |> come to exist later on, is a valid symlink. ... | comparing the metadata of the symbolic links. ... | time of the symbolic link, but unlike other files, the contents of the ...
    (comp.unix.programmer)
  • Re: [OpenVMS Alpha V8.3] SET FILE/SYMLINK ?
    ... (Peter 'EPLAN' LANGSTOeGER) ... feature. ... A symlink does not have to point to a file, like a logical name, it can contain ... And while the container for a symbolic link may be a file, ...
    (comp.os.vms)
  • Re: has this bug been fixed?
    ... > option to not deference it? ... So it would seem that the symlink is always resolved if it ... A symbolic link to a directory behaves differently than you ... This means that the parent of the new working directory is ...
    (comp.sys.hp.hpux)
  • Nonstandard symbolic link to a disk volume
    ... I create a symbolic link like "\??\Qwerty" which points to "\Device\HarddiskVolume1". ... Also the following examples of use of this symlink in the cmd are successful: ... Is there an opportunity to open a target volume in file explorer using the above symlink? ...
    (microsoft.public.development.device.drivers)
  • Re: Finding all the links in a Unix file/directory path
    ... John wrote: ... Since directory 'f' is a symbolic link to directory 'c', ... of the the file tree, i.e. if a directory entry was a symlink in the ... original then it should become a symlink in the copy, ...
    (comp.lang.perl.misc)